How to insert functions to the Functions toolbar of new SAP ALV Display CL_SALV_TABLE

The new ALV Display based on the class CL_SALV_TABLE offers you the possibility to add a new function. It is completely based on the Display mode. In the container mode, the function is added through the functions object. In the complete mode, it is added through the GUI status for the Dynpro.

Adding functions in Container mode:

The Add_function( ) method of the functions object is used to insert functions to the functions toolbar.

DATA lr_functions_list TYPE REF TO cl_salv_functions_list.

lr_functions_list = lr_alv_object->get_functions( ).

lr_functions_list->set_all( ).

lr_functions_list->add_function( name = ‘SUM’  text = ‘SUM’  tooltip = ‘SUM’

position = if_salv_c_function_position=>right_of_salv_function ).

Adding functions in complete mode:

In order to insert a new function in complete mode, copy the GUI status SALV_TABLE_STANDARD in your report.

  1. Open the function group SALV_METADATA_STATUS through the transaction SE80. Right click on the GUI status SALV_TABLE_STANDARD.
  2. Select the copy from the options in order to copy the GUI status.
  3. Give the program name and a name for the copied GUI status in the popup window and finally confirm the entries.
  4. The ALV object must be able to recognize the newly added GUI-status. It is recognized through the set_screen_status method of the ALV object.

Lr_alv_object->set_screen_status( report = ‘ZALV_NEW_FUNCTION’ pfstatus = ‘SALV_TABLE_STANDARD’ set_functions = lr_alv_object->c_functions_all ).

The GUI status can be further adjusted to insert the new function code.

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.