Search BAdI - How to Implement a Search BAdI

In this article you will learn how to implement a Search BAdI. You will understand how filters work and get an overview of all methods with respective areas of application.

Our Search BAdI blog series in overview

  1. How to Implement a Search BAdI - general overview
  2. Search BAdI - Meta Method Explained
  3. Search BAdI - Do Search Method Explained
 

Methods

The enhancement spot /NLY/EDITOR contains a BAdI definition /NLY/BADI_SEARCH, which covers all possible search operations. You can use it to change the search style, number of minimum characters to be entered before search will start and even implement your own search logic.

Customer specific logic is deployed in methods of the implementing class. The structure of methods is inherited from the BAdI definition you selected.

Search BAdI Methods

BAdI definition /NLY/BADI_SEARCH contains the following methods:

  • /NLY/IF_SEARCH~SET_META_EXIT -   Exit meta data of search
  • /NLY/IF_SEARCH~DO_SEARCH_EXIT - Exit for custom search logic

I will explain the respective methods in more detail below.

Meta Method

Using the Meta method, you can adjust any meta data of the search. For example, you can change the search bar to dropdown or activate and disable strict search.

 

Search vs Dropdown Search

The dropdown search suites best for short result lists and always loads all values locally first. Then, the search is executed on the locally loaded values. Thus, dropdown is ideal for short lists. On the other hand, the search function is executed for the entered search term only (eventually it is executed multiple times, if you enter the letters quite slowly). Therefore, SEARCH setting suites best for objects with large master data selections.

Do Search Method

In the Do Search method, you can implement your own search including formatting the results for display to the end user.

Custom search

Overview

In the following chart you will find an overview of all search methods.

Search BAdI Overview

Filter

The filter contains the search type and the search name. For example, if the search is executed on an InfoObject, the search name is the name of the InfoObject.

Search filter

The table or DSO is not part of the filter. It means the BAdI is executed across all DSOs or tables, which contain the same InfoObject. This way, you don’t have to implement a BAdI multiple times for different DSOs.

If you want to implement different searches for DSOs, which contain the same InfoObject, two use cases exist. In one case you want to have different search appearance (meta data) for a specific object. In the other case you want to have different search logic implemented for the same object.

For example, you may want to have different search styles of the same InfoObject for different tables. In a small table you may want to use DROPDOWN and in a big table, with many entries, you may want to use SEARCH. In this case, you can implement a new referenced InfoObject (so that the master data is reused). Moreover, you can also set table specific settings in the Table Column Properties. You can also use the Table Maintenance Meta BAdI to overwrite the settings done in the Search Meta BAdI.

In another example, you want to implement different search logic. In this case, you can use the Table Maintenance Meta method, to change the search mode and thus trigger another DO SEARCH implementation.

For example, if you want to trigger a search logic of another InfoObject, you can change the parameters SEARCHMODE and SEARCHNAME to the respective InfoObject. In the example below you can find the coding of the Table Maintenance Meta Method.

  METHOD /nly/if_editor~set_meta_exit.
FIELD-SYMBOLS: <l_s_fields_info> TYPE /nly/ts_fields_info,
<l_s_f4help> TYPE /nly/ts_search_info.

LOOP AT ch_t_fields_info ASSIGNING <l_s_fields_info>.

CASE <l_s_fields_info>-fname.

WHEN 'CALYEAR'.

LOOP AT <l_s_fields_info>-f4help ASSIGNING <l_s_f4help>.

<l_s_f4help>-searchmode = 'IOBJ'.
<l_s_f4help>-searchname = '0FISCYEAR'.

ENDLOOP.
ENDCASE.
ENDLOOP.
ENDMETHOD.

The filter of the triggered DO SEARCH BAdI must be set up accordingly.

Filter for implementation of another InfoObject's DO SEARCH method

You can also replace the search logic completely InfoObject independent using the CUSTOM search type. Please refer to the coding below for an example.

    FIELD-SYMBOLS: <l_s_fields_info> TYPE /nly/ts_fields_info,
<l_s_f4help> TYPE /nly/ts_search_info.

LOOP AT ch_t_fields_info ASSIGNING <l_s_fields_info>.

CASE <l_s_fields_info>-fname.

WHEN 'CALYEAR'.

LOOP AT <l_s_fields_info>-f4help ASSIGNING <l_s_f4help>.

<l_s_f4help>-searchmode = 'CUSTOM'.
<l_s_f4help>-searchname = 'ZCUST'.

ENDLOOP.
ENDCASE.
ENDLOOP.
ENDMETHOD.

Don't forget to setup the filter of the DO SEARCH BAdI accordingly. Choose CUSTOM as STYPE and the name of the logic as SEARCHNAME.

Filter for the custom implementation

 

NextTables BAdI Reference