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.
Find the BADI for XK01/XK02First 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
Select the suitable BADI and verify the BADITo 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.