Copyright 2023 - BV TallVision IT

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. 

  1. First of all, you will need a working ALV report with content that was composed through the CL_SALV_TABLE class.
  2. 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 methods constructor and on_user_command, like so:
    CLASS lcl_event_manager DEFINITION.
          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.
        DATA: go_salv TYPE REF TO cl_salv_table.

    Let's assume the menu code for refresh is REFRESH. Also, the class lcl_my_controller is set up for my ALV report, for which the GO_ALV is available as TYPE 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.
      METHOD on_user_command.
        CASE e_salv_function.
          when 'REFRESH'.
            lcl_my_controller=>main_selection( ).
            lcl_my_controller=>go_salv->refresh( ).
  3. Notice the method main_selection in the on_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.
  4. 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 the go_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 the CONSTRUCTOR of your event manager).

      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.
    CREATE OBJECT go_event_man
          r_object = go_salv.
  5. 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.