BAdI Basics: Definition, Interface and Implementation
Understand the basic structure of a BAdI and how definition, interface and implementation work together.
Explanation
A BAdI has a definition and one or more implementations. The definition describes the enhancement option and usually provides an interface. The implementation contains the custom logic written by the developer. At runtime, SAP standard code calls the BAdI method, and the active implementation logic is executed. In simple terms, SAP provides a plug point and the customer writes logic inside that plug point. This is safer than modifying SAP standard code directly. In ECC, both classic and new BAdIs are used. In S/4HANA, released BAdIs are especially important for clean-core extension strategy.
Code example
* Purpose:* This is a simple conceptual BAdI call flow.* SAP standard gets the BAdI instance and calls the interface method.* The active customer implementation is executed at runtime. DATA lo_badi TYPE REF TO zif_ex_po_check. * Step 1: Get BAdI implementation objectGET BADI lo_badi. * Step 2: Call BAdI method* Custom implementation logic runs here if activeCALL BADI lo_badi->check_purchase_order EXPORTING is_header = ls_header it_item = lt_item CHANGING ct_return = lt_return. * Step 3: Caller reads return messages and decides whether to continueIF line_exists( lt_return[ type = 'E' ] ). MESSAGE 'Purchase order validation failed' TYPE 'E'.ENDIF.Real project scenario
A purchase order validation requirement can be handled through a purchasing BAdI where custom checks are added before save, instead of modifying SAP standard purchase order code.
Common mistakes
- Confusing BAdI definition and implementation. - Thinking BAdI always has only one implementation. - Not checking active implementation status. - Writing all logic directly inside BAdI method.
Best practices
- Understand BAdI definition before implementation. - Check interface method signature carefully. - Keep implementation logic focused. - Use return messages instead of uncontrolled errors.
Interview angle
A beginner should explain BAdI as a standard enhancement plug point. An experienced candidate should explain definition, interface, implementation and runtime call.