Summary
Search help exit is used to modify the F4 values at run time before its being displayed as a list to the user for selection. This document explains step by step procedure for implementing a search help exit with an example.
Steps in Search Help
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.
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.
Example Scenario
Consider searching for sales order through VA03, and select sales document not fully confirmed tab, enter customer number and press enter
The result list will be displayed as below,
Now say our requirement is to have 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.
The result list will be displayed as below,
Now say our requirement is to have 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.
Steps in 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 customer number.
Once these steps are done output will appear as below,
Input Customer - 121
Output with Customer number and name.
3) Define the interface attributes for the function module as shown below
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.
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 customer number.
Once these steps are done output will appear as below,
Sample code
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.
*"----------------------------------------------------------------------
*"*"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.
No comments:
Post a Comment