DATA: stbl TYPE lvc_s_stbl.
DATA: w_ref_alv TYPE REF TO cl_gui_alv_grid.
定义类
* ----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
* ----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS handle_modify
FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified et_good_cells.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
定义方法
* ----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
* ----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_modify..
*-------------------------------------------------
在此处添加你自己的代码,改变传入ALV函数的那个内表的值,就能实现你的功能。
*-------------------------------------------------
* 稳定刷新
stbl-row = 'X'." 基于行的稳定刷新
stbl-col = 'X'." 基于列稳定刷新
CALL METHOD w_ref_alv->refresh_table_display
EXPORTING
is_stable = stbl.
ENDMETHOD. "HANDLE_MODIFY
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
定义事件
*&---------------------------------------------------------------------*
*& Form FRM_SET_EVENT
*&---------------------------------------------------------------------*
FORM frm_set_event .
ws_events1-name = 'CALLER_EXIT'.
ws_events1-form = 'FRM_CALLER_EXIT'.
APPEND ws_events1 TO it_events1.
ENDFORM. " FRM_SET_EVENT
注册回车事件
*&---------------------------------------------------------------------*
*& Form F_CALLER_EXIT
*&---------------------------------------------------------------------*
FORM frm_caller_exit USING ls_data TYPE slis_data_caller_exit.
.
DATA gt_event_receiver TYPE REF TO lcl_event_receiver.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = w_ref_alv.
* 设置Dropdown List事件
CALL METHOD w_ref_alv->set_drop_down_table
EXPORTING
it_drop_down = i_ddval.
* 设置enter事件
CALL METHOD w_ref_alv->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
CREATE OBJECT gt_event_receiver.
SET HANDLER gt_event_receiver->handle_modify FOR w_ref_alv.
ENDFORM. "F_CALLER_EXIT
把事件表作为参数传入ALV函数中,大功告成
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF_STATUS_SET2'
i_callback_user_command = 'PROCESS_USER_COMMAND1'
is_layout_lvc = ws_layout1
it_fieldcat_lvc = gd_fieldcat1
i_save = 'A'
it_events = it_events1
TABLES
t_outtab = it_zman_hour_spec1
EXCEPTIONS
program_error = 1
OTHERS = 2.