ALV显示可以编辑的状态下可以带出描述信息等,比如维护表程序输入公司代码时需要带出公司代码的描述,这时就需要通过下面事件来触发
定义一个类:
CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. METHODS:handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed. ENDCLASS.
定义此类一个方法
CLASS lcl_event_receiver IMPLEMENTATION. *--DATA_CHANGED
METHOD handle_data_changed. PERFORM handle_data_changed CHANGING er_data_changed. ENDMETHOD. "HANDLE_CHANGED_DATA ENDCLASS.
定义类的引用:
***带出描述
DATA: g_event_receiver TYPE REF TO lcl_event_receiver.
CREATE OBJECT g_event_receiver.
SET HANDLER g_event_receiver->handle_data_changed FOR gr_alvgrid. ***带出描述
CALL METHOD gr_alvgrid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
类的方法form
FORM handle_data_changed CHANGING ir_data_changed
TYPE REF TO cl_alv_changed_data_protocol.
DATA: ls_mod_cell TYPE lvc_s_modi,
lv_value TYPE lvc_value,
l_name1 TYPE zbwppt004-zplct. ***得到生产线描述
LOOP AT ir_data_changed->mt_mod_cells
INTO ls_mod_cell.
IF ls_mod_cell-fieldname = 'ZKPLC'.
CALL METHOD ir_data_changed->get_cell_value ”方法gt_cell_value用户获取所要的单元格数据
EXPORTING
i_row_id = ls_mod_cell-row_id “单元格的ID
i_fieldname = 'ZKPLC' "单元格的字段
IMPORTING
e_value = lv_value. "单元格的字段值 IF lv_value IS NOT INITIAL. SELECT SINGLE zplct "根据取到的单元格字段值取得改字段的描述赋给变量l_name1
INTO l_name1
FROM zbwppt004
WHERE zkplc = lv_value. CALL METHOD ir_data_changed->modify_cell "修改单元格的值的方法
EXPORTING
i_row_id = ls_mod_cell-row_id ”单元格的ID
i_fieldname = 'ZPLCT' "单元格的字段
i_value = l_name1. “单元格的字段值是刚才得到的变量l_name1
ELSE.
CALL METHOD ir_data_changed->modify_cell
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'ZPLCT'
i_value = ''.
ENDIF.
ENDIF.
CLEAR lv_value.
ENDLOOP. ENDFORM.