BAdIs — Business Add-Ins
SAP's primary in-system developer extension mechanism — implement released Business Add-In interfaces to inject custom business logic into standard S/4HANA processes without modifying a single line of SAP code.
BAdI Architecture
Executive Summary
BAdIs (Business Add-Ins) are SAP's primary mechanism for injecting custom business logic into standard S/4HANA processes. SAP defines Enhancement Spots in the standard code where customers can implement custom logic via released BAdI interfaces. The customer code runs inside S/4HANA but is fully isolated from SAP standard objects — and because the BAdI interface carries a C1 release contract, it is guaranteed stable across S/4HANA upgrades for 10+ years.
BAdI Types
Uses GET BADI + CALL BADI syntax. Still present in S/4HANA standard code but cannot be used in ABAP Cloud development. Do not create new implementations using this pattern.
Uses BADI_INSTANTIATE or CL_BADI_CONTEXT=>GET_DATA. Fully ABAP Cloud-compatible. All new BAdI implementations must use this pattern.
SAP-published BAdIs with an explicit C1 release contract. Guaranteed stable for 10+ years. These are the only BAdIs customers should implement in a Clean Core context.
BAdI Implementation Workflow
- 1Search for released BAdIs in SPRO or SAP Help for the target business process area
- 2Create an Implementation class in ADT (set ABAP language version: Cloud Development)
- 3Implement the released BAdI interface methods in the class
- 4Activate the Implementation under Enhancement Spot → Enhancement Implementation
- 5Optionally set filter values to restrict when the implementation fires
- 6Write ABAP Unit tests covering the implementation logic
- 7Run ATC check — resolve all findings before transport
- 8Transport to Quality and run regression test suite
DEWA BAdI Implementation — Pricing Logic
This example implements the SD_COND_ACCESS_BADI (C1-released) to apply a government entity pricing discount for DEWA's government customer segment.
" =====================================================
" DEWA — Sales Order Pricing BAdI Implementation
" Enhancement Spot: SD_COND_ACCESS_BE
" BAdI Name: SD_COND_ACCESS_BADI (Released — C1)
" =====================================================
CLASS zcl_dewa_pricing_badi DEFINITION
PUBLIC FINAL
CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_badi_sd_cond_access. " Released BAdI interface (C1)
ENDCLASS.
CLASS zcl_dewa_pricing_badi IMPLEMENTATION.
METHOD if_badi_sd_cond_access~determine_access_sequence.
" DEWA custom pricing: apply UAE government discount for public entities
" This method is called for each condition type access
" Only process DEWA-specific pricing condition Z_GOV_DISC
CHECK iv_kschl = 'Z_GOV_DISC'.
" Read customer data via released CDS view
SELECT SINGLE
yy1_customertier_bpa AS customer_tier
FROM i_businesspartnerbasic
WHERE BusinessPartner = @iv_kunnr
INTO @DATA(lv_tier).
IF sy-subrc = 0 AND lv_tier = 'GOV'.
" Government customer — apply 10% discount
APPEND VALUE #(
knumh = 'GOVT_DISC_10'
datab = sy-datum
datbi = '99991231'
) TO et_konv_add.
ENDIF.
ENDMETHOD.
ENDCLASS.ABAP Unit Tests for the BAdI
" =====================================================
" ABAP Unit Test for the BAdI Implementation
" =====================================================
CLASS ltc_dewa_pricing_badi DEFINITION FOR TESTING
RISK LEVEL HARMLESS DURATION SHORT.
PRIVATE SECTION.
METHODS:
setup,
test_gov_customer_gets_discount FOR TESTING,
test_non_gov_no_discount FOR TESTING.
DATA: mo_cut TYPE REF TO zcl_dewa_pricing_badi.
ENDCLASS.
CLASS ltc_dewa_pricing_badi IMPLEMENTATION.
METHOD setup.
mo_cut = NEW zcl_dewa_pricing_badi( ).
ENDMETHOD.
METHOD test_gov_customer_gets_discount.
DATA: lt_konv_add TYPE STANDARD TABLE OF ty_konv.
" Act — government customer
mo_cut->if_badi_sd_cond_access~determine_access_sequence(
EXPORTING iv_kschl = 'Z_GOV_DISC'
iv_kunnr = 'CUST_GOV_001'
CHANGING et_konv_add = lt_konv_add
).
" Assert — discount condition added
cl_abap_unit_assert=>assert_not_initial(
act = lt_konv_add
msg = 'Government customer should receive discount condition'
).
ENDMETHOD.
METHOD test_non_gov_no_discount.
DATA: lt_konv_add TYPE STANDARD TABLE OF ty_konv.
mo_cut->if_badi_sd_cond_access~determine_access_sequence(
EXPORTING iv_kschl = 'Z_GOV_DISC'
iv_kunnr = 'CUST_PRIV_001'
CHANGING et_konv_add = lt_konv_add
).
" Assert — no discount for private customer
cl_abap_unit_assert=>assert_initial(
act = lt_konv_add
msg = 'Private customer should not receive government discount'
).
ENDMETHOD.
ENDCLASS.How to Discover Released BAdIs
DEWA Enterprise Implementation
- BAdIs Implemented
- 4
- All C1-Released
- Yes
- ABAP Unit Test Coverage
- 100%
- ATC BLOCKER Findings
- 0
Best Practices
Before implementing any BAdI, confirm the interface has a C1 release contract in ADT (Properties tab). Un-released BAdIs have no stability guarantee.
Write ABAP Unit tests before committing the BAdI implementation to a transport. Test the happy path, edge cases, and error scenarios.
Set filter values (plant, country, document type) to restrict when your BAdI fires. A BAdI called for all documents when only needed for one type wastes system resources.
One BAdI implementation class = one business responsibility. Do not combine multiple unrelated customisations into a single implementation class.
Subscribe to SAP Note updates for BAdIs you have implemented. SAP occasionally adds optional methods to released BAdI interfaces in Feature Pack Stacks.