One of my clients recently came to me with a challenging requirement – add fields from a custom table into the results of standard search helps. The hope was to do this with the lowest number of modifications possible.
I came up with the following possibilities.
- Copy each search help into the “Z” namespace and modify them as needed
- Core mod each standard search help, adding the new requirements
- Add the fields dynamically via a search help exit
Option 1 – This would be the standard solution undertaken by most developers. There is a huge problem with this beyond the number of new custom objects to be maintained. The collective search help would contain both the SAP-standard versions as well as the new, modified versions. This would inevitably create confusion for the users. You could hide the standard elementary search helps, but this is a core mod in itself.
Option 2 – A developer could modify the search help selection method, typically a view, and add the new fields. They would also need to add the new fields into the search help parameters, adding them to the fields to be displayed. These two tasks would need to be done for each elementary search help in the collective help. Come upgrade time, each of these mods needs to be redone.
Option 3 – If we can add the fields via a search help exit, the only core mod is adding the search help exit to the SAP-standard elementary helps. No modification to the database views would be needed, and the upgrade process would be easy – simply re-add the search help exit to each object. Let’s see if we can do this!
For this example, we’re going to tackle the customer search help (DEBI).
For reference, here is the example custom table I will be using. We will be adding the customer’s favorite movie and sport to standard elementary search helps.
The first thing we need to do is create the search help exit function module. The easiest way to do this is to copy function module F4IF_SHLP_EXIT_EXAMPLE. This guarantees the correct function module parameters are used. The exit will not work if the parameters are not exact.
At a high-level, these are the steps we need to take:
- Add the new fields to the search help output structure
- Read the additional data from the database
- Copy the new fields into the search help output
- Add the search help exit to the existing elementary help
All of the code I wrote for this is available in full at the end of this blog. For brevity’s sake, some details have been skipped in the screenshots, but the entirety of the work is available in the attachments.
Step 1 – Adding the new fields to the output structure
This step needs to be done during the “PRESEL” search help event, meaning the fields are added before the user has a chance to enter filters. The new fields need to be added into three separate places – the interface, the field list, and the field properties. Each of these is in the search help exit CHANGING parameter SHLP.
Adding to the interface
This is the simplest step. All we need to do is append lines to SHLP-INTERFACE, assigning our fieldname(s) to field SHLPFIELD.
Adding to the field list
This portion informs the search help where in the structure to expect our new output fields. The reason for this requirement is the generic SAP search help code uses a 1000 character field for output. We need to define the type of field, the length, offset (where in the 1000 character field our data exists), the output length, and other data dictionary type criteria. Most of the information is available to us in the table definition via table DD03L. For simplicity, I am adding the new fields to the end of the standard search help output. The added advantage of this is we are able to use the same search help exit for multiple elementary search helps, and it is also upgrade-proof. Even if SAP adds additional fields to the view being used, it doesn’t matter to our code.
These entries are added to SHLP-FIELDDESCR.
Adding to the field properties
The field properties (SHLP-FIELDPROP) define the field output order. Here we are telling where in the output we want our fields to appear (SHLPLISPOS). Again, for simplicity’s sake, we are going to add the fields to the end.
Step 2 – Read the additional data from the database
This step occurs during the “DISP” search help event, meaning the data has already been selected via standard functionality. We need the search results in order to tie the data to our custom table.
The first step is to define a structure that will hold the data. We will use elementary help DEBIA in this example, but you can see multiple other examples in the code attached at the end of this blog. We will take the standard view used in DEBIA (M_DEBIA) and add our custom fields. Our structure looks like this:
We then call function module F4UT_PARAMETER_VALUE_GET using parameter KUNNR and a tables parameter results_tab table of GTY_DEBIA (screenshot above) to get a list of all customers returned by the search help. This internal table of customers can then be used to get our custom data. In this example, we are selecting records from table ZCUSTOMER_FAVES.
Step 3 – Copy the new fields into the search help output
This step also occurs during the “DISP” event. After retrieving our custom data in step 2, we need to add it to the output. We will do this by matching up our customer records. However, nothing ground-breaking, but we are going to use ASSIGN COMPONENT so that we can use generic typing in our method parameters. This enables us to use the same code across all the different DEBI elementary search helps.
After the data mapping portion, we need to copy our updated records back into the search help output. This is done by calling function module F4UT_PARAMETER_RESULTS_PUT for each of the custom fields (F_MOVIE and F_SPORT in our example).
Step 4 – Add the search help exit to the existing elementary help
This is the core modification piece of this development. We need to add our search help exit to the standard SAP elementary helps. Note the same exit is used in different elementary helps.
Finally… the results!!
However, note that there are no changes to standard view M_DEBIA
Here is the code for my example search help exit: Mike Berg Code File 1
This is the code for the search help exit helper class: Mike Berg Code File 2
If you have an interest in viewing similar conten about SAP Search, visit our blog, here.
View our LinkedIn, here.