You have an ALV report up and running, for a small selection of "liquid data", information that changes frequently. This article shows you how to add refresh action in the form of a button to your report, following a step by step plan.
First of all, this example ALV setup uses the CL_SALV_TABLE
rather than the CL_GUI_ALV_GRID
class to compose report output as ALV, as this is my preferred ALV class (it's also the class that supports more functionality, such as colored cells).
Refresh your ALV report
The actual report refresh is very simple to implement, but before doing that, a button will need to be made available. This involves implementing an event manager for your ALV report.
- First of all, you will need a working ALV report with content that was composed through the
CL_SALV_TABLE
class. - Set up an event manager for user commands to capture the user command for your refresh. First create an
lcl_EVENT_manager
local class with methodsconstructor
andon_user_command
, like so:CLASS lcl_event_manager DEFINITION. PUBLIC SECTION. METHODS: constructor IMPORTING r_object TYPE REF TO cl_salv_table, on_user_command FOR EVENT added_function OF cl_salv_events IMPORTING e_salv_function. PRIVATE SECTION. DATA: go_salv TYPE REF TO cl_salv_table. ENDCLASS.
Let's assume the menu code for refresh is
REFRESH
. Also, the classlcl_my_controller
is set up for my ALV report, for which theGO_ALV
is available asTYPE REF TO CL_SALV_TABLE
attribute. Here's the implementation of the even class:CLASS lcl_event_manager IMPLEMENTATION. METHOD constructor. DATA: lo_events TYPE REF TO cl_salv_events_table. go_salv = r_object. lo_events = go_salv->get_event( ). SET HANDLER on_user_command FOR lo_events. ENDMETHOD. METHOD on_user_command. CASE e_salv_function. when 'REFRESH'. lcl_my_controller=>main_selection( ). lcl_my_controller=>go_salv->refresh( ). ENDCASE. ENDMETHOD. ENDCLASS.
- Notice the method
main_selection
in theon_user_command
method. This is your own main selection method which will refresh the ALV main table content. It's the very same method you will have used to populate information in your report. - The event manager class is created, but ot also needs to be instantiated and linked to your ALV report. First define attribute
go_event_man
on your controller class (lcl_MY_controller
). Put it richt beneath thego_ALV
definition:DATA: go_SALV type ref to CL_SALV_TABLE, go_event_man TYPE REF TO lcl_event_manager.
Now instantiate the event manager, though
CREATE OBJECT
(which will run theCONSTRUCTOR
of your event manager).TRY. cl_salv_table=>factory( IMPORTING r_salv_table = go_salv CHANGING t_table = gt_report ). CATCH cx_salv_msg. * The wrapper class does not raise the exception, to avoid having to catch it. ENDTRY. CREATE OBJECT go_event_man EXPORTING r_object = go_salv.
- And last (but not least) the button should be made visible to the end user. Fill in "refresh" in the command window to test your refresh. Check out article Setup the menu for more detail.