Wednesday, March 18, 2015

Creating a Basic SAP Search Help and explanation




The following steps show you how to create a basic SAP search help which allows you to provide the user with a selection help for a specific input field. A search help in its simplest form will just display a list of values from a single database table or view (selection method), which the user can select an option from. The value they select will then be entered into the input field the search help was requested from. 

Step1 - Create Search help 
Execute transaction SE11 and create a new search help called 'ZSHELP'. Please note this can be anything starting with Z that fits in the box but in some older SAP systems must be less than 5 characters long to be used as matchcode
 

Select Elementary search help 
 


Step2 - Enter basic details 
Enter a short description and PA0002 into the selection method field, this is basically the table the search help gets it data from 
 


Step3 - Enter search help parameters 
The next step is to add the fields that are going to be used by this search help as parameters i.e. those that appear in the output list or selection screen. To do this click the dropdown option of the first search help parameter 
 

Then select the appropriate field from the list (PERNR) 
 

Repeat this for fields NCHMC and VNAMC 
 
IMP - Import values from the screen/field to the search help 

EXP - Export value back to the input field(s) 

LPOS - Position on the output list the user selects from 

SPOS - Position on the selection screen if your search help to have select options which the user can enter to restrict further the search help value list by. 

Default - Add a default value the field is populated with 


Step4 - Save, activate and test 
Enter LPos values as follows (3,1,2) and tick the EXP column for the pernr field. This is the field who's value you want to be returned when the user selects an option/row. 
 

Save and activate the search help and press the test button, a screen will appear showing how the search help will appear on a pernr field. Press the search help button at the end of the field 
 

The search help output will now look like this with the fields in the order you specified then in the LPOS field 
 


Step5 - Change output order 
Now enter LPos values as follows (1,2,3) 
 

If you save, activate and test the search help again you will see that the output order has changed 
 


Step6 - Add selection options 
Now enter 1 and 2 against parameters NCHMC and VNAME within the SPos column 
 

Now if you save, activate and test the search help again you will see that you have the 2 parameters available on the search help to further restrict the value list. You may need to expand the view using the little arrow to see this additional options. 
 

Enter values in the additional parameters and notice how the hit list is restricted 
 


Step7 - Change Dialog behaviour 
Just to demonstrate what this option does, ensuring you still have values within the SPos column change the dialog behaviour from 'Display values immediately' to 'Dialog with value restriction' 
 

Now when you test it you should notice that the parameter restriction fields are display before you see the value results list. You could also add defaults to these fields using the default column. This option may be usful if the search help returns lots of values as it gives the user an option to restrict further before the data is retrieved and displayed. 
 

Step 8 - Assign matchcode to report parameter 
If you have created your search help to be matchcode compatible (i.e. less than 5 chars long) you can add the following line of ABAP code into your program: 

PARAMETER p_prog LIKE trdir-name MATCHCODE OBJECT zsh. 

alternatively see other methods of adding a search help.


SAP Search helps can be implemented in a variety of ways:
Add to Table fieldAdded via SE11: Place cursor on desired field within database and select menu path  Goto->Search help->for fieldEffect: If field used to create screen field, search help will be called when user executes F4/drop down input help. All fields on screen will be populated if appropriate fields exist in search help and screen.
Add to TableAdded via SE11: Place cursor on desired field within database and select menu path  Goto->Search help->for table
Add to Data elementAdded via SE11: Select desired data element (double click), enter search help name and parameters in appropriate fields on screen. Will be applied to all fields associated with that data element
Add to Screen fieldAdded via screen painter: One of field attributes is search help. Will only populate the one screen field.
Add to Sel. screen parameter (MATCHCODE)Added using 'matchcode' addition for parameters declaration: Search help name must be no more than 5 characters long.

e.g. PARAMETER p_prog LIKE trdir-name MATCHCODE OBJECT zsh.




How to create a Search Help with an Exit

Thanks to this option, it is possible to choose easily an entry without any need for controlling its relevance, since it is automatically supported by the search help functionality.
If you have luck, you would find a standard search help with adequate filters that fulfill your requirement. But, it is not so obvious to find the right search help!
For instance, the standard search help MAT1 contains several tabs with different filters to refine the search for material numbers. Even though, it is not possible to fulfill complex conditions like “Display only materials whose valuation class correspond to a given cost element group
In such cases, you need to create your own search help and implement the specific conditions on your own, using search help exits.
In this blog, I will explain how to create a search help that fulfills the condition mentioned above:
Display only materials whose valuation class correspond to a given cost element group
For those who are not familiar with the concept of valuation classes in MM:
  • Go to transaction MM03 and choose a material number then select the “Accounting 1” view
  • Enter the plant in next popup then confirm.
  • The valuation class could be found under “Current valuation”.
  • The valuation class permits –in combination with other factors- to determine the G/L account on which the stock values have to be posted.
  • G/L accounts are assigned to valuation classes via transaction OBYC.
  • The FI G/L accounts correspond to primary cost elements in CO. Those are categorized into cost element groups that could be visualized using transaction KAH3.
We have now in mind the relationship between valuations classes in MM and cost element groups in CO. Lets create the search help that realizes our requirement.

First step: Create the search help via SE11

In SE11, choose “Search Help” and enter its name, then click on “Create”.
In the next popup, choose the option “Elementary search help” since we will create a single tab in the search help.
Enter a description then fill in the search help parameters:
  • Importing parameters are passed at runtime to the search help. In our example, it concerns information related to a cost element group, i.e. Group name, company code and controlling area.
  • Exporting parameters correspond to the fields displayed in the hit list. These are the material number and description.
  • Further parameters could be added such material type and language. These are filters displayed in the dialog box that enable further restriction of the hit list.
A default value could be assigned to each parameter by filling the column “Default value”. For example, if you want to display only materials with a specific type, you need just to add it as a default value.
Fill in the columns LPOS and SPOS with parameters positions in the hit list and the dialog box respectively.
Keep the dialog type “display values immediately” to display the hit list without going through a dialog box.
The result looks as follows:
It remains only to add the search help exit.
It is a function module with special parameters.
In SE37, create the function module Z_PS_F4_EXIT_MATNR.
It is necessary to add the following parameters. Otherwise the search help could not be activated.
  • Changing parameters
  • Table parameters:
  • Go now back to the search help and activate it

Second step: Implementation of the search help exit.

The search help implementation is structured as follows:
  1. Get importing parameters
  2. Get dialog box parameters
  3. Select material numbers corresponding to a given cost element group
  4. Constitute the result list of the search help
  • Get importing parametersFor this purpose, use parameter SHLP as follows:
  • Get dialog box parameters
    For this purpose, use parameter SHLP-SELOPT as follows:
  • Select material numbers corresponding to the selected cost element group
    This functionality is splitted into several function modules for reusability.
    • Create a function module that builds a range of cost elements belonging to a given group.
    Create a structure…..
    …and table type for the range
    Go to SE37 and create the function module Z_PS_GET_KSTAR_FROM_GROUP with the following parameters:
    Add the following code:
    • Create a function module that returns materials with valuation classes that correspond to a given cost element group.
    Create the following structure which will contain the parameters needed for valuation class selection.
    Create function module Z_PS_GET_RESSOURCE_BY_GRPNAME with following parameters.
Implement now the function module:
  • Call the previously created MF Z_PS_GET_KSTAR_FROM_GROUP to get the range of cost elements belonging to the group in parameter.
  • Use the following tables to find out the relevant material numbers:
    • T030: Get valuation classes corresponding to the previously determined cost elements range
    • MBEW: get materials that have one of the selected valuation classes
The final code looks as follows:
Go back to search help exit Z_PS_F4_EXIT_MATNR and add a call to the function module ‘Z_PS_GET_RESSOURCE_BY_GRPNAME’ :
  • Constitute result list
    Select descriptions of materials found in last step. The dialog box parameters have to be taken into account in the selection.
    Append the result to search help hit list
    To recapitulate, here is the complete code of search help exit Z_PS_F4_EXIT_MATNR

Third step: Test the search help

Create a table with the following zones:
Select zone “MATNR” and click on button “Srch Help”.
Enter the search help name
Mapping between search help parameters and table zones is done automatically. Just confirm the generated proposal.
Generate a maintenance dialog for the table to be able to maintain it via SM30.
Go now to SM30 and add a new entry in the table. Enter group name, company code and controlling area.
Use the search help of zone “Material” to get relevant values. When you execute it, only material numbers corresponding to the group name value are listed.
Change the group name and notice the effect in search help result
You can also display the dialog box to enable more filtering options

5 comments:

  1. I am not sure the place you are getting your information, however good topic. I needs to spend some time studying more or understanding more. Thank you for wonderful information I was in search of this info for my mission.


    Sap Training in Chennai | Sap Abap Training in Chennai | Sap SD Training in Chennai

    ReplyDelete
    Replies
    1. Have kept these objects for refering from client place. Till I am in Abap.

      Delete
  2. Thanks.. I have kept few of my developments for my own easiness.. so that I can search anytime and refer.. instead of keeping in drives of laptops.. had thought none will check my blog.

    ReplyDelete
  3. Hi. I have one problem in my program. I have created two elementary search help. In program, I have assigned matchcode objects for both the field. Now, I want to filter second field base on first field.

    Please suggest how I can filter in the program

    ReplyDelete