headershadow

How to create a Search Help with an Exit

Print Friendly

Every SAP user knows the user-friendly search help that offers a list of possible values for a given zone after pressing F4.

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

Kind Regards
Imen
Sap University Team


More about

3 thoughts on “How to create a Search Help with an Exit


Comment author said

By Shriniwas P on 7 February 2013 at 07:53

Thanks Imen. Good efforts taken. Helpful indeed.

Thanks,
Shriniwas

 

Comment author said

By Cyrus Minab on 1 March 2014 at 07:51

Hi Imen,
I've a requirement to search for equipment based on below fields.
equi-serge (serial#)
equz-tidnr (technical ID#)

We need to create a custom search with a custom input field. So basically when the user enters value in this custom field, the system should search both of the above fields in equipment and if it finds values that matches the user input, then it produces list of equipment(s) with equipment number, serial number and technical id number. The user can input a complete value in the input or portion of the value (i.e. *)

Any help is much appreciated.
Thanks

 

Comment author said

By Dimce on 23 March 2018 at 10:45

Very useful. Thank you Imen.

 

Leave a Reply


*