Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 54

Contents :

1.BADI
2. Difference between Customer exit and BADI
3. Different ways of finding BADI
4. Types of BADI – 1.Standard BADI
2. Custom BADI
3. Filter BADI
5. BADI Sequencing
6. BADI with Fallback Class

BADI:
 Business Addins
 It is based on object oriented programming
 In Userexits (Customerexits) the same exit cannot be reuse in other projects
 In BADIs the same BADI definition can be implemented in N number of
implementations
 BADI concept is purely designed based on object oriented programming
 For implementing BADI, SAP will provide you an interactive & respective
implementation class
 Here interface is a collection of methods where you have to implement the
additional code

Advantages of BAdi’s:

 The main advantage of using badi’s is , we can create multiple


implementations for a single BADI definition.
 Whereas 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.

Note:
T codes for working with BADIs are

 SE18 -------- for BADI definition
 SE19 -------- for BADI implementation

 The interface name for a badi will be as below.

 Ex:- ZIF_EX_<BADI NAME>

 The class name for a badi will be as below.

 Ex:- ZCL_EX_<IMPLEMENTATION NAME>

Navigation for 7wg BADI:

1st Method:

 Go to SE24
 Object Type: CL_EXITHANDLER
 Display
 Double click on method GET_INSTANCE
 Place cursor at call method CL_EXITHANDLER
 Go to GET_INSITANCE method
 GET_CLASS_NAME_BY_INTERFACE
 Select Dynamic Break Point, stop

 Go to VA01 ( Any T-code you want find out BADI)


 Variable: EXIT_NAME we can find all possible BADI’s.

2nd Method:

 Find package name for T-code


 Go to SE80
 Select Package
 Provide package name
 Enter
 Expand Enhancements
 Expand Classic BADIs Def

Types of BADI:
1. Standard BADI
2. Custom BADI
3. Filter BADI

***Standard BADI:

 In Standard BADI, BADI definitions are predefined (given by SAP)


 In Standard BADI we have to provide only implementation section

Object-1:
In XK02 (Vendor) BADI : VENDOR_ADD_DATA METHOD :
CHECK_ALL_DATA

BUSINESS REQUIREMENT

 Raise an error message whenever the vender belongs to Germon


country and Region is not specified.

STEP 1:Find the list of the BADIS for TCODE XKO2.


 GO TO SE24
 Give the class name as CL_EXIT HANDLER
 Click on display
 Double click on the method GET_INSTANCE
 Put a break point
 Execute the TCODE /NXKO2
 Give the vender no as 1
 Select all the check boxes
 Press enter
 Give the country as DE and click on save
 The debugger will start and note down the list of the BADIS

VENDER_FIELDSTATUS
GOS_SRV_SELECT
ADDRESS_CHECK
ADDR_TXJCD_CHECK
CVI_CALL_BTE
ADDRESS_UPDATE
VENDER_ADD_DATA

 Go to se18
 Give the BADI NAME
 And check all the methods
 Find the suitable/roughly decide BADI name and method by reading the
description and checking the signature.
 Then create implementation

Step 2 : Creating implementation for the BADI


 Go to SE19
 give u r standard BADI name : vender_add_data.
 Give the implementation name as ZXK02_IMP
 Click on create

 Give the description


 Go to Interface tab
 Double click on the method check_all_data
 You will get a popup. Click on Ok
 You will get popup implementation ZXK02_IMP is migrated. Click ok

 Click on create button.

 Provide the Enhancement implementation name and description.

 Select created enhancement . Click on OK.


 In METHOD IF_EX_VENDER_ADD_DATA~CHECK_ALL_DATA write following
logic.

METHOD IF_EX_VENDER_ADD_DATA~CHECK_ALL_DATA.
IF I_LFA1-LAND1= ‘DE’ AND I_LFA1-REGIO =’ ‘.
Message ‘Region is required for GERMON VENDORS’ TYPE ‘E’.
ENDIF.
ENDMETHOD.

 Activate the method


 Back
 Activate the implementation

Step 3 : TESTING weather BADI is correct or not


 Now run the transaction XKO2. Vendor 1 . Enter.
 Do not provide any value for state or region . Click on Save.
 Now you will get a error message ‘Region is required for GERMON
VENDORS’ .
Custom BADI:
In Custom BADI, BADI definition is custom defined

Steps:
1. In SE18 - Create Custom BADI.
2. In SE19 - Create implementations for your BADI

Filter BADI:
 It is a part of Custom BADI
 In Filter BADI, the same definition can be called in different
implementations

 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.

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.

The filter value will be DE generally .

Examples of filter values are land1,bukrs,werks

Object:

Determine tax code for sales organization. Based on Sales organization.

Solution:
 Go to SE18
 Utilities --- Create Classic BADI
 Definition Name: ZBADI_CUST_FILTER
 Enter

 Scroll down to bottom, select Filter Depend check box


 Filter Type: VKORG
 Save
 Go to Interface tab

Note:
Based on your definition name system will create an interface
ZIF_EX_BADI_CUST_FILTER

 Double click on interface name ZIF_EX_BADI_CUST_FILTER


Method Level Description
GET_TAX INSATANCE getting tax details

 Select method GET_TAX


 Parameters

Parameter Type Associated Type


TAX CHANGING I

 Activate
 During activation you will find a message, Enter
 Once your interface is activated system will add additional parameter
FLT_VAL based on your filter type VKORG
 Back
 Activate

Implementation :

 Go to SE19
 Classic BADI
 BADI Name: ZBADI_CUST_FILTER
 Create Impl
 Enter
 Implementation Name: ZBADI_FIL1
 Enter

 Short Text: implementation for filter badi


 Scroll down to bottom
 Select ‘+’ Insert Row
Sales org
1000

 Save
 Interface tab
 Double click on GET_TAX
 Place cursor between METHOD………..ENDMETHOD
IF FLT_VAL = ‘1000’.
TAX = 10.
ENDIF.

 Activate
 Back
 Activate
 Back

 Classic BADI
 BADI Name: ZBADI_CUST_FILTER
 Create Impl
 Enter

 Implementation Name: ZBADI_FIL2


 Enter
 Short Text: implementation for filter badi
 Properties Tab
 Scroll down to bottom
 Select ‘+’ Insert Row

Sales org
1020
 Save
 Interface tab
 Double click on GET_TAX
 Place cursor between METHOD………..ENDMETHOD
IF FLT_VAL = ‘1020’.
TAX = 20.
ENDIF.

 Activate
 Back
 Activate
 Back

 Classic BADI
 BADI Name: ZBADI_CUST_FILTER
 Create Impl
 Enter
 Implementation Name: ZBADI_FIL3
 Enter
 Short Text: implementation for filter badi
 Scroll down to bottom
 Select ‘+’ Insert Row

Sales org
1030

 Save
 Interface tab
 Double click on GET_TAX
 Place cursor between METHOD………..ENDMETHOD

IF FLT_VAL = ‘1030’.
TAX = 30.
ENDIF.

 Activate
 Back
 Activate

Driver Program :
 Go to SE38
 Program: ZCAL_CUSTOM_FILTER_BADI
 Create
 Short Description
 Type: Executable Program
 Save
Final Code:

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE


TEXT-000.
PARAMETERS v_vkorg TYPE vkorg.
SELECTION-SCREEN: END OF BLOCK b1.

DATA v_tax TYPE I.

DATA obj TYPE REF TO ZIF_EX_BADI_CUST_FILTER.

* get reference of the class implemented


CALL METHOD CL_EXITHANDLER=>GET_INSTANCE
CHANGING
INSTANCE = obj.

IF SY-SUBRC NE 0.
MESSAGE ‘Error in calling BADI’ TYPE ‘E’.
ELSE.
CALL METHOD obj->get_tax
EXPORTING
FLT_VAL = V_VKORG
CHANGING
TAX = V_TAX.

IF V_TAX IS NOT INITIAL.


WRITE:/ ‘The tax code for sales organization’, V_VKORG, ‘is’, V_TAX.

ENDIF.
ENDIF.
Output:

For 1000 sales org:


For 1020 sales org:

BADI with Fallback Class:

Scenario: For a BADI definition if some BADI Implementations are exist then all
the active BADI implementations are called during run time. If all the BADI
implementations are inactive or does not exist then if there is any fallback class
exist then it is called during runtime. The FALLBACK class is a default
implementation of BADI definition which is called if all the BADI
implementations are inactive or none of the BADI implementation exists.
Step1. Go to TCODE-SE20. Create a Enhancement Spot
Step2. Provide a Enhancement spot name and click on the Create button.

 Step3. Provide a short text and click on the continue button.

Step4. Save in local object.


Step5. Create a BADI definition. Activate the enhancement spot and click on the
create button to create a BADI Definition.

Step6. Provide the BADI definition name and the description and at last click on
the Continue button.
Step7. Some of the BADI definition properties are Multiple use.

Step8. Expand the BADI definition, click on the Interface element from the left
hand side. Then provide the Interface name 'ZIF_SHOW_MESSAGE' in the right
hand side and then double click on it. A popup will appear stating to create the
same . Click on YES button to create it.
Step9. Now provide a method description and activate it and go back.

Step10. Activate it.

Step11. Create a BADI Implementation. Expand the BADI definition in the L:H:S.
Select the Implementation and click on the highlighted button to create the
implementation.
Step12. Now provide a Enhancement implementation name and description and
click on the continue button.

Step13. Now provide the BADI Implementation name, description and the
implementing class name and click on the continue button.

Step14. Now expand the BADI implementation form the L:H:S and click on the
Implementing class to implement the method.
Step15. Now double click on the Method Name to implement it.

Step16. click on YES to continue.

Step17. Provide some in the method and activate it. At last click on the BACK
button .
Step18. Now one BADI implementation is created for the BADI definition.

Step19. Go to SE38 to create a report and calling the BADI implementation.


Provide the Report name and click on the Create button.

Step20. Provide the below code. activate it and RUN it.


Step21. The Active Implementation is called.

Step22. Go to the BADI implementation .


Step23. Deselect the check box and activate the Enhancement implementation.

Step24. Now again run the program.

Step25. The output is as shown below. As the BADI implementation is inactive.


Step26. Now go to the BADI Definition.

Step27. Select the check box and provide a fall back Class name and double click
on it. From the popup click YES to continue.
Step28. Now double click on the method to implement it.

Step29. Provide some statement and activate it. At last click on  BACK button.

Step30. Now activate the class and go back.


Step31. After this the Enhancement spot is inactive.

Step32. Activate the enhancement spot.


Step33. Run the Report.

Step34. The output is as shown below. As the BADI implementation is Inactive


and the FALLBACK class is exists.

Step35. Go to the BADI implementation and activate it again by selecting the


check box.
Step36. Now run the report.

Step37. The output is as shown below.

BADI Sequencing:

The sequence for execution of BAdI implementations can be controlled for BAdIs
used on a multiple basis by a sort mechanism.

By default the implementations are executed randomly.

For implementing sorting in BAdi. After creation of BAdi, we need to select


sorting in utilities tab.

There are two types of sorting mechanisms :


Standard Sort : if sort is to take place using numeric sort values. The numeric
values are entered in the displayed field Layer Value when you create the
implementations and stored in a table. The implementations are executed in
accordance with the specified sequence.

Special Sort : if sorting is to take place using non-numeric sort values. In this case,
you need to enter the name of the implementation.

Example: Changing BAdi implementation sequence

Step1:Goto Se18.Create ZBADI_SEQUENC BAdi.

Step2: Provide short description. Make sure it is multiple use check box is enable
Step3: Goto Interface tab. Double click on ZIF_EX_BADI_SEQENCE. Create
method as follows.

Step4: Activate method.

Step5: Back. Activate BAdi.

Stpe6: To implement sequence . Goto -> Utilities -> Sort.


Step 7: Select Standard Sort. Click ok.

Step 8: Create workbench request. Click ok.

Step 9: Implemenatation of BAdi.

Goto – SE19 .Select Classical BAdi.

BADI : ZBADI_SEQENCE.

Click on Create Imp.


Step 10: Provide Implementation Name : ZSEQ_IMP1

Step 11: Provide Shot description.

Goto – Properties Tab.


Layer value – 1 i.e this implementation is going to execute 1st.

Step 12: Goto Interface tab. Double click on MESSAGE method.


Step 13: Write following code in METHOD ….. ENDMETHOD.

Activate Method.

Step 14: Go to SE19 – Create one more implementation


Step 15: Give Imp name as ZSEQ_IMP2

Step 16: Provide short description.

Layer value : 2 – its going to execute 2ed in the sequence.


Step 17: Go to Interface tab – double click in Message method.

Step 18: Write following code in METHOD …. ENDMETHOD.

Activate.

Step 19: Back . Activate the Implementation.

Step 20: Go to SE19 – Create one more implementation : ZSEQ_IMP3


Step 21: Give Layer vales as 3 – Its going to be execute 3ed in the sequence.

Step 22: Write following logic in the METHOD … ENDMATHOD.

Activate.
Step 23: Back.

Activate the Implementation.

Step 24: Creating Driver Program :

Go to – SE38

Create a executable report : ZBADI_SEQ_PROGRAM


Step 25: Write the following code in the program.

Step 26: Activate the program.

Step 27: Execute Program.


Based on Layer value the implementations are executed.

You might also like