给ALV字段添加搜索帮助详解编程语言

1.引用标准的搜索帮助

在 宏中定义,F4标示,参考表参考字段
GS_FIELDCAT-F4AVAILABL = &5.
GS_FIELDCAT-REF_TABLE = &6.
GS_FIELDCAT-REF_FIELD = &7.

FIELDCAT中引用

给ALV字段添加搜索帮助详解编程语言

为了搜索帮助的值能带入ALV字段中请设置GS_FIELDCAT-EDIT = ‘X’.

效果

给ALV字段添加搜索帮助详解编程语言

2.自建搜索帮助

当所搜帮助需要做筛选的时候,标准的不能满足,手动建F4帮助,给ALV写event事件
首先定义

DATA:GT_EVENT TYPE SLIS_T_EVENT WITH HEADER LINE. 
DATA STBL TYPE LVC_S_STBL. 
DATA: REF_GRID TYPE REF TO CL_GUI_ALV_GRID. 

在选择屏幕之前

CLASS LCL_EVENT_RECEIVER DEFINITION. 
  PUBLIC SECTION. 
    "F4 
    METHODS: 
      HANDLE_F4 
                    FOR EVENT ONF4 OF CL_GUI_ALV_GRID 
        IMPORTING E_FIELDNAME 
                    ES_ROW_NO 
                    ER_EVENT_DATA 
                    ET_BAD_CELLS. 
ENDCLASS. 
 
DATA GT_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER . 
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION. 
  METHOD  HANDLE_F4. 
 
*     窗口时间参数的自定义f4检索帮助 
    CASE E_FIELDNAME. 
      WHEN 'ZEQUNR'.   "内表字段名称 
        PERFORM F4_HELP_ZSJCS USING E_FIELDNAME 
                                    ES_ROW_NO. 
    ENDCASE. 
*     设置后,alv稳定刷新 
 
    STBL-ROW = 'X'." 基于行的稳定刷新 
    STBL-COL = 'X'." 基于列稳定刷新 
    CALL METHOD REF_GRID->REFRESH_TABLE_DISPLAY 
      EXPORTING 
        IS_STABLE = STBL. 
 
  ENDMETHOD.                    "HANDLE_F4 
 
ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION 

在展示ALV之前加入如下代码

DATA: I_GRID_SETTINGS TYPE LVC_S_GLAY. 
  GT_EVENT-NAME = 'CALLER_EXIT'. 
  GT_EVENT-FORM = 'FM_BUTTON'. 
  APPEND GT_EVENT. 
  DATA:  RS_SELFIELD TYPE SLIS_SELFIELD. 
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 = REF_GRID. 
* 设置enter事件 
  CALL METHOD REF_GRID->REGISTER_EDIT_EVENT 
    EXPORTING 
      I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER 
    EXCEPTIONS 
      ERROR      = 1 
      OTHERS     = 2. 
 
 
  CREATE OBJECT GT_EVENT_RECEIVER. 
  SET HANDLER   GT_EVENT_RECEIVER->HANDLE_MODIFY FOR REF_GRID. 
 
  " CHECK gv_flg IS INITIAL. 
 
  "gv_flg = 'X'. 
 
  LS_F4-FIELDNAME  = 'ZEQUNR'.   "窗口时间参数(需要定义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 REF_GRID. 
 
  CALL METHOD REF_GRID->REGISTER_F4_FOR_FIELDS 
    EXPORTING 
      IT_F4 = LT_F4[]. 
 
ENDFORM. 

手动建搜索帮助

*&---------------------------------------------------------------------* 
*&      Form  F4_HELP_ZSJCS 
*&---------------------------------------------------------------------* 
*       窗口时间参数的自定义f4检索帮助 
*----------------------------------------------------------------------* 
FORM F4_HELP_ZSJCS USING P_FIELDNAME  TYPE LVC_FNAME 
                         P_ROW_NO     TYPE LVC_S_ROID. 
  DATA: LT_RETURN TYPE STANDARD TABLE OF DDSHRETVAL, 
        LS_RETURN TYPE DDSHRETVAL. 
  DATA :LV_EQART TYPE EQART. 
 
  CLEAR GS_TAB. 
  READ TABLE GT_TAB INTO GS_TAB INDEX P_ROW_NO-ROW_ID. 
 
  IF P_FIELDNAME = 'ZEQUNR'.  "展示内表字段 
 
    SELECT SINGLE EQART 
      INTO LV_EQART 
      FROM EQUI 
    WHERE EQUNR = GS_TAB-EQUNR. "筛选条件 
 
    SELECT EQUNR 
    INTO CORRESPONDING FIELDS OF TABLE GT_EQUI 
    FROM EQUI 
   WHERE EQART = LV_EQART 
    AND EQTYP = 'T'.  "筛选条件 
 
    SORT GT_EQUI BY EQUNR. 
  ENDIF. 
 
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' 
    EXPORTING 
      RETFIELD        = 'EQUNR'            "筛选内表里面的字段 
      DYNPPROG        = SY-REPID 
      DYNPNR          = SY-DYNNR 
      DYNPROFIELD     = 'GS_TAB-ZEQUNR'            "ALV内表字段 
      VALUE_ORG       = 'S' 
"     CALLBACK_PROGRAM = SY-REPID 
    TABLES 
      VALUE_TAB       = GT_EQUI        "需要显示帮助的值内表 
      RETURN_TAB      = LT_RETURN          "返回值 
    EXCEPTIONS 
      PARAMETER_ERROR = 1 
      NO_VALUES_FOUND = 2 
      OTHERS          = 3. 
  IF SY-SUBRC = 0. 
****将选的值填入ALV字段中 
        READ TABLE gt_tab INTO gs_tab INDEX p_row_no-row_id. 
        IF sy-subrc = 0. 
          READ TABLE lt_return INTO ls_return INDEX 1. 
          IF ls_return-fieldval IS NOT INITIAL. 
            GS_TAB-ZEQUNR = ls_return-fieldval. 
          ENDIF. 
          MODIFY gt_tab FROM gs_tab INDEX p_row_no-row_id 
          TRANSPORTING ZEQUNR. 
        ENDIF. 
  ENDIF. 
ENDFORM.                    " F4_HELP_ZSJCS 

注意:F4搜索帮助框没有出现可能是因为FIELDCAT中未给F4标示打上X(GS_FIELDCAT-F4AVAILABL = ‘X’)
F4搜索帮助的值没有回写进ALV字段中,可能时候因为没有写回写的代码

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19976.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论