修改字段BB的内容,回车后修改CC的值
步骤:
1、定义类lcl_event_handler、定义方法用于实现类CL_GUI_ALV_GRID的事件DATA_CHANGED_FINISHED,实现类、方法;
2、调用FM ‘REUSE_ALV_GRID_DISPLAY_LV’时,给事件CALLER_EXIT添加FORM子程序;
3、在事件CALLER_EXIT的FORM子程序中注册回车事件、创建类lcl_event_handler对象CREATE OBJECT g_event_receiver、注册事件 DATA_CHANGED_FINISHED
SET HANDLER g_event_receiver->handle_modify FOR gr_grid.
TYPE-POOLS: slis.
TYPES: BEGIN OF typ_itab,
aa TYPE c,
bb TYPE i,
cc TYPE i,
END OF typ_itab.
DATA: gt_itab TYPE TABLE OF typ_itab WITH HEADER LINE,
wa_tab TYPE typ_itab,
gt_fieldcat TYPE lvc_t_fcat,
wa_layout TYPE lvc_s_layo,
gt_event TYPE slis_t_event WITH HEADER LINE,
gr_grid TYPE REF TO cl_gui_alv_grid.
CLASS: lcl_event_handler DEFINITION DEFERRED.
DATA: g_event_receiver TYPE REF TO lcl_event_handler.
*----------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler 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_handler DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_modify.
DATA: ls_stbl TYPE lvc_s_stbl.
LOOP AT gt_itab INTO wa_tab.
wa_tab-cc = wa_tab-bb * 2 .
MODIFY gt_itab FROM wa_tab TRANSPORTING cc.
ENDLOOP.
ls_stbl = ‘XX‘.
CALL METHOD gr_grid->refresh_table_display
EXPORTING
is_stable = ls_stbl.
ENDMETHOD. "HANDLE_MODIFY
ENDCLASS. "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
**--取数
PERFORM frm_fetch_data.
**--输出列字段设置
PERFORM frm_set_fieldcat.
**--输出列字段属性设置
PERFORM frm_set_fieldcat_attribute.
**--ALV显示
PERFORM frm_display_alv.
*&---------------------------------------------------------------------*
*& Form FRM_FETCH_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_fetch_data .
gt_itab-aa = ‘aa‘.
gt_itab-bb = 1.
gt_itab-cc = 3.
APPEND gt_itab.
ENDFORM. " FRM_FETCH_DATA
*&---------------------------------------------------------------------*
*& Form FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_set_fieldcat .
DATA: ls_fieldcat TYPE lvc_s_fcat.
DEFINE fieldcat.
ls_fieldcat-col_pos = &1.
ls_fieldcat-fieldname = &2.
ls_fieldcat-scrtext_l = &3.
ls_fieldcat-checkbox = &4.
ls_fieldcat-edit = &5.
ls_fieldcat-decimals = &6.
append ls_fieldcat to gt_fieldcat.
clear ls_fieldcat.
END-OF-DEFINITION.
fieldcat ‘1‘ ‘AA‘ ‘AA‘ ‘‘ ‘‘ ‘‘.
fieldcat ‘2‘ ‘BB‘ ‘BB‘ ‘‘ ‘X‘ ‘‘.
fieldcat ‘3‘ ‘CC‘ ‘CC‘ ‘‘ ‘‘ ‘0‘.
ENDFORM. " FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FRM_SET_FIELDCAT_ATTRIBUTE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_set_fieldcat_attribute .
ENDFORM. " FRM_SET_FIELDCAT_ATTRIBUTE
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_display_alv .
gt_event-name = ‘CALLER_EXIT‘. "slis_ev_caller_exit_at_start事件
gt_event-form = ‘FRM_CALLER_EXIT‘.
APPEND gt_event.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘
EXPORTING
i_callback_program = sy-repid
it_fieldcat_lvc = gt_fieldcat[]
it_events = gt_event[]
TABLES
t_outtab = gt_itab.
ENDFORM. " FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& Form FRM_CALLER_EXIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->E_GRID text
*----------------------------------------------------------------------*
FORM frm_caller_exit USING ir_grid TYPE slis_data_caller_exit.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR‘
IMPORTING
e_grid = gr_grid.
"---注册回车事件
CALL METHOD gr_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
CREATE OBJECT g_event_receiver.
SET HANDLER g_event_receiver->handle_modify FOR gr_grid.
ENDFORM. "FRM_CALLER_EXIT
版权声明:本文为博主原创文章,未经博主允许不得转载。