Skip to main content

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.
And do an F1 on the FILTER TYPE field.
Click on the F4 on the FILTER TYPE field name and enter some search criteria to find a relevant data element.
And click on the continue button
 

Select the data element from the list to set up your filter and hit enter.
Click on the save button and active the BADI definition.
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.
Click on continue to proceed
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.
 
Select the first implementation and click on the continue button.
Now click on the ATTRIBUTES tab to see the difference.
You will notice that now the implementation is capable of adding filters for the user names. You can click on the INSERT ROW button to add any new filters.  
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.
Once done click on save and activate the implementation.
Similarly add filter to the other implementation and save and activate.
 
As seen from the above we have used a different user name in the other implementation. So this means that the first implementations will execute for user SAPUSER and the second implementation will be executed for the other user SAPUSER1. This is the main functionality of the Filters in the BADI’s you can control when a BADI should be triggered in the system.
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.
Execute the program and check if its stops at the breakpoint.
As seen from above it triggers the first IMPLEMENTATION of the BADI the reason being we passed the filter value SAPUSER and we defined the filter value as SAPUSER in the implementation screen. So since these two values match the system triggered the first implementation and the execution stops at breakpoint place in the method.
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.
And we can see the new output.
This how we can use the filters to control the way a BADI should trigger. This is very useful concept introduced by SAP for customer enhancements.

Comments

katrinaDcruz said…
Thanks for sharing this Information, Got to learn new things from your Blog on Sap. Learn More from http://abapinho.com/2016/02/acrescenta-parametros-a-metodos-e-funcoes-standard/

Popular posts from this blog

Create Data Source in SAP

Data Sources are extraction structure. Data Sources are used to extract data from various source system. In the below steps, we will see how to create a data source using a SAP table VBAK. 1) Execute transaction RSO2 2) Enter data source name to be created 3) Press Create 4) Enter description of the data source 5) Enter the name of table or view on which data source has to be created. Data Source can also be created using a View, Info set or a Function Module. 6) Save the data source 7) Execute RSO2 again and click Change 8) Select VBELN field as selection 9) Save the Data Source 11) To check whether data is getting extracted, execute transaction RSA3 12) Enter the name of data source as shown below and press 'Extraction' 13) An information message will appear stating no. of records fetched 14) Additional button 'Display list' will appear, press button 15) Select one of the data packet and double click to get records fetched 16) Data Source is ready to be used!

Responsibilities of BW Data Architect

Responsibilities of an implementation project... For ex, Lets say If its a fresh implementation of BI or for that matter you are implementing SAP... First and foremost will be your requirements gathering from the client. Depending upon the requirements you will creat a business blueprint of the project which is the entire process from the start to the end of an implementation... After the blue print phase sign off we start off with the realization phase where the actual development happens... In our example after installing the necessary softwares, patches for BI we need to discuss with the end users who are going to use the system for inputs like how they want a report to look like and what are the Key Performance Indicators(KPI) for the reports etc., basically its a question and answer session with the business users... After collecting those informations the development happens in the development servers... After the development comes to an end the same objects are tested in quality