ABAP 物料搜索帮助增强

实现效果

在标准物料搜索帮助上加一个自定义的搜索帮助tab栏位
ABAP 物料搜索帮助增强_第1张图片

实现步骤

SE11找到物料编码的搜索帮助MAT1
ABAP 物料搜索帮助增强_第2张图片
双击是一个搜索帮助集合,需要通过菜单栏的附加搜索帮助新建自定义的搜索帮助
ABAP 物料搜索帮助增强_第3张图片
ABAP 物料搜索帮助增强_第4张图片
在附加搜索帮助中新建搜索帮助,双击即可进入新建搜索帮助页面
ABAP 物料搜索帮助增强_第5张图片
ABAP 物料搜索帮助增强_第6张图片
搜索帮助出口从se37拷贝标准函数【F4IF_SHLP_EXIT_EXAMPLE】
在【CALLCONTROL-STEP = 'SELECT’】时编写搜索帮助的取值代码即可
ABAP 物料搜索帮助增强_第7张图片

FUNCTION ZMM_MATNR_F4.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     VALUE(SHLP) TYPE  SHLP_DESCR
*"     VALUE(CALLCONTROL) LIKE  DDSHF4CTRL STRUCTURE  DDSHF4CTRL
*"----------------------------------------------------------------------

*--------------类型声明----------------------------------------------*
  TYPES: BEGIN OF ty_return,
           matnr    TYPE matnr,
           ernam    TYPE ernam,
         END OF ty_return.

*--------------变量声明----------------------------------------------*
  DATA: ls_return TYPE ty_return,
        lt_return TYPE TABLE OF ty_return,
        lr_ernam  TYPE RANGE OF mara-ernam,
        ls_ernam  LIKE LINE  OF lr_ernam.

* EXIT immediately, if you do not want to handle this step
  IF CALLCONTROL-STEP <> 'SELONE' AND
     CALLCONTROL-STEP <> 'SELECT' AND
     " AND SO ON
     CALLCONTROL-STEP <> 'DISP'.
     EXIT.
  ENDIF.

*"----------------------------------------------------------------------
* STEP SELONE  (Select one of the elementary searchhelps)
*"----------------------------------------------------------------------
* This step is only called for collective searchhelps. It may be used
* to reduce the amount of elementary searchhelps given in SHLP_TAB.
* The compound searchhelp is given in SHLP.
* If you do not change CALLCONTROL-STEP, the next step is the
* dialog, to select one of the elementary searchhelps.
* If you want to skip this dialog, you have to return the selected
* elementary searchhelp in SHLP and to change CALLCONTROL-STEP to
* either to 'PRESEL' or to 'SELECT'.
  IF CALLCONTROL-STEP = 'SELONE'.
*   PERFORM SELONE .........
    EXIT.
  ENDIF.

*"----------------------------------------------------------------------
* STEP PRESEL  (Enter selection conditions)
*"----------------------------------------------------------------------
* This step allows you, to influence the selection conditions either
* before they are displayed or in order to skip the dialog completely.
* If you want to skip the dialog, you should change CALLCONTROL-STEP
* to 'SELECT'.
* Normaly only SHLP-SELOPT should be changed in this step.
  IF CALLCONTROL-STEP = 'PRESEL'.
*   PERFORM PRESEL ..........
    EXIT.
  ENDIF.
*"----------------------------------------------------------------------
* STEP SELECT    (Select values)
*"----------------------------------------------------------------------
* This step may be used to overtake the data selection completely.
* To skip the standard seletion, you should return 'DISP' as following
* step in CALLCONTROL-STEP.
* Normally RECORD_TAB should be filled after this step.
* Standard function module F4UT_RESULTS_MAP may be very helpfull in this
* step.
  IF CALLCONTROL-STEP = 'SELECT'.

    "得到传入条件
    LOOP AT shlp-selopt INTO DATA(ls_selopt).
      CASE ls_selopt-shlpfield.
        WHEN 'ERNAM'.
          MOVE-CORRESPONDING ls_selopt TO ls_ernam.
          APPEND ls_ernam TO lr_ernam.
      ENDCASE.
    ENDLOOP.

    SELECT
      matnr,  " 物料号
      ernam   " 创建人
    FROM mara
    WHERE
      ernam IN @lr_ernam
    INTO CORRESPONDING FIELDS OF TABLE @lt_return.

    "将查询结果回执到屏幕上来
    CALL FUNCTION 'F4UT_RESULTS_MAP'
      TABLES
        shlp_tab          = shlp_tab
        record_tab        = record_tab
        source_tab        = lt_return
      CHANGING
        shlp              = shlp
        callcontrol       = callcontrol
      EXCEPTIONS
        illegal_structure = 1
        OTHERS            = 2.
    "下一个时间点直接转到DISP,否则无法在屏幕上显示帮助列表

    callcontrol-step = 'DISP'.

*   PERFORM STEP_SELECT TABLES RECORD_TAB SHLP_TAB
*                       CHANGING SHLP CALLCONTROL RC.
*   IF RC = 0.
*     CALLCONTROL-STEP = 'DISP'.
*   ELSE.
*     CALLCONTROL-STEP = 'EXIT'.
*   ENDIF.
*    EXIT. "Don't process STEP DISP additionally in this call.
  ENDIF.
*"----------------------------------------------------------------------
* STEP DISP     (Display values)
*"----------------------------------------------------------------------
* This step is called, before the selected data is displayed.
* You can e.g. modify or reduce the data in RECORD_TAB
* according to the users authority.
* If you want to get the standard display dialog afterwards, you
* should not change CALLCONTROL-STEP.
* If you want to overtake the dialog on you own, you must return
* the following values in CALLCONTROL-STEP:
* - "RETURN" if one line was selected. The selected line must be
*   the only record left in RECORD_TAB. The corresponding fields of
*   this line are entered into the screen.
* - "EXIT" if the values request should be aborted
* - "PRESEL" if you want to return to the selection dialog
* Standard function modules F4UT_PARAMETER_VALUE_GET and
* F4UT_PARAMETER_RESULTS_PUT may be very helpfull in this step.
  IF CALLCONTROL-STEP = 'DISP'.
*   PERFORM AUTHORITY_CHECK TABLES RECORD_TAB SHLP_TAB
*                           CHANGING SHLP CALLCONTROL.
    EXIT.
  ENDIF.
ENDFUNCTION.

按上面步骤依次进行此时就已经有新建的搜索帮助栏位了,其他两篇博客提到要把新建的搜索帮助分配出去才能生效,但是按上面步骤貌似就直接分配了…可以参考下下面两位的分配步骤是啥样的

参考链接:
标准程序选择屏幕的搜索帮助增强
标准搜索帮助的增强

你可能感兴趣的:(abap基础,SAP,ABAP)