BADI in SAP Enhance standard SAP applications using SAP enhancement frame work (BADI), add additional functionality to standard SAP applications
BADI and types of BADI SAP enhancement framework BADI, badi advantages, types of BADI available in SAP BADI (Business Add-in)
BADI is another way of implementing enhancements to the standard programs with out modifying the original code.
BADI’s are implemented using oo programming technique Technically a BADI is nothing but an interface.
Each BADI consists of the method with out implementation called as BADI definition.
We need to create classes to write the abap code by implementing the methods called as BADI implementation.
SE18 is the T-code for BADI definition, SE19 is the T-code for BADI implementation. Advantages of BADI
The main advantage of using BADI’s is , we can create multiple implementations
for a single BADI definition. Where as with the exits, we can create a single implementation.i.e a single project for a enhancement.
We cannot create another project (implementation) for enhancement which is already used. That is why we go for BADI’s.
Types of BADI
Single implementation BADI. Multiple implementation BADI.
Filter BADI.
Custom BADI (Not used/Rarely used)
Single implementation BADI:- A BADI which has only one implementation (single class) is called single implementation BADI. Multiple implementation BADI:- A BADI which has multiple implementations is called multiple implementation BADI. By default all the implementations will be executed. We cannot control the sequence of execution of multiple implementations. Filter BADI It is type of BADI which has a filter value so that only those implementations which satisfy the filter value are executed. The remaining implementations are not executed this type of BADI is called a filter BADI. Properties of BADI
If WITH IN SAP checkbox is selected then this BADI is only used by sap.
If multiple use checkbox is selected then it is a multiple implementation BADI.
If multiple use checkbox is not selected then it is a single implementation BADI.
If filter dependent checkbox is selected then it is filter dependent BADI. We need to specify the filter type such as land1,bukrs,werks.for the filter BADI.
Finding BADI for a T-code How to find a BADI in SAP ?, finding BADI for a transaction code in SAP There are two ways of finding BADI for transactions. 1. Using standard class CL_EXITHANDLER. 2. Using SE84 T-code. Using CL_EXITHANDLER Class to find BADI CL_EXITHANDLER is a class in SAP, it will trigger for each and every transaction in SAP, in this class there is a method called GET_INSTANCE, by using this method we can find the list of BADI`s for a transaction.
Steps to find BADI using CL_EXITHANDLER Go to T-code SE24,provide class name as CL_EXITHANDLER and display.
Double click on the method GET_INSTANCE and put a break-point on the below method GET_CLASS_NAME_BY_INTERFACE.
Execute the transaction (example VA01), the break-point will trigger, not down the values that comes to variable exit_name. (Press F8 to get next exit name, continue process until screen displays).
Using SE84 to find BADI Find package for a T-code.Go to SE93, provide t-code name(VA01), display.
Go to SE84, expand enhancements, expand Business Add-ins and select definition. Provide package name and execute, you will find list of BADI`s.
Some times you may need to use both the methods to find suitable BADI.
Real time example of using BADI in SAP Real time example of BADI for Vendor Master (Xk01) in SAP, BADI implementation for XK01 Requirement: Raise an error message whenever the vendor belongs to German and region is not specified. Requirement analysis In SAP vendors are created using T-code XK01, the created vendors will be stored in LFA1 (Vendor Master table), so we need to add custom functionality to validate region when creating vendor using XK01 (also when changing in XK02),to do this we go for BADI. To implement the BADI for XK01 we need to follow the below steps. Step1: Find the BADI. Step2: Select suitable BADI . Step3: Implement the BADI. Step4: Test the BADI.
Find the BADI for XK01/XK02 First step to implement BADI is finding the badi . Go to SE24 and put the break point in GET_INSTANCE method of CL_EXITHANDLER class. Go to LFA1, take a vendor no and go to XK02, provide vendor no, enter.
You will go to next screen, change any one value and click on Save (Ctrl S).
The break-point will be triggered, note down all BADI names.
Below are the list of BADI`s you will get
VENDOR_FIELDSTATUS
GOS_SRV_SELECT
ADDRESS_CHECK
ADDR_TXJCD_CHECK
CVI_CALL_BTE
ADDRESS_UPDATE
VENDOR_ADD_DATA
Select the suitable BADI and verify the BADI To select the suitable BADI, go to SE18, provide BADI name, display
Based on description and interface signature (importing and exporting parameters) we can choose and verify some BADI`s
Now VENDOR_ADD_DATA will be useful for our requirement.
Implement the BADI BADI uses object oriented concepts, BADI is nothing but a interface, to implement the BADI, we need to create implementation for the interface. To implement the BADI go to SE19(BADI Builder), provide BADI name, create implementation.
A popup will open, provide a implementaion name ex: ZVENDOR_ADD_DATA, continue.
Provide short description, based on description choose a method and double click to add owr own code.
Here CHECK_ALL_DATA will be useful for final checks, so double click on CHECK_ALL_DATA. METHOD IF_EX_VENDER_ADD_DATA~CHECK_ALL_DATA. BREAK-POINT. ENDMETHOD.
Go to XK02, provide vendor no, select address check box, change any one, save. Now our break point will trigger, so we can implement this because this is very much suitable for our requirement. Remove the break point and write the below code for implementing exit. METHOD IF_EX_VENDER_ADD_DATA~CHECK_ALL_DATA. IF I_LFA1=LAND1=`DE’AND I_LFA1-REGIO=` ‘. MESSAGE 'Region is required for German Vendors' TYPE 'E'. ENDMETHOD.
Save, activate the method, go back activate the implementation. Now BADI is implemented.
Test the BADI To test the BADI, go to XK02, provide a vendor no, enter. Change country to DE and Region to Space.
Save (Ctrl S). You will get a error message.
The BADI is implemented successfully.