声明: CLASS lcl_event_receiver DEFINITION DEFERRED. DATA event_receiver TYPE REF TO lcl_event_receiver. DATA go_grid TYPE REF TO cl_gui_alv_grid. DATA I TYPE I. DATA gt_f4 TYPE lvc_t_f4. DATA gs_f4 TYPE lvc_s_f4. *————————————————————————————————————————* * CLASS LCL_EVENT_RECEIVER DEFINITION *———————————————————————————————————————-* CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. METHODS: onf4 FOR EVENT onf4 OF cl_gui_alv_grid IMPORTING e_fieldname e_fieldvalue es_row_no er_event_data et_bad_cells e_display. ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION *———————————————————————————————————————-* * CLASS LCL_EVENT_RECEIVER IMPLEMENTATION *———————————————————————————————————————-* CLASS lcl_event_receiver IMPLEMENTATION. METHOD onf4. PERFORM sub_f4_help USING e_fieldname es_row_no. er_event_data->m_event_handled = 'x' . ENDMETHOD. "onf4 ENDCLASS. 在ALV状态设置里,定义 CHECK i IS INITIAL. i = 1. gs_f4-fieldname = 'ZTEXT'. gs_f4-register = 'X'. gs_f4-getbefore = 'X'. gs_f4-chngeafter = 'X'. INSERT gs_f4 INTO TABLE gt_f4. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = go_grid. CREATE OBJECT event_receiver. SET HANDLER event_receiver->onf4 FOR go_grid. CALL METHOD go_grid->register_f4_for_fields EXPORTING it_f4 = gt_f4[]. 定义SUB_F4_HELP *&---------------------------------------------------------------------* *& Form SUB_F4_HELP *&---------------------------------------------------------------------* * 弹出f4 *----------------------------------------------------------------------* FORM sub_f4_help USING e_fieldname TYPE lvc_fname es_row_no TYPE lvc_s_roid. DATA: t_ddshretval TYPE STANDARD TABLE OF ddshretval, wr_return TYPE ddshretval, l_it_cells TYPE lvc_t_cell, l_gw_cells TYPE lvc_s_cell. CHECK e_fieldname = 'ZTEXT'. REFRESH it_f4. REFRESH t_ddshretval. SELECT werks veran ktext FROM tc24 INTO TABLE it_f4 WHERE werks = p_dwerk. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'KTEXT' "指定ALV用F4的字段 dynpprog = sy-repid value_org = 'S' TABLES value_tab = it_f4 return_tab = t_ddshretval EXCEPTIONS parameter_error = 1 no_values_found = 2 OTHERS = 3. IF sy-subrc = 0 AND t_ddshretval IS NOT INITIAL . CLEAR wr_return. READ TABLE t_ddshretval INTO wr_return INDEX 1. IF wr_return-fieldval IS NOT INITIAL. LOOP AT it_alv INTO wa_alv . IF sy-tabix = es_row_no-row_id. wa_alv-ztext = wr_return-fieldval. MODIFY it_alv FROM wa_alv. ENDIF. ENDLOOP. CALL METHOD go_grid->refresh_table_display. REFRESH l_it_cells. CLEAR l_gw_cells. l_gw_cells-row_id-index = es_row_no-row_id. l_gw_cells-col_id = e_fieldname. APPEND l_gw_cells TO l_it_cells. CALL METHOD go_grid->set_selected_cells EXPORTING it_cells = l_it_cells. ENDIF. ENDIF. ENDFORM. " SUB_F4_HELP