效果图:

ALV demo 05:cl_salv_table event_微信

定义的status

ALV demo 05:cl_salv_table event_微信_02

ALV demo 05:cl_salv_table event_微信_03

code:
*&---------------------------------------------------------------------*
*& Report ZLM_ALV005
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZLM_ALV005.



DATA: GT_SPFLI TYPE TABLE OF SPFLI.
DATA: LS_SPFLI TYPE SPFLI.
DATA: GR_TABLE TYPE REF TO CL_SALV_TABLE.
DATA: GR_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS_LIST.
DATA: GR_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE.
DATA: GR_SELECTIONS TYPE REF TO CL_SALV_SELECTIONS.

CLASS LCL_HANDLE_EVENTS DEFINITION.
PUBLIC SECTION.
METHODS:
ON_USER_COMMAND FOR EVENT ADDED_FUNCTION OF CL_SALV_EVENTS IMPORTING E_SALV_FUNCTION,
ON_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_SALV_EVENTS_TABLE IMPORTING ROW COLUMN.
ENDCLASS. "lcl_handle_events DEFINITION

DATA: EVENT_HANDLER TYPE REF TO LCL_HANDLE_EVENTS.

START-OF-SELECTION.

SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_SPFLI FROM SPFLI UP TO 100 ROWS.

CALL METHOD CL_SALV_TABLE=>FACTORY IMPORTING R_SALV_TABLE = GR_TABLE CHANGING T_TABLE = GT_SPFLI.

GR_TABLE->SET_SCREEN_STATUS( PFSTATUS = 'STATUS'
REPORT = SY-REPID
SET_FUNCTIONS = GR_TABLE->C_FUNCTIONS_ALL ).

GR_EVENTS = GR_TABLE->GET_EVENT( ).
CREATE OBJECT EVENT_HANDLER.
SET HANDLER EVENT_HANDLER->ON_USER_COMMAND FOR GR_EVENTS.
SET HANDLER EVENT_HANDLER->ON_DOUBLE_CLICK FOR GR_EVENTS.

* Set up selections.
GR_SELECTIONS = GR_TABLE->GET_SELECTIONS( ).
GR_SELECTIONS->SET_SELECTION_MODE( 1 ). "Single

* Display
GR_TABLE->DISPLAY( ).

CLASS LCL_HANDLE_EVENTS IMPLEMENTATION.
METHOD ON_USER_COMMAND.
"Get the selection rows
DATA: LR_SELECTIONS TYPE REF TO CL_SALV_SELECTIONS.
DATA: LT_ROWS TYPE SALV_T_ROW.
DATA: LS_ROWS TYPE I.
DATA: MESSAGE TYPE STRING.
CASE E_SALV_FUNCTION.
WHEN 'TEST'.
LR_SELECTIONS = GR_TABLE->GET_SELECTIONS( ).
LT_ROWS = LR_SELECTIONS->GET_SELECTED_ROWS( ).

READ TABLE LT_ROWS INTO LS_ROWS INDEX 1.
READ TABLE GT_SPFLI INTO LS_SPFLI INDEX LS_ROWS.
CONCATENATE LS_SPFLI-CARRID LS_SPFLI-CONNID LS_SPFLI-CITYFROM LS_SPFLI-CITYTO INTO MESSAGE SEPARATED BY SPACE.
MESSAGE I001(00) WITH 'You pushed the button!' MESSAGE.
ENDCASE.
ENDMETHOD. "on_user_command

METHOD ON_DOUBLE_CLICK.
DATA: MESSAGE TYPE STRING.
DATA: ROW_C(4) TYPE C.
ROW_C = ROW.
CONCATENATE 'Row' ROW_C 'Column' COLUMN INTO MESSAGE SEPARATED BY SPACE.
MESSAGE I001(00) WITH 'You double-clicked on ' MESSAGE.
ENDMETHOD.
ENDCLASS.



QQ群 :SAP干货铺,  群号:775662808