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.
The interface has a WRITE method.
For the above BADI definition, 3 implementation’s are created as shown.
Badi method Write
Badi Method write
Badi Method write
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.
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.
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
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 )
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.
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.
During the Function group copy process, you can give your custom name to the Function modules to be copied.
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.
Go to Sort Implementation class and double click on the IF_BADI_SORTER~PUT_DATA_TO_SCREEN. Call the FM that was created above.
Also for the method IF_BADI_SORTER~GET_DATA_FROM_SCREEN use the FM that was created above.
Also for change the method IF_BADI_SORTER~SET_LAYER_CHANGEABLE.
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.
Click Save and Activate. The debugger should stop again.
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.
The results are after sorting are:
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.
Multiple implementations are created for BADI ZDEMO_BADI_SEQ_FILTER.
The sequence order for these multiple implementations can be achieved by calling Filter values in the program as shown.
Here the 1st Implementation shall be called. Passing “SECOND” as filter values will trigger 2nd Implementation.
Hope this was helpful.