> 文章列表 > ABAP:自定义搜索帮助:可参考标准函数F4IF_SHLP_EXIT_EXAMPLE

ABAP:自定义搜索帮助:可参考标准函数F4IF_SHLP_EXIT_EXAMPLE

ABAP:自定义搜索帮助:可参考标准函数F4IF_SHLP_EXIT_EXAMPLE

当我们在自定义选择屏幕中, 需要写入我们自定义的搜索帮助的时候,可以通过预定义函数来实现:
实例说明:
第一步:创建搜索帮助SE11分销渠道(Z_VTWEG)
1.选择基本索引帮助:
ABAP:自定义搜索帮助:可参考标准函数F4IF_SHLP_EXIT_EXAMPLE

2.选择参考表,因为这里分销渠道和文本来源于TVTWT,这里选择方法就填入TVTWT,对话类型选择D立即显示值,就是点击即可出现结果。
ABAP:自定义搜索帮助:可参考标准函数F4IF_SHLP_EXIT_EXAMPLE
列表的意思是排列顺序
搜索帮助出口:需要我们自定义一个函数,可复制标准函数:F4IF_SHLP_EXIT_EXAMPLE去创建
参数和预定义函数一致,这里我们调用‘SELECT’这个时间点来进行数据的查询输出,自定义的帮助出口函数中的具体代码如下

FUNCTION zsd_vtweg_f4_exit.
*“----------------------------------------------------------------------
"“本地接口:
*” TABLES
*” SHLP_TAB TYPE SHLP_DESCT
*" RECORD_TAB STRUCTURE SEAHLPRES
*" CHANGING
*" VALUE(SHLP) TYPE SHLP_DESCR
*" VALUE(CALLCONTROL) LIKE DDSHF4CTRL STRUCTURE DDSHF4CTRL
*"----------------------------------------------------------------------
DATA:BEGIN OF lt_tab OCCURS 0,
vtweg TYPE vtweg,
vtext TYPE vtxtk,
spras TYPE spras,
END OF lt_tab.
DATA:r_vtweg TYPE RANGE OF vtweg WITH HEADER LINE,
r_vtext TYPE RANGE OF vtxtk WITH HEADER LINE,
r_spras TYPE RANGE OF spras WITH HEADER LINE,
ddshelops TYPE ddshselopt.

  • 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 …
    LOOP AT record_tab INTO DATA(ls_table).

    ENDLOOP.
    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’.

  • PERFORM STEP_SELECT TABLES RECORD_TAB SHLP_TAB

  •                   CHANGING SHLP CALLCONTROL RC.
    
  • IF RC = 0.

  • CALLCONTROL-STEP = 'DISP'.
    
  • ELSE.

  • CALLCONTROL-STEP = 'EXIT'.
    
  • ENDIF.
    "传入参数
    LOOP AT shlp-selopt INTO DATA(ls_selopt).
    CASE ls_selopt-shlpfield.
    WHEN ‘SPRAS’.
    MOVE-CORRESPONDING ls_selopt TO r_spras.
    APPEND r_spras.
    WHEN OTHERS.
    ENDCASE.
    ENDLOOP.
    "根据输入参数查询数据
    SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_tab FROM tvtwt WHERE spras = sy-langu.
    "将查询结果回执到屏幕上来

    CALL FUNCTION 'F4UT_RESULTS_MAP'
*       EXPORTING
*         SOURCE_STRUCTURE         =
*         APPLY_RESTRICTIONS       = ' 'TABLESshlp_tab          = shlp_tabrecord_tab        = record_tabsource_tab        = lt_tabCHANGINGshlp              = shlpcallcontrol       = callcontrolEXCEPTIONSillegal_structure = 1OTHERS            = 2.
*下一个时间点直接转到DISP,否则无法再屏幕上显示帮助列表callcontrol-step = 'DISP'.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.LOOP AT record_tab INTO DATA(ls_item).ENDLOOP.EXIT.ENDIF.
ENDFUNCTION.

ABAP:自定义搜索帮助:可参考标准函数F4IF_SHLP_EXIT_EXAMPLE
因为我这里是全部输出系统当前语言的分销渠道,所以这里的搜索没有去做限制,也可以更具具体情况去限制
3.自定义屏幕中写入参考我们的搜索帮助即可
ABAP:自定义搜索帮助:可参考标准函数F4IF_SHLP_EXIT_EXAMPLE