SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Search Help Exit



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Search Help, Match Code
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Apr 12, 2008 12:09 pm    Post subject: Search Help Exit Reply with quote

Search Help Exit

A search help describes the standard input help process. In exceptions it could be necessary to deviate in some points from this standard. Such a deviation from the standard can also be implemented with a search help exit.

The input help process should look as much the same as possible throughout the entire system. Search help exits should therefore only be used for exceptions.

A search help exit is a function module that has a predefined interface. A search help exit is called at certain times by the help processor. The administrative data of the help processor are passed to the search help exit using the interface.

You can store your own program logic that manipulates this administrative data in the search help exit. Individual steps of the input help process can be skipped with a search help exit.

F4UT_OPTIMIZE_COLWIDTH

Search help exit F4UT_OPTIMIZE_COLWIDTH adjusts the column width in the hit list to the contents of the column. It makes sense to use this search help exit when the columns of the hit list have to be made very wide for extreme cases (e.g. for name fields), but normally they will contain much smaller values.

Code:
FUNCTION F4UT_OPTIMIZE_COLWIDTH.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"       IMPORTING
*"             VALUE(PARAMETER_OPTIMIZE) TYPE  C OPTIONAL
*"       TABLES
*"              SHLP_TAB TYPE  SHLP_DESCR_TAB_T
*"              RECORD_TAB STRUCTURE  SEAHLPRES
*"       CHANGING
*"             REFERENCE(SHLP) TYPE  SHLP_DESCR_T
*"             REFERENCE(CALLCONTROL) TYPE  DDSHF4CTRL
*"----------------------------------------------------------------------
  data fieldprop_Wa like ddshfprop.
  data dfies_wa like dfies.
  data i type i.
  field-symbols: <col>.
  data: len type i, maxlen type i.
  DATA: value LIKE DDSHIFACE-VALUE,
        param_tab LIKE DD32P-FIELDNAME OCCURS 0 WITH HEADER LINE.

  RANGES params FOR fieldprop_wa-FIELDNAME.

* CHECK CALLCONTROL-STEP = 'DISP' or callcontrol-step = 'PRESEL'.
  check callcontrol-step = 'PRESEL1'.

  IF PARAMETER_OPTIMIZE IS INITIAL.
     CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'
          EXPORTING
               PARAMETER         = 'PARAMETER_OPTIMIZE'
          IMPORTING
               VALUE             = value
          TABLES
               SHLP_TAB          = SHLP_TAB
               RECORD_TAB        = RECORD_TAB
          CHANGING
               SHLP              = SHLP
               CALLCONTROL       = CALLCONTROL
          EXCEPTIONS
               OTHERS            = 2.
     IF SY-SUBRC = 0.
        SPLIT value AT ',' INTO TABLE param_tab.
     ENDIF.
  ELSE.
       SPLIT PARAMETER_OPTIMIZE AT ',' INTO TABLE param_tab.
  ENDIF.
  params-OPTION = 'EQ'.
  params-SIGN = 'I'.
  LOOP AT param_tab.
       params-LOW = param_tab.
       APPEND params.
  ENDLOOP.
  sort shlp-fielddescr by fieldname.
  loop at shlp-fieldprop into fieldprop_wa
          where fieldname in params and shlplispos <> 0.
    read table shlp-fielddescr
         with key fieldname = fieldprop_wa-fieldname binary search
         transporting no fields.
    check sy-subrc = 0.
    i = sy-tabix.
    DFIES_wa-mask+7(1) = 'O'.
    MODIFY shlp-fielddescr from DFIES_wa index i transporting mask+7(1).
  endloop.
ENDFUNCTION.


Each search help exit must have the same interface as function module F4IF_SHLP_EXIT_EXAMPLE (is used as pattern for all the search help exits to be created). You can find more information about the interface in the documentation for this function module.

F4IF_SHLP_EXIT_EXAMPLE

Code:
FUNCTION F4IF_SHLP_EXIT_EXAMPLE.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     VALUE(SHLP) TYPE  SHLP_DESCR
*"     VALUE(CALLCONTROL) LIKE  DDSHF4CTRL STRUCTURE  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'.
*   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'.
*   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.

Calling the Search Help Exit

If a search help exit is assigned to a search help, the help processor calls it at the following times:

Before Displaying the Dialog Box for Selecting the Required Search Path.

It is only called for collective search helps. Using the search help exit, the set of elementary search helps available can for example be restricted depending on the context.

Before Starting the F4 Process for the Elementary Search Help

The call is triggered independent of whether the dialog window for entering the search conditions appears or whether the selection is executed immediately (for example, because in the Hot key of the elementary search help Immediate value display is set).

Before Displaying the Dialog Box for Entering Search Conditions.

You can either influence the dialog for entering search conditions or skip it altogether here. You can also influence how the selection screen looks. The call is triggered only if there is no direct selection (that is, if in the Hot key of the elementary search help Immediate value display is not set).

Before Selecting Data.

The data selection can be partly or completely copied from the search help exit. This can become necessary if the data selection cannot be implemented with a SELECT statement for a table or a view.

Before Displaying the Hit List.

You can influence the display of the hit list in this step with the search help exit. You can reduce the number of values displayed here. For example, you can display only values for which the person calling the input help has authorization. You can also copy the complete hit list from the search help exit.

Before Returning the Values Selected by the User to the Input Template.

It could be advisable to intervene at this time if control of the further transaction flow should depend on the value selected. A typical example is setting set/get parameters.

Search help SFLIGHT example
Search help SFLIGHT is used to find flight data. When they look for flights, the staff of travel agencies normally need information about whether there are still seats available on the flight. The selection method of the search help (view on tables SCARR, SFLIGHT and SPFLI) does not directly contain this information. The selection method only contains information about the number of seats available on the flight and how many seats are already reserved.

From this information, search help exit SAPBC_GLOBAL_F4_SFLIGHT computes the number of seats still available and returns the results in a parameter of the search help. The number of seats still available can thus be displayed in the hit list.

You therefore only have to program one action in the search help exit for the call before displaying the hit list.



If the process flow of the input help, first the search help exit is called for this event, then the processing for this event is executed, and only then the next step is determined. If within the search help exit a new next step is determined, then the search help exit is not called again for this next step.

SAPBC_GLOBAL_F4_SFLIGHT

Code:
FUNCTION SAPBC_GLOBAL_F4_SFLIGHT.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     VALUE(SHLP) TYPE  SHLP_DESCR
*"     VALUE(CALLCONTROL) LIKE  DDSHF4CTRL STRUCTURE  DDSHF4CTRL
*"----------------------------------------------------------------------
* The scope of this search help exit is decribed in the documentation.
* Note that SAPBC_GLOBAL_F4_SFLIGHT_MIN_FR provides a more complex
* example of a serch help exit.

DATA: BEGIN OF Seatinfo OCCURS 0,                " parallel table to
            seatsmax TYPE SFLIGHT-SEATSMAX,      " record_tab containing
            seatsocc TYPE SFLIGHT-SEATSOCC,      " the information about
            seatsfre TYPE S_SEATSFRE,            " the seats
      END OF Seatinfo.

IF CALLCONTROL-STEP = 'SELECT'.
* The search help parameters SEATSMAX and SEATSOCC are not displayed on
* the list of possible entries. Hence, provided they are not connected
* to dynpro fields, the F4 processor might consider it not to be
* necessary to select the contents of these fields.
* But this exit needs these contents in order to compute the number of
* free seats. Thus, the space for this contents is allocated by the
* following two calls. This automatically forces the F4 processor to
* fill this space with the contents of these fields.
   CALL FUNCTION 'F4UT_PARAMETER_ALLOCATE'
        EXPORTING
             PARAMETER         = 'SEATSMAX'
        TABLES
             SHLP_TAB          = shlp_tab
             RECORD_TAB        = record_tab
        CHANGING
             SHLP              = shlp
             CALLCONTROL       = callcontrol.
   CALL FUNCTION 'F4UT_PARAMETER_ALLOCATE'
        EXPORTING
             PARAMETER         = 'SEATSOCC'
        TABLES
             SHLP_TAB          = shlp_tab
             RECORD_TAB        = record_tab
        CHANGING
             SHLP              = shlp
             CALLCONTROL       = callcontrol.
ENDIF.

CHECK callcontrol-step = 'DISP'.

* This Exit only has to do something before the list of possible values
* is displayed. At that moment it has to compute the number of free
* seats for each row and attach it to the result of the selection
* process

* First fill the seatsmax-Info from the selected data. Note that there
* are two ways of using F4UT_PARAMETER_VALUE_GET described in the
* documetation of that function module. Here the second one is used.
CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'
     EXPORTING
          PARAMETER         = 'SEATSMAX'
                                    " Reference to search help parameter
          FIELDNAME         = 'SEATSMAX'
                                    " Reference to field of Seatinfo
     TABLES
          SHLP_TAB          = shlp_tab
          RECORD_TAB        = record_tab
          RESULTS_TAB       = Seatinfo
     CHANGING
          SHLP              = shlp
          CALLCONTROL       = callcontrol.

* Now do the same with the seatsocc-Info:
CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET'
     EXPORTING
          PARAMETER         = 'SEATSOCC'
                                    " Reference to search help parameter
          FIELDNAME         = 'SEATSOCC'
                                    " Reference to field of Seatinfo
     TABLES
          SHLP_TAB          = shlp_tab
          RECORD_TAB        = record_tab
          RESULTS_TAB       = Seatinfo
     CHANGING
          SHLP              = shlp
          CALLCONTROL       = callcontrol.

* Now compute the number of free seats:
LOOP AT Seatinfo.
     IF Seatinfo-seatsocc < Seatinfo-seatsmax.
        Seatinfo-seatsfre = Seatinfo-seatsmax - Seatinfo-seatsocc.
     ELSE.
          CLEAR Seatinfo-seatsfre.
     ENDIF.
     MODIFY Seatinfo TRANSPORTING seatsfre.
ENDLOOP.

* Finally transport the computed numbers into the search help data.
CALL FUNCTION 'F4UT_PARAMETER_RESULTS_PUT'
     EXPORTING
          PARAMETER         = 'SEATSFRE'
                                    " Reference to search help parameter
          FIELDNAME         = 'SEATSFRE'
                                    " Reference to field of Seatinfo
     TABLES
          SHLP_TAB          = shlp_tab
          RECORD_TAB        = record_tab
          SOURCE_TAB        = Seatinfo
     CHANGING
          SHLP              = shlp
          CALLCONTROL       = callcontrol.
ENDFUNCTION.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Search Help, Match Code All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.