1. 定义和注册事件接受器类
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED
*----------------------------------------------------------------------*
* LCL_EVENT_RECEIVER
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA gv_flg TYPE char01.
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* lcl_event_receiver的类定义:
*----------------------------------------------------------------------*
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.
METHODS:
handle_f4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data
et_bad_cells.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_modify.
DATA: lv_enter TYPE REF TO cl_gui_event,
lv_eventid TYPE i.
* 获取当前事件
lv_enter = tem_grid->cur_event.
* 实例化成功的时候
IF lv_enter IS NOT INITIAL.
lv_eventid = lv_enter->eventid.
ENDIF.
* 只有在[回车]事件的时候,再进行检查(19:代表回车事件)
IF lv_eventid = 19
AND sy-ucomm = ''.
IF p_mmvds = 'X'.
* 设置供应商描述字段和物料描述字段
PERFORM set_name1_maktx.
* 设置后,alv稳定刷新
PERFORM refresh_table_alv.
* 添加行项目检查(多频次包装基础表)
PERFORM check_line_mmvds.
ELSEIF p_detail = 'X'.
* 添加行项目检查(窗口时间表)
PERFORM check_line_dtdetail.
ELSEIF p_vds = 'X'.
* 设置供应商描述字段(供应商供货信息基础表)
PERFORM set_name1_vds.
* 设置后,alv稳定刷新
PERFORM refresh_table_alv.
* 添加行项目检查(供应商供货信息基础表)
PERFORM check_line_vds.
ENDIF.
ENDIF.
* 设置后,alv稳定刷新
PERFORM refresh_table_alv.
ENDMETHOD. "HANDLE_MODIFY
METHOD handle_f4.
* 供应商供货信息基础表的情况
IF p_vds = 'X'.
* 窗口时间参数的自定义f4检索帮助
PERFORM f4_help_zsjcs USING e_fieldname
es_row_no.
* 设置后,alv稳定刷新
PERFORM refresh_table_alv.
ENDIF.
ENDMETHOD. "HANDLE_F4
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
2. 调用alv函数
**EVENT LAYOUT
DATA: ls_events TYPE slis_alv_event,
lt_event TYPE slis_t_event,
ls_layout TYPE lvc_s_layo.
ls_events-name = 'CALLER_EXIT'.
ls_events-form = 'FM_BUTTON'.
APPEND ls_events TO lt_event.
ls_layout-stylefname = 'FIELD_STYL'.
ls_layout-zebra = 'X'.
ls_layout-box_fname = 'CHK_BOX'.
ls_layout-cwidth_opt = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF_STATUS_SET'
i_callback_user_command = 'USER_COMMAND'
is_layout_lvc = ls_layout
it_fieldcat_lvc = gt_fieldcat_lvc
i_save = 'X'
it_events = lt_event
TABLES
t_outtab = pt_outdata
EXCEPTIONS
program_error = 1
OTHERS = 2.
3. 定义是事件子程序
*&---------------------------------------------------------------------*
*& Form FM_BUTTON
*&---------------------------------------------------------------------*
* 设置enter事件
*----------------------------------------------------------------------*
* -->E_GRID text
*----------------------------------------------------------------------*
FORM fm_button USING e_grid TYPE slis_data_caller_exit.
DATA: lv_event_receiver TYPE REF TO lcl_event_receiver,
lt_f4 TYPE lvc_t_f4,
ls_f4 TYPE lvc_s_f4.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = tem_grid.
* 设置enter事件
CALL METHOD tem_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
CREATE OBJECT lv_event_receiver.
SET HANDLER lv_event_receiver->handle_modify FOR tem_grid.
* 设置f4事件
CHECK gv_flg IS INITIAL.
gv_flg = 'X'.
ls_f4-fieldname = 'ZSJCS'. "窗口时间参数(需要定义F4帮助按钮的字段)
ls_f4-register = 'X'.
ls_f4-getbefore = 'X'.
ls_f4-chngeafter = 'X'.
INSERT ls_f4 INTO TABLE lt_f4.
CREATE OBJECT lv_event_receiver.
SET HANDLER lv_event_receiver->handle_f4 FOR tem_grid.
CALL METHOD tem_grid->register_f4_for_fields
EXPORTING
it_f4 = lt_f4[].
ENDFORM. "FM_BUTTON
4. 定义alv-status子程序
*&---------------------------------------------------------------------*
*& Form PF_STATUS_SET
*&---------------------------------------------------------------------*
* status设定
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
FORM pf_status_set USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STATUS_ALV'.
ENDFORM. "PF_STATUS_SET
5. 定义alv-comman子程序
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* USER COMMMAND
*----------------------------------------------------------------------*
* -->P_UCOMM text
* -->PS_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING ucomm LIKE sy-ucomm
selfield TYPE slis_selfield.
DATA l_grid TYPE REF TO cl_gui_alv_grid.
*------------将ALV上修改的内容保存到内表---------------------------------*
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data.
CASE ucomm.
* [行项目追加]按钮
WHEN 'CREATE'.
* 多频次包装基础表
IF p_mmvds = 'X'.
* 添加行项目(多频次包装基础表)
PERFORM cteate_line_mmvds.
* 窗口时间基础表
ELSEIF p_detail = 'X'.
* 添加行项目(窗口时间基础表)
PERFORM cteate_line_dtdetail.
* 供应商供货信息基础表
ELSEIF p_vds = 'X'.
* 添加行项目(供应商供货信息基础表)
PERFORM cteate_line_vds.
ENDIF.
selfield-refresh = 'X'. "将更新后内表的数据反馈到alv画面,自动刷新功能
* [行项目删除]按钮
WHEN 'DELETE'.
* 多频次包装基础表
IF p_mmvds = 'X'.
* 删除行项目(多频次包装基础表)
PERFORM delete_line_mmvds.
* 窗口时间基础表
ELSEIF p_detail = 'X'.
* 删除行项目(窗口时间基础表)
PERFORM delete_line_dtdetail.
* 供应商供货信息基础表
ELSEIF p_vds = 'X'.
* 删除行项目(供应商供货信息基础表)
PERFORM delete_line_vds.
ENDIF.
selfield-refresh = 'X'. "将更新后内表的数据反馈到alv画面,自动刷新功能
* [保存]按钮
WHEN 'SAVE'.
* 多频次包装基础表
IF p_mmvds = 'X'.
* 保存处理(多频次包装基础表)
PERFORM save_data_mmvds.
* 窗口时间基础表
ELSEIF p_detail = 'X'.
* 保存处理(窗口时间基础表)
PERFORM save_data_dtdetail.
* 供应商供货信息基础表
ELSEIF p_vds = 'X'.
* 保存处理(供应商供货信息基础表)
PERFORM save_data_vds.
ENDIF.
ENDCASE.
*------------将ALV上修改的内容保存到内表---------------------------------*
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data.
ENDFORM. "USER_COMMAND
6. 其他子程序定义
*&---------------------------------------------------------------------*
*& Form REFRESH_TABLE_ALV
*&---------------------------------------------------------------------*
* 设置后,alv稳定刷新
*----------------------------------------------------------------------*
FORM refresh_table_alv .
DATA: stbl TYPE lvc_s_stbl.
*
stbl-row = 'X'." 基于行的稳定刷新
stbl-col = 'X'." 基于列稳定刷新
CALL METHOD tem_grid->refresh_table_display
EXPORTING
is_stable = stbl.
ENDFORM. " REFRESH_TABLE_ALV
*&---------------------------------------------------------------------*
*& Form F4_HELP_ZSJCS
*&---------------------------------------------------------------------*
* 窗口时间参数的自定义f4检索帮助
*----------------------------------------------------------------------*
FORM f4_help_zsjcs USING p_fieldname TYPE lvc_fname
p_row_no TYPE lvc_s_roid.
DATA: lt_dtdetail TYPE STANDARD TABLE OF ztpp_dtdetail,
lt_return TYPE STANDARD TABLE OF ddshretval,
ls_return TYPE ddshretval.
CLEAR gw_vds.
READ TABLE gt_vds INTO gw_vds INDEX p_row_no-row_id.
IF p_fieldname = 'ZSJCS'.
SELECT *
INTO TABLE lt_dtdetail
FROM ztpp_dtdetail
WHERE werks = gw_vds-werks.
SORT lt_dtdetail BY werks zsjcs.
DELETE ADJACENT DUPLICATES FROM lt_dtdetail
COMPARING werks zsjcs.
ENDIF.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'ZSJCS' "lt内表里面的字段
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'ZSJCS' "画面上绑定字段
value_org = 'S'
callback_program = sy-repid
TABLES
value_tab = lt_dtdetail "需要显示帮助的值内表
return_tab = lt_return "返回值
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc = 0.
READ TABLE lt_return INTO ls_return INDEX 1.
gw_vds-zsjcs = ls_return-fieldval.
MODIFY gt_vds FROM gw_vds INDEX p_row_no-row_id
TRANSPORTING zsjcs.
ENDIF.
ENDFORM. " F4_HELP_ZSJCS