Ads

What is Search Help Exit in SAP ABAP and How to Create it

What is Search Help Exit in SAP ABAP and How to Create it?



Search Help Exit

You may not know the correct records when you searching for some information from the SAP Data Base, in this case, based on known values, you can filter records to retrieve the data or you can filter the data to fetch your required records with the help of Search Help Exit and also using this function module, you can modify F4 Values at run time.

Search Help Exit Definition


Search Help Exit is a function module which contains predefined changing and tables parameter you can be modified/filter the F4 values selected by Elementary or collective search help using Search help exit function module from the DataBase table.

Consider searching for sales order through VA03, and select sales document not fully confirmed tab, enter the customer number, and press enter
 
The result list will be displayed as below,
 
Now say our requirement is to have a customer number and customer name in the customer column as '121- BHARAT FORGES'. 
We can achieve this by implementing a search help exit and modifying the internal length & output length attributes of the customer field at run time and concatenating customer name to customer number at run time. 
For the purpose of this document I have copied search help VMVAC to ZVMVAC and implemented an exit for this search help.

Step by Step Method for implementing Search Help Exit



1)       Create a function group 'ZVMVAC' using transaction SE80

2)       Create a function module ZVMAC_SHLP_EXIT for search help exit

  
3)       Define the interface attributes for the function module as shown below

Changing Parameters

Parameter                           Type spec.                                Associated type

SHLP                                  TYPE                                       SHLP_DESCR

CALLCONTROL              TYPE                                       DDSHF4CTRL


SHLP- Structure containing search help type, interface and field descriptions of the search help. 
CALLCONTROL - Structure containing the current step of the search help process.

Tables Parameters

Parameter                     Type spec.                    Associated type

SHLP_TAB                    TYPE                           SHLP_DESCT

RECORD_TAB              TYPE                            SEAHLPRES
   

SHLP_TAB -contains search help field description, field properties, and selection criteria. 
RECORD_TAB - contains the search help result list. 
In this example, we will be modifying RECORD_TAB in control step DISP i.e. display as below  

1)       We need to increase the output length of field KUNNR, in addition to increasing the output length of KUNNR we also need to adjust the offset position of other fields in order to avoid overlapping of Customer data with other fields. 

2)       Customer numbers will be available in SHLP, build a range of all the customer numbers which will formulate WHERE condition for selecting customer name. 

3)       Select customer name from KNA1 for all the customers. 

4)       Modify RECORD_TAB to append customer name to a customer number. 
Once these steps are done output will appear as below,

Input Customer - 121


Output with Customer number and name.

Example Program for Search Help Exit in SAP ABAP


FUNCTION zvmvac_shlp_exit.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     VALUE(SHLP) TYPE  SHLP_DESCR
*"     VALUE(CALLCONTROL) TYPE  DDSHF4CTRL
*"----------------------------------------------------------------------
  DATA: ls_fielddescr TYPE dfies, "loc str for shlp-fielddescr
        ls_selopt TYPE ddshselopt.  "loc str for shlp-selopt
*Local structure for itab record_tab
  DATA: BEGIN OF ls_record.
          INCLUDE STRUCTURE seahlpres.
  DATA: END OF ls_record.
  DATA: ls_name1 TYPE name1_gp,
        ls_start TYPE string,
        ls_end TYPE string,
        v_kunnr TYPE kunnr.
*Internal table to store Customer Name
  DATA: BEGIN OF gt_kna1 OCCURS 0,
         kunnr LIKE kna1-kunnr,
         name1 LIKE kna1-name1,
        END OF gt_kna1.
  RANGES: lr_kunnr FOR kna1-kunnr.  "Ranges for customer number
  CHECK callcontrol-step = 'DISP'.
  LOOP AT shlp-fielddescr INTO ls_fielddescr.
    CASE ls_fielddescr-fieldname.
      WHEN 'KUNNR'.
        ls_fielddescr-intlen = ls_fielddescr-outputlen = 45.
        MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
      WHEN 'ERNAM'.
        ls_fielddescr-offset = 63.
        MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
      WHEN 'ERDAT'.
        ls_fielddescr-offset = 75.
        MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
      WHEN 'VBELN'.
        ls_fielddescr-offset = 83.
        MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
    ENDCASE.
  ENDLOOP.
*Build range for customer number
  LOOP AT shlp-selopt INTO ls_selopt WHERE shlpfield = 'KUNNR'.
    lr_kunnr-sign = ls_selopt-sign.
    lr_kunnr-option = ls_selopt-option.
    lr_kunnr-low = ls_selopt-low.
    lr_kunnr-high = ls_selopt-high.
    APPEND lr_kunnr.
    CLEAR: lr_kunnr.
  ENDLOOP.
*Select Customer name
  SELECT kunnr name1
    FROM kna1
    INTO TABLE gt_kna1
    WHERE kunnr IN lr_kunnr.
*Modify record_tab to append Customer name to customer number
  LOOP AT record_tab INTO ls_record.
    v_kunnr = ls_record-string+18(10).
    READ TABLE gt_kna1 WITH KEY kunnr = v_kunnr.
    IF sy-subrc = 0.
      ls_start = ls_record-string+0(28).
      ls_end = ls_record-string+28( * ).
      CLEAR: ls_record-string.
      ls_record-string+0(28) = ls_start.
      ls_record-string+29(1) = '-'.
      ls_record-string+30(36) = gt_kna1-name1.
      ls_record-string+66( * ) = ls_end.
      MODIFY record_tab FROM ls_record.
      CLEAR: ls_record,ls_start,ls_end,gt_kna1,v_kunnr.
    ENDIF.
  ENDLOOP.
ENDFUNCTION.


Short View on Search Help Exit 


1)       SELONE - in this step FM 'DD_SHLP_GET_DIALOG_INFO' is called to populate the internal description of the fields for search help fields in table  SHLP_TAB 

2)       PRESEL1 - in this step the maximum records, internal length, offset attributes of the fields are set 

3)       PRESEL - in this step a pop-up is displayed for the user to enter the selection criteria. 

4)       SELECT - in this step based on the selection criteria entered by the user data will be selected to RECORD_TAB internal table based on the selection method specified for the search help 

5)       DISP - this is the final step before the result list is displayed to the user.



Comments

Post a Comment

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced