CL_SALV_EVENTS_TABLE¶
Event handler class for user interactions on a CL_SALV_TABLE grid.
Purpose¶
CL_SALV_EVENTS_TABLE is the event object for a CL_SALV_TABLE grid. Obtain it via lo_alv->get_event( ), then register your handler methods using SET HANDLER. It exposes events for toolbar button clicks, cell clicks, double-clicks, and pre/post standard-function hooks.
Key events¶
| Event | Raised when | Key importing parameters |
|---|---|---|
ADDED_FUNCTION |
A custom toolbar button is clicked | e_salv_function (the button name) |
LINK_CLICK |
A hotspot or link cell is clicked | e_row (row index), e_column (field name) |
DOUBLE_CLICK |
Any cell is double-clicked | e_row, e_column |
BEFORE_SALV_FUNCTION |
Just before a standard function executes | e_salv_function |
AFTER_SALV_FUNCTION |
Just after a standard function executes | e_salv_function |
How to register a handler¶
The handler method signature must match the event signature exactly. Use FOR EVENT ... OF cl_salv_events_table in the method definition.
Example¶
Handle LINK_CLICK to drill down — read the clicked row from the internal table and call a transaction:
REPORT z_salv_events_demo.
DATA gt_users TYPE STANDARD TABLE OF usr02.
CLASS lcl_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS on_link_click
FOR EVENT link_click OF cl_salv_events_table
IMPORTING sender e_row e_column.
ENDCLASS.
CLASS lcl_handler IMPLEMENTATION.
METHOD on_link_click.
" e_row is 1-based index into the internal table
READ TABLE gt_users INDEX e_row INTO DATA(ls_user).
IF sy-subrc = 0.
SET PARAMETER ID 'XUS' FIELD ls_user-bname.
CALL TRANSACTION 'SU01' AND SKIP FIRST SCREEN.
ENDIF.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SELECT bname, ustyp, gltgv, gltgb
FROM usr02
INTO TABLE @gt_users
UP TO 50 ROWS.
DATA lo_alv TYPE REF TO cl_salv_table.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = lo_alv
CHANGING t_table = gt_users ).
" mark BNAME as a clickable hotspot
DATA(lo_col) = CAST cl_salv_column_table(
lo_alv->get_columns( )->get_column( 'BNAME' ) ).
lo_col->set_cell_type( if_salv_c_cell_type=>hotspot ).
" register the event handler
DATA(lo_events) = lo_alv->get_event( ).
SET HANDLER lcl_handler=>on_link_click FOR lo_events.
lo_alv->display( ).
CATCH cx_salv_msg INTO DATA(lx_salv).
MESSAGE lx_salv->get_text( ) TYPE 'E'.
CATCH cx_salv_not_found INTO DATA(lx_not_found).
MESSAGE lx_not_found->get_text( ) TYPE 'E'.
ENDTRY.
Common pitfalls¶
Handler class and method must be PUBLIC
SET HANDLER will fail at runtime if the method is not in the PUBLIC SECTION of the class. This is easy to miss when moving code from a local class to a global class.
Local class must be declared before START-OF-SELECTION
In a report, local class definitions (CLASS lcl_handler DEFINITION) must appear before the START-OF-SELECTION event block. If you place them after, the SET HANDLER statement cannot resolve the class and the program dumps.
e_row is a display index, not a database key
The e_row parameter in LINK_CLICK and DOUBLE_CLICK is the 1-based index of the row as currently displayed — after any active sorts or filters. If your display table is filtered, READ TABLE ... INDEX e_row may return the wrong record. Use it against the same internal table reference that was passed to factory.
Suppress standard behaviour with BEFORE_SALV_FUNCTION
Register a handler for BEFORE_SALV_FUNCTION and set the er_application_events parameter to intercept and cancel standard functions (e.g. prevent layout changes). Useful for locked, audit-relevant reports.
ADDED_FUNCTIONonly fires for custom buttons added viaCL_SALV_FUNCTIONS_LIST=>add_function. Standard button clicks fireBEFORE_SALV_FUNCTION/AFTER_SALV_FUNCTION.- The
senderparameter in every handler is theCL_SALV_EVENTS_TABLEobject that raised the event — rarely needed but useful for multi-grid screens.
See also¶
CL_SALV_TABLE— the parent ALV objectCL_SALV_FUNCTIONS_LIST— adding custom toolbar buttonsCL_SALV_COLUMNS_TABLE— setting cell types (hotspot, button)- Demo program:
SALV_DEMO_TABLE_EVENTS