Step by Step Guide On BADI With Filter Implementation
Step by Step Guide On BADI With Filter Implementation
Step 1 Before implementing filter objects to a BADI. We need to deactivate all the implementation for
that BADI.
Go to SE18 (BADI definition) and from there navigate to all BADI implementation to view all the active
implementations for that BADI.
Select the BADI implementations listed on the screen and deactivate the implementation. Once
done, return back to the initial screen of SE18 and proceed with next step.
Step 2 go to SE18 – BADI Definition screen and change the existing BADI definition that we created in
the earlier tutorial.
Select the FILTER –DEPENDENT check box under the TYPE section. This will open up the FILTER
TYPE field for inputs.
If a BADI implementation already exists then the system will try to adjust the implementations since the
definition of the BADI has been changed (This step will be required only if you have not deactivated the
implementations as explained in the first step).
Click on the continue button.
Now to ensure that the interface parameters have been adjusted by the system click on the interface tab
and then double click on any method to see the list of parameters.
As seen from the above screen the system has added a new parameter. You can now use this filter in the
code to trigger your logic conditionally.
Similarly it will also adjust the other methods defined in the interface. Since in the implementation part the
BADI interface is used the changed done in the parameters are bydefault reflected in the BADI
implementation as well.
Lets go to the implementation part and see the details.
Select the menu IMPLEMENTATION DISPLAY.
The system will display all the implementation if it has more than one implementation.
And as you can see from the screen shot below the new parameter list is automatically available in the
implementation part.
Now lets use this filter type and make changes to the program.
We have introduced a new CHECK condition to query and check the value of the filter during runtime.
Click on the save and activate the method.
Return to the initial screen of the implementation and define a filter value by clicking on the INSERT ROW
button under the filter section. The filter value acts like a condition. Only if, during the runtime the filter
value matches the method will get executed.
We need to make changes to the program in order to reflect the newly created filter.
Comment the existing call of the instance method and Call the instance method again using the
PATTERN.
As seen above the second call to the method has the additional filter parameters FLT_VAL.
Pass appropriate values to the parameters and once done with changes save it and activate the program
for testing.
Before testing place a breakpoint on each of the implementations to see which one gets triggered in what
sequence.
Now since we are using the filter value passed by the program and as the above check fails the execution
will come out without executing.
now if you hit F7 to proceed to the next execution you will notice that the execution has returned back to
the program.
The simple reason being the second implementation filter check failed. That means that we are passing
the filter value SAPUSER from the program and inside the Implementation we have added the filter as
user SAPUSER1. So since the filter value does not match the system does not trigger the second BADI
implementation and hence there is no output.
Now lets make one change in the FIRST BADI IMPLEMENTATION. We will remove the check we had
introduced in the code.
We have commented the line as shown above. Lets execute the program again and see the system
behavior.
Now if you see from above, the FIRST IMPLEMENTATION has triggered as the value of the FILTER
passed from the program and the value of the FILTER maintained in the Implementation section
matches.
But it does not trigger the SECOND IMPLEMENTATION as the value of the filter passed from the
program does not match the value of the FILTER maintained in the implementation section.
Now lets change the calling program and change the filter value such that it DOES not trigger the FIRST
IMPLEMENTATION but triggers the SECOND IMPLEMENTATION.
Now we are passing the filter value as SAPUSER1 instead of SAPUSER. Now when we execute the
program the system should trigger only the SECOND IMPLEMENTATION of the BADI and not the first
one. Lets execute the program and confirm this
As seen above the system does not trigger the first implementation but it directly triggered the SECOND
IMPLEMENTATION as the value of the filter passed by the program and the value of the filter maintained
in the implementation section matches.