What are the different events of the class CL_GUI_ALV_GRID?

The class CL_GUI_ALV_GRID of the old ALV model provides different events. It is available in the Tab EVENTS of the class CL_GUI_ALV_GRID.

EventParameterDescription
BUTTON_CLICKE_ROW -> Row
E_COLUMN -> Column
E_ROW_NO -> Row id
It is triggered when a button is clicked.
USER_COMMANDE_UCOMM -> Function codeIt is triggered when a function is triggered,
DOUBLE_CLICK E_ROW -> Row
E_COLUMN -> Column
E_ROW_NO -> Row Id
It is triggered when a cell of the ALV Table is double clicked.
HOT_SPOT_CLICKE_ROW -> Row
E_COLUMN -> Column
E_ROW_NO -> Row Id
It is triggered when a Hotspot is clicked.
TOOLBARE_OBJECT -> It is an object of type CL_ALV_EVENT_TOOLBAR_SETIt is triggered when any entity on the toolbar is clicked.
Events of class CL_GUI_ALV_GRID

The implementation of the above events is similar for all events. It involves definition of Eventhandler, registering the Event handler with the SET HANDLER command.

The implementation of Double click event is shown below

CLASS zcl_handler DEFINITION PUBLIC.

PUBLIC SECTION.

CLASS_METHODS double_click_method FOR EVENT double_click

OF cl_gui_alv_grid IMPORTING e_row e_column es_row_no.

ENDCLASS.

CLASS zcl_handler IMPLEMENTATION.

METHOD double_click_method.

CALL FUNCTION ‘POPUP_TO_CONFIRM’

EXPORTING

titlebar = ‘Double Click occurred’

text_question = e_column-fieldname

text_button_1 = ‘Yes’

text_button_2 = ‘No’.

ENDMETHOD.

ENDCLASS.

Registration of Double Click event through SET HANDLER

SET HANDLER zcl_handler => double_click_method FOR lr_gui_alv_grid.

The class CL_GUI_ALV_GRID provides three methods to register events.

REGISTER_DELAYED_EVENT ( ) : If the cell of the ALV table or the line of record is changed, then this event can be used.

REGISTER_EDIT_EVENT ( ) :

If the data in the ALV is changed, then this event can be triggered automatically. The key benefit here is user does not have to click the ‘ENTER’ Button explicitly.

Let us look at this event with an example:

The edit event is registered with the help of the REGISTER_EDIT_EVENT method of the ALV object like below.

CALL METHOD lr_gui_alv_grid -> register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid => mc_evt_modified.

The parameter i_event_id is set to mc_evt_modified. By setting this event_id, the variable m_cell_edit is set explicitly to ‘X’. Even if the user forgets to click the enter key, then this variable m_cell_edit is set automatically.

REGISTER_F4_FOR_FIELDS ( ) :

If the F4- Value help for a field is clicked, then this event can be used.

How to add user-defined buttons in SAP ALV TOOLBAR

In this blog post, we discuss about the events of the class CL_GUI_ALV_GRID. The old SAP ALV model provides standard functions such as summing, sorting, search function, Excel Export function etc. It also enables us to add new functions to the SAP ALV toolbar.

The Event TOOLBAR of the class CL_GUI_ALV_GRID is used to add functions to the toolbar of the SAP ALV List.

The following steps are needed in order to add a Button.

  1. Define the Event handler.
  2. Register the Event handler for the event.
  3. Activate the event through the method SET_TOOLBAR_INTERACTIVE()
  1. Definition of Event Handler.

The Event handler is defined in the static method of the class like below.

              CLASS zcl_handler DEFINITION PUBLIC.

   PUBLIC SECTION.

                       CLASS-METHODS st_select_all_method FOR EVENT toolbar

                          OF cl_gui_alv_grid IMPORTING e-object.

               ENDCLASS.

               CLASS zcl_handler IMPLEMENTATION.

                      METHOD st_select_all_method.

                            DATA ls_button_toolbar TYPE stb_button.

                            ls_button_toolbar-function = ‘SELALL’.

                            ls_button_toolbar-icon = icon-select-all.

                            ls_button_toolbar-quickinfo = ‘SELECT ALL function’.

                            INSERT ls_button_toolbar INTO e_object -> mt_toolbar INDEX 2.

                     ENDMETHOD.

               ENDCLASS.

2. Event handler Registration.

The Event handler is registered using the ‘SET HANDLER … FOR … ‘ command.

An example below shows the registration.

SET HANDLER zcl_handler => st_select_all_method FOR lr_gui_alv_grid.

3. Activation of Event.

As a last step, the event must be activated through the method SET_TOOLBAR_INTERACTIVE. This ensures that the event is triggered from ALV. It is the method of the ALV object.

CALL METHOD lr_gui_alv_grid -> set_toolbar_interactive( )

 The event handler registration and event activation code section appears between the ALV table call ‘SET_TABLE_FOR_FIRST_DISPLAY’ and the ‘CALL SCREEN’ of Dynpro call.

 The Event handler uses the parameter e_object in order to insert the button entry into the internal table mt_toolbar. The parameter E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.