Skip to Content
Author's profile photo Former Member

Badi_Sorter with Kernel Badi and other sorting options

Was trying to figure out how to implement BADI_SORTER to guarantee the implementation sequence for the new kernel BADI. Searched SCN and other blogs and could not get any information. So decided to do a self help and help others with this blog.

The intention here is to do a sample test Sorting of Multiple Implementations of a Kernel BADI. A pre-requisite of knowing Kernel BADI basics is required.

Ok So I have defined a Enhancement Spot ZDEMO_ENH_SPOT.

In the enh spot, a BADI is defined by the name ‘DEMO_BADI‘ with an interface as shown.

Enh Spot def 1.jpg

The interface has a WRITE method.

For the above BADI definition, 3 implementation’s are created as shown.

3 Badi Impl.jpg

Implementation 1

Badi Impl 1.jpg

Badi method Write

Impl 1 method write.JPG

Implementation 2

Badi Impl 2.jpg

Badi Method write

Impl 2 method write.JPG

Implementation 3

Badi Impl 3 .jpg

Badi Method write

Impl 3 method write.JPG

So we are done with 3 active BADI implementations.

SAP doesn’t guarantee the sequence of implementations. However SAP has provided a BADI called BADI_SORTER to achieve the order sequence.

The BADI has a interface with the following methods. The 3 major ones are marked below.

BADI sorter interface methods.jpg

The main central method is the SORT_IMPLS where the multiple implementations are put in the sequence order.

How the sequence order is putforth? A subscreen with a input field takes an integer value. The BADI_SORTER has a screen enhancement which calls up our subscreen (with input field for sequence). This additional subscreen is then visible as shown below.

Sorter field screen shot.jpg

The layer value is nothing but the input order sequence.

Its quite simple. All you have to do is copy an SAP standard program(function group + screen) to your target and use it.

The function group(Function Modules + Screen) are used to pass the input screen value to the BADI_SORTER

Badi Sort Logic 1.jpg

Ok Implement the BADI – BADI_SORTER.

( The “How to implement BADI” details are not covered here as it is an pre-requisite to this blog )

Badi Sort Logic 2 .jpg

During the implementation process, if asked for the below screen, click on Copy sample class. The Implementation class shall the have the coding of the example implementation class CL_BADI_SORTER_LAYER.

Copy sample class.jpg

Save the enhancement implementation at this point.

The main part is here. The screen enhancement.

Copy the Funtion group ENH_BADI_SORTER_SUBSCREENS to our own Function group. The copy can be done via SE80 or using SE38. I have copied to a Func group BADI_SORT_2. Hence the main program name is BADI_SORT_2 prefixed by SAPL. Enter subscreen as 2000.

Func group 1.jpg

During the Function group copy process, you can give your custom name to the Function modules to be copied.

Func group 2.jpg

The function module BADI_SORTER_LAYER_GET is used read the input field (layer) for the BADI_SORTER. Similarly the function module BADI_SORTER_LAYER_SET is used to set the value to the input field (layer).

Save and activate the Function group.

The use of function modules logic are very similar to a BADI screen logic which is used to add additional subscreen to an SAP standard screen.

Enter the function group main program below and subscreen as 2000. Save so far done.

Badi Sort Logic 3 .jpg

Go to Sort Implementation class and double click on the IF_BADI_SORTER~PUT_DATA_TO_SCREEN. Call the FM that was created above.

FM sorter layer put.jpg

Also for the method IF_BADI_SORTER~GET_DATA_FROM_SCREEN use the FM that was created above.

FM sorter layer get .jpg

Also for change the method IF_BADI_SORTER~SET_LAYER_CHANGEABLE.

FM sorter layer set changeable.jpg

Save and Activate the enhancement implementation.

The Sort Implementation is ready. This implementation shall be called when we activate our DEMO_BADI multiple implementation’s.

Its time to have a quick test and check. Go back to our BADI implementation in change mode and double click on the implementation and enter a sort integer value.

Before proceeding further, set a break point in the Sort Implementation method SORT_IMPLS. The debugger will display the sorting order of the 3 implementations at line 21.

Breakpoint at sort impls.JPG

Badi impl 3 test.jpg

Impl 1 check 1.jpg

Impl 2 check 1.jpg

Click Save and Activate. The debugger should stop again.

Impl 3 check 1.jpg

Imple sort excel.JPG

Click Save and Activate. The debugger should stop at line 21 of SORT_IMPLS if its set.

During Activation, the implementation sorting’s happen at line no 21. Observe how sorting takes place in the SORT_IMPLS method.

Let’s do a quick test by calling the BADI in a program.

program code.JPG

The results are after sorting are:

program result.JPG

Try changing the sort field(layer) in each of the implementations. Pls activate the implementations after entering a new value and the sorting can be observed via the sort method SORT_IMPLS.

Hope this was helpful.

Another approach for Sorting implementations is via Filter Type except that this is for Custom Kernel BADI’s. The reason being

the filter values combinations for these are not enhanceable.

For Custom Kernel BADI, you can something like this to sort the implementation sequence.

Enh Spot filter.jpg

Multiple implementations are created for BADI ZDEMO_BADI_SEQ_FILTER.

filter for all 3.jpg

The sequence order for these multiple implementations can be achieved by calling Filter values in the program as shown.

SE38 program.JPG

Here the 1st Implementation shall be called. Passing “SECOND” as filter values will trigger 2nd Implementation.

Hope this was helpful.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Sujin,


      Very Nice information and Helpful.




      Author's profile photo Syambabu Allu
      Syambabu Allu

      Hi Sujin,

      Good Blog with well explanation.



      Author's profile photo Anusha anusha
      Anusha anusha

      Hi Sujin,

      Very Nice Information and Helpful.




      Author's profile photo Miller Lam
      Miller Lam

      Dear Sujin,

      Such a great sharing, came with helpful.

      Nice ~ "SORT".