ALV通过F4事件,实现自定义搜索帮助F4
生活随笔
收集整理的這篇文章主要介紹了
ALV通过F4事件,实现自定义搜索帮助F4
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
| ALV通過參考可以直接獲取表中搜索幫助,但是表中字段沒有搜索幫助或者不合要求就需要通過F4事件完成了。 1、定義OOALV類 CLASS lcl_event_receiver DEFINITION DEFERRED.DATA:gt_fieldcat TYPE lvc_t_fcat,gs_fieldcat TYPE lvc_s_fcat,go_grid TYPE REF TO cl_gui_alv_grid,go_event_receiver TYPE REF TO lcl_event_receiver.*----------------------------------------------------------------------* * CLASS lcl_event_receiver DEFINITION *----------------------------------------------------------------------* CLASS lcl_event_receiver DEFINITION.PUBLIC SECTION.METHODS:handle_f4_help FOR EVENT onf4 OF cl_gui_alv_gridIMPORTING e_fieldnamees_row_noer_event_dataet_bad_cellse_display.ENDCLASS. "lcl_event_receiver DEFINITION *----------------------------------------------------------------------* * CLASS lcl_event_receiver IMPLEMENTATION *----------------------------------------------------------------------* CLASS lcl_event_receiver IMPLEMENTATION.METHOD handle_f4_help.FIELD-SYMBOLS:<fs_alv> TYPE gs_alv.CASE e_fieldname.WHEN 'ARKTX'.READ TABLE git_alv ASSIGNING <fs_alv> INDEX es_row_no-row_id.IF sy-subrc = 0.PERFORM frm_get_arktx_f4 CHANGING <fs_alv>-arktx.ENDIF. * WHEN .WHEN OTHERS.ENDCASE.CALL METHOD go_grid->refresh_table_display.ENDMETHOD.ENDCLASS. "lcl_event_receiver |
gs_fieldcat-f4availabl = 'X'. gs_fieldcat-edit = 'X'.
3、將F4事件注冊到ALV對象中
DATA:lt_f4 TYPE lvc_t_f4,ls_f4 TYPE lvc_s_f4.CALL METHOD go_grid->set_table_for_first_displayEXPORTINGit_toolbar_excluding = lt_excludeCHANGINGit_fieldcatalog = git_fieldcatit_outtab = git_alv[].CLEAR:ls_f4. ls_f4-fieldname = 'ARKTX'. ls_f4-register = 'X'. ls_f4-getbefore = 'X'. ls_f4-chngeafter = ''. ls_f4-internal = ''. INSERT ls_f4 INTO TABLE lt_f4.CALL METHOD go_grid->register_f4_for_fieldsEXPORTINGit_f4 = lt_f4.CREATE OBJECT go_event_receiver. SET HANDLER go_event_receiver->handle_f4_help FOR go_grid .
4、自定義F4,獲取數據
*&---------------------------------------------------------------------* *& Form FRM_GET_ARKTX_F4 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_<FS_ALV>_ARKTX text *----------------------------------------------------------------------* FORM frm_get_arktx_f4 USING pc_matnr TYPE vbrp-matnrCHANGING pc_arktx TYPE zfit005-maktx.DATA:BEGIN OF lt_zfit029 OCCURS 0,sub_type_m TYPE zfit029-sub_type_m,sub_name_m TYPE zfit029-sub_name_m,END OF lt_zfit029.DATA:lt_ret_tab TYPE TABLE OF ddshretval WITH HEADER LINE.DATA:lv_matnr TYPE zfit028-matnr.lv_matnr = pc_matnr.SELECT sub_type_msub_name_mINTO TABLE lt_zfit029FROM zfit028INNER JOIN zfit029 ON zfit028~type_m = zfit029~type_mWHERE zfit028~matnr = lv_matnr.CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'EXPORTINGretfield = 'SUB_NAME_M'value_org = 'S'TABLESvalue_tab = lt_zfit029return_tab = lt_ret_tabEXCEPTIONSparameter_error = 1no_values_found = 2OTHERS = 3.IF sy-subrc = 0.READ TABLE lt_ret_tab INDEX 1.IF sy-subrc = 0 AND lt_ret_tab-fieldval IS NOT INITIAL.pc_arktx = lt_ret_tab-fieldval.ENDIF.ENDIF.ENDFORM. " FRM_GET_ARKTX_F4
5、效果
總結
以上是生活随笔為你收集整理的ALV通过F4事件,实现自定义搜索帮助F4的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 根据表名如何查找使用它的程序名、接口等
- 下一篇: ABAP SORT