ALV popup based on class CL_SALV_TABLE

This is sample ALV popup based on class CL_SALV_TABLE. It uses gui status from the standard program SAPLKKBL, which includes buttons for ENTER and CANCEL – look at this program for other useful statuses.

The action of pressing the button is handled with event handler. I use the class attribute to store the reference on the main object with popup. Using this reference, you can check which row was selected by the user and do other actions (for example close screen with popup after cancel button was pressed).

Here the sample popup:

and the related coding:

REPORT zkm_test.

DATA:
  BEGIN OF ls_data,
    modtext TYPE modtext_d,
  END OF ls_data,
  lt_data LIKE TABLE OF ls_data.

CLASS cl_event_handler DEFINITION.

  PUBLIC SECTION.

    CLASS-DATA:
      lo_popup TYPE REF TO cl_salv_table.

    CLASS-METHODS on_function_click
      FOR EVENT if_salv_events_functions~added_function
        OF cl_salv_events_table IMPORTING e_salv_function.
ENDCLASS.

CLASS cl_event_handler IMPLEMENTATION.

  METHOD on_function_click.

    CASE e_salv_function.
      WHEN 'GOON'.
        lo_popup->close_screen( ).
*       do action
      WHEN 'ABR'.
        lo_popup->close_screen( ).
*       cancel
    ENDCASE.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  PERFORM main.

FORM main.

  DATA:
    lo_popup     TYPE REF TO cl_salv_table,
    lo_events    TYPE REF TO cl_salv_events_table.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_data
    FROM modsapt
    WHERE sprsl = 'EN'
      AND name LIKE 'S%'.

  TRY.
      CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table = lo_popup
        CHANGING
          t_table      = lt_data.

*     register handler for actions
      lo_events = lo_popup->get_event( ).
      SET HANDLER cl_event_handler=>on_function_click FOR lo_events.
*     save reference to access object from handler
      cl_event_handler=>lo_popup = lo_popup.

*     use gui-status ST850 from program SAPLKKB
      lo_popup->set_screen_status( pfstatus      = 'ST850'
                                   report        = 'SAPLKKBL' ).

*     display as popup
      lo_popup->set_screen_popup( start_column = 1
                                  end_column   = 60
                                  start_line   = 1
                                  end_line     = 10 ).

      lo_popup->display( ).

    CATCH cx_salv_msg.
      WRITE: / 'Error: ALV exception CX_SALV_MSG'.
  ENDTRY.
ENDFORM.

See other related notes on my website:

Scroll to Top