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.

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

CLASS cl_event_handler DEFINITION.


      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.

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

  PERFORM main.

FORM main.

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

    FROM modsapt
    WHERE sprsl = 'EN'
      AND name LIKE 'S%'.

      CALL METHOD cl_salv_table=>factory
          r_salv_table = lo_popup
          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'.
See other related notes in my infodepot:
ALV tree based on class CL_SALV_TREE ALV popup based on classic style REUSE_ALV_POPUP_TO_SELECT function module ALV editable popup based on classic style REUSE_ALV_GRID_DISPLAY function module
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2010

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.