BAdI Part 2: Finding and Implementing a BAdI Step by Step
Implement a BAdI end to end: locate it (SPRO, SE18, debugger), create the implementation in SE19 for classic and new BAdIs, write the method using its parameters, raise messages the way the application expects, activate, test and transport.
Explanation
📌 KEY POINTS
✅ Find BAdIs via SPRO ("Business Add-Ins" nodes), SE18/SE84 by package, or the debugger (Part 6).
✅ SE19: enter the BAdI (classic) or enhancement spot (new), create an implementation, SE19 generates the class with empty methods.
✅ Report errors the way the BAdI expects: CHANGING flags, exceptions declared in the interface, or application message macros.
⚠️ An implementation that is created but not activated does nothing — and an active, faulty one can stop the whole transaction.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Part 1 explained the structure. Now we build one from start to finish.
━━━━━━━━━━━━━━━━━━━━
▶ 1. FIND IT
- SPRO: many areas have "Business Add-Ins (BAdIs)" nodes with documentation (e.g. MM → Purchasing → BAdIs).
- SE18 → F4 by application component or package; SE84 → Enhancements → Business Add-Ins.
- Debugger: breakpoint at CL_EXITHANDLER=>GET_INSTANCE or statement GET BADI.
- Read the documentation and check "Multiple use" and filter settings.
━━━━━━━━━━━━━━━━━━━━
▶ 2. CREATE THE IMPLEMENTATION (SE19)
- Classic BAdI: Create Implementation → classic BAdI name → implementation name ZIM_… → class ZCL_IM_… is proposed.
- New BAdI: Create Implementation → enhancement spot → enhancement implementation ZEI_… → BAdI implementation ZBI_… → implementing class ZCL_… ; set filter values if the BAdI is filter-dependent.
- Package and transport.
━━━━━━━━━━━━━━━━━━━━
▶ 3. WRITE THE METHOD
Double-click the method → code. Use only the method's parameters and what their objects provide.
Example BADI_MATERIAL_CHECK method CHECK_DATA: parameters WMARA, WMARC and others; the interface declares exception APPLICATION_ERROR → MESSAGE e… RAISING application_error.
Example ME_PROCESS_PO_CUST: messages through the MM macros (INCLUDE mm_messages_mac, mmpur_message_forced) plus CH_FAILED.
━━━━━━━━━━━━━━━━━━━━
▶ 4. ACTIVATE AND TEST
- Activate the class and the implementation (classic: the Activate button in SE19).
- Set a breakpoint, run the transaction, check the parameters.
- Test negative and positive cases; test BAPI/background paths if the BAdI runs there.
━━━━━━━━━━━━━━━━━━━━
▶ 5. TRANSPORT
Implementation and class are in your transport request. After import, check that it is active in the target system (SE19).
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- SE18: open BADI_MATERIAL_CHECK and read method CHECK_DATA.
- SE19: create ZIM_MAT_CHECK; implement a check that material group is mandatory for material type ZFER.
- Activate and test in MM01/MM02.
✅ CHECKPOINT: you can find, implement, activate and test a BAdI with correct error handling.
Code example
* ===== Classic BAdI BADI_MATERIAL_CHECK, implementation ZIM_MAT_CHECK =====CLASS zcl_im_mat_check DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. INTERFACES if_ex_badi_material_check.ENDCLASS. CLASS zcl_im_mat_check IMPLEMENTATION. METHOD if_ex_badi_material_check~check_data.* Parameters come from the interface (see SE18): WMARA = material header data IF wmara-mtart = 'ZFER' AND wmara-matkl IS INITIAL. MESSAGE e001(zmm) RAISING application_error. " exception declared in the interface ENDIF. ENDMETHOD.* other methods of the interface remain emptyENDCLASS. * ===== Classic BAdI ME_PROCESS_PO_CUST: message with MM macros =====CLASS zcl_im_po_check DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. INTERFACES if_ex_me_process_po_cust.ENDCLASS. CLASS zcl_im_po_check IMPLEMENTATION. METHOD if_ex_me_process_po_cust~check. INCLUDE mm_messages_mac. " macros for PO messages DATA ls_header TYPE mepoheader. ls_header = im_header->get_data( ). IF ls_header-bsart = 'ZNB' AND ls_header-ekgrp IS INITIAL. mmpur_message_forced 'E' 'ZMM' '002' ls_header-ebeln '' '' ''. ch_failed = abap_true. ENDIF. ENDMETHOD.ENDCLASS. * ===== New BAdI implementation (SE19 via enhancement spot) - structure =====* Enhancement implementation ZEI_ORDER_CHECK* BAdI implementation ZBI_ORDER_CHECK (filter e.g. VKORG = '1000')* Implementing class ZCL_BI_ORDER_CHECK:* CLASS zcl_bi_order_check DEFINITION PUBLIC FINAL CREATE PUBLIC.* PUBLIC SECTION.* INTERFACES if_badi_interface. " marker interface of new BAdIs* INTERFACES zif_ex_order_check. " the BAdI interface* ENDCLASS.Real project scenario
A material master rule required a material group for finished goods. The developer found BADI_MATERIAL_CHECK via SPRO documentation, created ZIM_MAT_CHECK, and raised APPLICATION_ERROR with a Z message.
The check worked in MM01 but mass changes via MASS and the material upload program also stopped on missing groups — intended, but the upload team had not expected it. The team added the BAdI to the interface test plan and communicated the new rule before go-live.
Common mistakes
- Not activating the implementation.
- Using MESSAGE type E without RAISING where the interface expects an exception.
- Displaying messages the application cannot handle (e.g. popups).
- Ignoring filter values for new BAdIs.
- Testing only one transaction when the BAdI runs in several.
Best practices
- Read SE18 documentation and parameters first.
- Use the error mechanism the interface defines.
- Keep the method thin; call a Z class.
- Test dialog, mass change and interfaces.
- Check activation in each system after transport.
Interview angle
Questions: "How do you implement a BAdI?", "How do you raise an error in a BAdI?", "Where do you find BAdIs?"
Strong answer: find via SPRO/SE18/SE84/debugger; SE19 create implementation (classic: implementation + class; new: enhancement implementation, BAdI implementation, class with IF_BADI_INTERFACE, filter values); code with method parameters; errors via interface exceptions, CHANGING flags or application macros; activate, test all paths, transport and verify.
Practice this lesson
Quick check
1. Which object must an implementing class of a new BAdI implement besides the BAdI interface?
2. BAdI implementation is created in:
3. Which transaction is commonly used to create BAdI implementations?
Interview questions
1. How do you find the correct BAdI to enhance a transaction?
Answer it in your own words first, then compare.
2. Different company codes need different validations in a process where SAP offers a BAdI. How do you find and implement the right BAdI?
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.
More lessons in this topic
- BAdI Part 1: What a BAdI Is and How SAP Calls It
- BAdI Part 10: BAdIs in S/4HANA and Clean Core
- BAdI Part 3: Designing Your Own BAdI — Fallback Class and Filters
- BAdI Part 4: Classic BAdI vs New BAdI
- BAdI Part 5: Single-Use vs Multiple-Use BAdIs
- BAdI Part 6: Debugging BAdIs in Real Projects
- BAdI Part 7: Using Filter-Dependent BAdIs
- BAdI Part 8: Implementation Design — Keep BAdI Logic Clean