翻遍REUSE_ALV_GRID_DISPLAY_LVC这个函数我们可以发现,这个函数里预定义了一些事件类型。
不过也缺少了一些类型,看看SLIS这个类型池就可以发现,ONF4事件是没有的。
为了把这个函数做出通用和简易的,复制这个函数所在的函数组SLVC_FULLSCREEN到ZSLVC_FULLSCREEN.
然后我们在这个新函数组里,定义F4事件:
LZSLVC_FULLSCREENTOP中定义grid的时候加上F4:
LZSLVC_FULLSCREENTOP中定义本地类lcl_event_receiver的时候加上F4方法:
METHODS handle_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.View Code
LZSLVC_FULLSCREENTOP中实现本地类lcl_event_receiver的时候加上F4处理:
FORM method_onf4 USING pa_fieldname TYPE lvc_fname pa_fieldvalue TYPE lvc_value pa_row_no TYPE lvc_s_roid pa_r_event_data TYPE REF TO cl_alv_event_data pa_t_bad_cells TYPE lvc_t_modi pa_display. IF NOT gt_grid-i_callback_onf4 IS INITIAL AND NOT i_callback_program IS INITIAL. PERFORM (gt_grid-i_callback_onf4) IN PROGRAM (i_callback_program) USING pa_fieldname pa_fieldvalue pa_row_no pa_r_event_data pa_t_bad_cells pa_display. ENDIF. ENDFORM. " METHOD_DATA_CHANGEDView Code
LZSLVC_FULLSCREENF02中定义grid对象注册事件里加上ONF4
LZSLVC_FULLSCREENF01中分配回调对象:
因为SLIS里没有ONF4的对象,所以event get 里只能写固定值:
基本逻辑就是:定义ONF4事件,类里实现ONF4事件,实现方法里执行回调函数对应的程序和FORM。
这样我们就可以调ALV函数的时候加上一句简单的ONF4事件和对应的处理form里可以了。
REPORT zly_f4. TYPE-POOLS:slis. *CLASS lcl_event_receiver DEFINITION DEFERRED. DATA: gt_fcat TYPE lvc_t_fcat, gs_fcat TYPE lvc_s_fcat, gt_f4 TYPE lvc_t_f4, gs_f4 TYPE lvc_s_f4, gs_event TYPE slis_alv_event, gt_event TYPE slis_t_event, gs_layout TYPE lvc_s_layo, gs_glay TYPE lvc_s_glay. DATA: "event_receiver TYPE REF TO lcl_event_receiver, go_grid TYPE REF TO cl_gui_alv_grid. DATA: BEGIN OF gs_data , pernr TYPE char10, nachn TYPE nachn, gesch TYPE gesch, END OF gs_data, gt_data LIKE TABLE OF gs_data. DATA: BEGIN OF gs_f4value, gesch TYPE gesch, ztext TYPE text, END OF gs_f4value, gt_f4value LIKE TABLE OF gs_f4value. START-OF-SELECTION. PERFORM f_get_data. PERFORM f_show_data. FORM f_get_data . SELECT partner AS pernr name_last AS nachn FROM but000 INTO CORRESPONDING FIELDS OF TABLE gt_data UP TO 10 ROWS. * WHERE begda LE sy-datum AND endda GE sy-datum. ENDFORM. FORM f_show_data . DEFINE %%fcat. CLEAR GS_FCAT. GS_FCAT-FIELDNAME = &1. GS_FCAT-SCRTEXT_L = &2. IF &1 = 'GESCH'. GS_FCAT-EDIT = 'X'. GS_FCAT-F4AVAILABL = 'X'. ENDIF. APPEND GS_FCAT TO GT_FCAT. END-OF-DEFINITION. %%fcat: 'PERNR' '人员编号', 'NACHN' '姓名', 'GESCH' '性别'. gs_event-name = 'ONF4'. gs_event-form = 'F_F4_HELP'. APPEND gs_event TO gt_event. gs_glay-edt_cll_cb = 'X'. CALL FUNCTION 'ZREUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-cprog i_callback_pf_status_set = 'PF_STATUS_SET' it_fieldcat_lvc = gt_fcat it_events = gt_event i_grid_settings = gs_glay TABLES t_outtab = gt_data. ENDFORM. FORM f_f4_help USING e_fieldname TYPE lvc_fname p_fieldvalue TYPE lvc_value es_row_no TYPE lvc_s_roid p_r_event_data TYPE REF TO cl_alv_event_data p_t_bad_cells TYPE lvc_t_modi p_display. DATA: lt_ddshretval TYPE STANDARD TABLE OF ddshretval, ls_ddshretval TYPE ddshretval. CLEAR gs_f4value. gs_f4value-gesch = 1. gs_f4value-ztext = '男'. APPEND gs_f4value TO gt_f4value. CLEAR gs_f4value. gs_f4value-gesch = 2. gs_f4value-ztext = '女'. APPEND gs_f4value TO gt_f4value. CLEAR gs_f4value. gs_f4value-gesch = 3. gs_f4value-ztext = '中'. APPEND gs_f4value TO gt_f4value. CHECK e_fieldname = 'GESCH'. REFRESH lt_ddshretval. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'GESCH' " dynpprog = sy-repid dynpnr = sy-dynnr dynprofield = 'GESCH' value_org = 'S' callback_program = sy-repid callback_form = 'FM_CB_FORM' TABLES value_tab = gt_f4value return_tab = lt_ddshretval EXCEPTIONS parameter_error = 1 no_values_found = 2 OTHERS = 3. IF sy-subrc = 0 AND lt_ddshretval IS NOT INITIAL . CLEAR ls_ddshretval. READ TABLE lt_ddshretval INTO ls_ddshretval INDEX 1. IF ls_ddshretval-fieldval IS NOT INITIAL. CLEAR gs_data. READ TABLE gt_data INTO gs_data INDEX es_row_no-row_id. gs_data-gesch = ls_ddshretval-fieldval. MODIFY gt_data FROM gs_data INDEX es_row_no-row_id TRANSPORTING gesch. ENDIF. ENDIF. ENDFORM. FORM refresh_table_alv . DATA: ls_stbl TYPE lvc_s_stbl. ls_stbl-row = 'X'." ls_stbl-col = 'X'. CALL METHOD go_grid->refresh_table_display EXPORTING is_stable = ls_stbl. ENDFORM. FORM pf_status_set USING rt_extab TYPE slis_t_extab. SET PF-STATUS 'STATUS_ALV'. gs_f4-fieldname = 'GESCH'. gs_f4-register = 'X'. gs_f4-getbefore = 'X'. * gs_f4-chngeafter = 'X'. INSERT gs_f4 INTO TABLE gt_f4. CALL FUNCTION 'ZGET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = go_grid. CALL METHOD go_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified. CALL METHOD go_grid->register_f4_for_fields EXPORTING it_f4 = gt_f4[]. ENDFORM. *&---------------------------------------------------------------------* *& FORM FM_CB_FORM *&---------------------------------------------------------------------* FORM fm_cb_form TABLES record_tab STRUCTURE seahlpres CHANGING shlp TYPE shlp_descr_t callcontrol LIKE ddshf4ctrl. DATA: interface LIKE LINE OF shlp-interface. READ TABLE shlp-interface INTO interface INDEX 1. interface-shlpfield+4(1) = '1'. interface-valfield = 'DOC_LAYOUT'. APPEND interface TO shlp-interface. DELETE shlp-interface INDEX 1. ENDFORM. "BO_CALLBACK_FORM
标签:gt,F4,REUSE,data,GRID,gs,TYPE,event,f4value From: https://www.cnblogs.com/sapSB/p/18404242