如何限制搜索帮助

1.背景

通常来说,我们要限制搜索帮助里的值,我们有两种方法,方法1是,通过来限制搜索方法;方法2是通过搜索帮助出口来实现。第一种方法就是通过视图。第二种方法我们用的更广泛,本文也是通过第二种方法来介绍. 截图如下:

在这里插入图片描述
如果不知道搜索帮助建立方法,请参考如下:
参考

2. 只需要红色的截图部分在搜索帮助里;

在这里插入图片描述

3. 建立函数

3.1新建参数在"正在更改"

在这里插入图片描述

3.2新建参数在"表"

在这里插入图片描述

3.3 源代码

主要是用到了lt_result这个内表,还有F4UT_RESULTS_MAP这个函数,然后select的值.

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


  DATA:BEGIN OF ls_result,
         kostl LIKE m_kostn-kostl,
         kosar LIKE m_kostn-kosar,
         mctxt LIKE m_kostn-mctxt,
         bukrs LIKE m_kostn-bukrs,
       END OF ls_result.

  DATA:  lt_result LIKE STANDARD TABLE OF ls_result,
         wa_result LIKE                   ls_result.
* 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'.
      SELECT  cskt~kostl  csks~bukrs cskt~mctxt  cskt~kokrs  INTO CORRESPONDING FIELDS OF TABLE lt_result
  FROM csks
  INNER JOIN cskt ON  csks~kostl = cskt~kostl
  WHERE  csks~kostl = '0021000201' OR csks~kostl = '0021000202' OR csks~kostl = '0021000203' OR csks~kostl = '0021000204' OR csks~kostl = '0022000201'OR
     csks~kostl = '0022000202'OR csks~kostl = '0022000203'OR csks~kostl = '0022000204'.

  callcontrol-step = 'DISP'.
 CALL FUNCTION 'F4UT_RESULTS_MAP'
        TABLES
          shlp_tab          = shlp_tab
          record_tab        = record_tab
          source_tab        = lt_result
        CHANGING
          shlp              = shlp
          callcontrol       = callcontrol
        EXCEPTIONS
          illegal_structure = 1
          OTHERS            = 2.
      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.

4. 效果截图

在这里插入图片描述

5.参考

SAP帮助文档

猜你喜欢

转载自blog.csdn.net/beyond911/article/details/113389147