ABAP 搜索增强型搜索帮助(SE11)

1.SE11 创建搜索帮助

 

 2.新建出口函数 ZMM_LGORT_HELP_EXIT

 

3.ZMM_LGORT_HELP_EXIT 函数编辑(标准的出库函数修改而来的)

FUNCTION ZMM_LGORT_HELP_EXIT.
*"--------------------------------------------------------------------
*"*"局部接口:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCR_TAB_T
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     REFERENCE(SHLP) TYPE  SHLP_DESCR_T
*"     REFERENCE(CALLCONTROL) TYPE  DDSHF4CTRL
*"--------------------------------------------------------------------

* 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'.

    EXIT.
    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'.
    DATA:LR_WERKS TYPE RANGE OF ZMMT0413A-WERKS,
         LR_UNAME TYPE RANGE OF ZMMT0413A-UNAME,
         LR_LGORT TYPE RANGE OF ZMMT0413A-ZMMLGORT.

    LOOP AT SHLP_TAB INTO DATA(LS_SHLP).
      LOOP AT LS_SHLP-SELOPT INTO DATA(LS_SELOPT).
        IF LS_SELOPT-SHLPFIELD 'UNAME'.
          LR_UNAME[] VALUE #( BASE LR_UNAME[] SIGN = LS_SELOPT-SIGN OPTION = LS_SELOPT-OPTION LOW = LS_SELOPT-LOW HIGH = LS_SELOPT-HIGH ).
        ELSEIF LS_SELOPT-SHLPFIELD 'WERKS'.
          LR_WERKS[] VALUE #( BASE LR_WERKS[] SIGN = LS_SELOPT-SIGN OPTION = LS_SELOPT-OPTION LOW = LS_SELOPT-LOW HIGH = LS_SELOPT-HIGH ).
        ELSEIF LS_SELOPT-SHLPFIELD 'ZMMLGORT'.
          LR_LGORT[] VALUE #( BASE LR_LGORT[] SIGN = LS_SELOPT-SIGN OPTION = LS_SELOPT-OPTION LOW = LS_SELOPT-LOW HIGH = LS_SELOPT-HIGH ).
        ENDIF.
      ENDLOOP.
    ENDLOOP.

    SELECT  A~ZMMLGORT,
                    C~LGOBE AS LGOBE1,
                    A~ZMMWAHS,
                    B~LGOBE
      FROM ZMMT0413A AS A
       LEFT JOIN T001L AS B ON A~WERKS = B~WERKS
                           AND A~ZMMLGORT = B~LGORT
      LEFT JOIN T001L AS ON A~WERKS C~WERKS
                           AND A~ZMMWAHS C~LGORT
      INTO TABLE @DATA(LT_TCJ04)
      WHERE A~WERKS IN @LR_WERKS
        "and uname in @lr_uname
        AND ZMMLGORT IN @LR_LGORT.
    SORT LT_TCJ04 BY ZMMLGORT LGOBE1 ZMMWAHS LGOBE.
    DELETE ADJACENT DUPLICATES FROM LT_TCJ04 COMPARING ZMMLGORT LGOBE1 ZMMWAHS LGOBE.
    CALL FUNCTION 'F4UT_RESULTS_MAP'
*     EXPORTING
*       SOURCE_STRUCTURE         =
*       APPLY_RESTRICTIONS       = ' '
      TABLES
        SHLP_TAB          = SHLP_TAB
        RECORD_TAB        = RECORD_TAB
        SOURCE_TAB        = LT_TCJ04
      CHANGING
        SHLP              = SHLP
        CALLCONTROL       = CALLCONTROL
      EXCEPTIONS
        ILLEGAL_STRUCTURE 1
        OTHERS            2.
    IF SY-SUBRC <> 0.

    ENDIF.
    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.
  SORT RECORD_TAB.
  DELETE ADJACENT DUPLICATES FROM RECORD_TAB COMPARING ALL FIELDS.
  IF CALLCONTROL-STEP 'DISP'.
*   PERFORM AUTHORITY_CHECK TABLES RECORD_TAB SHLP_TAB
*                           CHANGING SHLP CALLCONTROL.
    EXIT.
  ENDIF.

ENDFUNCTION.

 

4.保存激活后,根据需要选择需要的筛选字段以及选择字段

 

posted @ 2022-07-18 13:44  别忘了带红领巾  阅读(1054)  评论(0)    收藏  举报