ERPClimb logoERPClimb
BAdI
ABAP Developmentintermediate 8 min read

BAdI Part 3: Designing Your Own BAdI — Fallback Class and Filters

Lessons are open to try during our launch period. Some advanced content may move to Pro later. AI practice limits apply separately.

Key takeaway

Create your own new BAdI for Z programs: enhancement spot, BAdI definition, interface, filter (e. g. country or company code), fallback class for default behaviour, calling it with GET BADI / CALL BADI, and handling CX BADI NOT IMPLEMENTED.

In this lessonShow sections

Visual overview

BAdI Part 3: Designing Your Own BAdI — Fallback Class and Filters — learning sheetFlow: Create spot, BAdI, interface, filter and fallback class as above → Call it from a Z report (code example) → Implement it for company code 1000 and compare output with company code 2000 (fallback). Key ideas: WHEN TO CREATE AN OWN BADI; BUILD IT (SE18 / SE20); CALL IT; IMPLEMENTATIONS. Watch out: For single-use BAdIs without fallback, GET BADI raises CX_BADI_NOT_IMPLEMENTED if no implementation exists — handle it.ERPClimb.com / ABAP / LESSON 3/10 / LEARNING SHEETBAdI Part 3: Designing Your Own BAdI — Fallback Class andFilters1 · HOW IT FLOWS1Create spot, BAdI,interface, filter andfallback class as above2Call it from a Z report(code example)3Implement it for companycode 1000 and compareoutput with company code…2 · KEY IDEAS EXPLAINEDWhen To Create An Own BAdIA Z program runs in several countries or companieswith different rules.Other teams must extend your logic independently.Build It (SE18 / SE20)1. Create enhancement spot ZES_INVOICE_CHECK(package, transport).Call ItWith a fallback class, a single-use BAdI alwaysfinds an implementation.Multiple-use BAdIs call all matchingimplementations; with none, the call does nothing.ImplementationsCompany-specific teams create implementations withfilter values (BUKRS = 1000, BUKRS = 2000). Thecore program stays unchanged.3 · REMEMBER · WATCH OUTRememberYou can define your own new BAdIs in Z programs so others can extendthem without changing your code.Filters (e.g. BUKRS, LAND1) select the implementation for the currentcontext.A fallback class provides default behaviour when no implementationmatches the filter.!Watch outFor single-use BAdIs withoutfallback, GET BADI raisesCX_BADI_NOT_IMPLEMENTED if noimplementation exists — handle it.4 · IN A REAL PROJECTA shared service centre ran one invoice verification program for 12 company codes. Local rules were firstcoded as IF bukrs = … blocks, and every change required retesting all companies. A custom BAdI with filterBUKRS and a fallback class for the group-wide rule allowed each company team to maintain its own…Original ERPClimb learning sheet • Verify against your SAP release and edition

Expert visual walkthrough

ABAP DEVELOPMENT ACADEMY · Architecture hierarchyERPClimb.com

Designing Your Own BAdI — Fallback Class and Filters

BAdI · Chapter-specific technical teaching map

Architecture hierarchy

1Top level

BAdI definition

2Related level

Interface

3Related level

Fallback class

4Related level

Filter values

Tutor's chapter takeaway

Create your own new BAdI for Z programs: enhancement spot, BAdI definition, interface, filter (e.g. country or company code), fallback class for default behaviour, calling it with GET BADI / CALL BADI, and handling CX_BADI_NOT_IMPLEMENTED.

In a real project

A shared service centre ran one invoice verification program for 12 company codes. Local rules were first coded as IF bukrs = … blocks, and every change required retesting all companies. A custom BAdI with filter BUKRS and a…

Watch out for

• No fallback class for a single-use BAdI (CX_BADI_NOT_IMPLEMENTED). • Changing the interface after implementations exist. • Displaying messages inside implementations. • Filters that are too fine-grained or overlapping. •…

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

The situation: a real project scenario

A shared service centre ran one invoice verification program for 12 company codes. Local rules were first coded as IF bukrs = … blocks, and every change required retesting all companies.
A custom BAdI with filter BUKRS and a fallback class for the group-wide rule allowed each company team to maintain its own implementation. The core program was frozen, and a new company code only needed an implementation if it deviated from the default.

Explanation

Parts 1 and 2 implemented SAP's own BAdIs. Now it's time to design one of your own — a typical need in global templates used across several countries or companies.

A few situations call for defining your own BAdI: a Z program running across several countries or companies, each with different rules; other teams needing to extend your logic independently, without touching your code; or simply a default behavior that needs exceptions for particular units. You can define your own new BAdIs in Z programs so others can extend them without changing your code.

Building one starts in SE18 and SE20. First, create an enhancement spot, say ZES_INVOICE_CHECK, with its package and transport. Inside that spot, create a BAdI definition, ZBADI_INVOICE_CHECK. Its settings include whether it's single use or multiple use — a distinction covered in Part 5 — along with "Limited filter use" and an instance-creation mode.

Define an interface, ZIF_EX_INVOICE_CHECK, with a method CHECK that takes IMPORTING is_invoice and either EXPORTING et_messages or RAISING a dedicated exception class. Add a filter on BUKRS, typed as BUKRS, with the usual comparison operators allowed. Filters (e.g. BUKRS, LAND1) select the implementation for the current context.

And create a fallback class, ZCL_INVOICE_CHECK_DEFAULT, implementing both the interface and IF_BADI_INTERFACE — this provides default behaviour when no implementation matches the filter.

Calling it looks like GET BADI lo_badi FILTERS bukrs = lv_bukrs. followed by CALL BADI lo_badi->check EXPORTING … . With a fallback class in place, a single-use BAdI always finds an implementation to run. A multiple-use BAdI, by contrast, calls every matching implementation it finds, and if none match, the call simply does nothing. For single-use BAdIs without fallback, GET BADI raises CX_BADI_NOT_IMPLEMENTED if no implementation exists — handle it, since there's no silent default to fall back on in that case.

From there, company-specific teams create their own implementations with their own filter values — BUKRS = 1000 for one, BUKRS = 2000 for another — and the core program itself never needs to change.

A few design tips matter here: keep the interface stable, since changing it breaks every existing implementation at once; pass data as structures or tables rather than loose parameters; and return messages rather than displaying them directly, leaving that choice to the caller. It's also worth documenting clearly what each method is expected to do, and exactly when it gets called.

As an exercise, create the spot, BAdI, interface, filter and fallback class as described above, call it from a Z report as shown in the code example, and implement it for company code 1000, comparing its output against company code 2000, which falls back to the default. By the end, you should be able to provide your own filter-dependent BAdI, complete with sensible default behavior.

Code example

ABAP Code
* ===== Interface ZIF_EX_INVOICE_CHECK (BAdI interface) =====* INTERFACE zif_ex_invoice_check PUBLIC.*   INTERFACES if_badi_interface.*   METHODS check*     IMPORTING is_invoice  TYPE zs_invoice*     EXPORTING et_messages TYPE bapiret2_t.* ENDINTERFACE. * ===== Fallback class: default rule for all company codes =====* CLASS zcl_invoice_check_default DEFINITION PUBLIC FINAL CREATE PUBLIC.*   PUBLIC SECTION.*     INTERFACES if_badi_interface.*     INTERFACES zif_ex_invoice_check.* ENDCLASS.* CLASS zcl_invoice_check_default IMPLEMENTATION.*   METHOD zif_ex_invoice_check~check.*     " default: amount must be positive*   ENDMETHOD.* ENDCLASS. * ===== Core program calling the own BAdI =====REPORT zinvoice_check. PARAMETERS p_bukrs TYPE bukrs DEFAULT '1000'. DATA: lo_badi     TYPE REF TO zbadi_invoice_check,      ls_invoice  TYPE zs_invoice,      lt_messages TYPE bapiret2_t,      ls_message  TYPE bapiret2. START-OF-SELECTION.  ls_invoice-bukrs  = p_bukrs.  ls_invoice-amount = '-10'.   TRY.      GET BADI lo_badi FILTERS bukrs = p_bukrs.      " fallback if no filter match      CALL BADI lo_badi->check        EXPORTING is_invoice  = ls_invoice        IMPORTING et_messages = lt_messages.    CATCH cx_badi_not_implemented.                  " only without fallback class      WRITE: / 'No implementation for company code', p_bukrs.  ENDTRY.   LOOP AT lt_messages INTO ls_message.    WRITE: / ls_message-type, ls_message-message.  ENDLOOP. * ===== Company-specific implementation (filter BUKRS = 1000) =====* METHOD zif_ex_invoice_check~check.*   " company 1000: additionally require a reference*   IF is_invoice-xblnr IS INITIAL.*     ls_msg-type = 'E'. ls_msg-id = 'ZFI'. ls_msg-number = '010'.*     APPEND ls_msg TO et_messages.*   ENDIF.* ENDMETHOD.

Watch out

Common mistakes

  • No fallback class for a single-use BAdI (CX_BADI_NOT_IMPLEMENTED).
  • Changing the interface after implementations exist.
  • Displaying messages inside implementations.
  • Filters that are too fine-grained or overlapping.
  • Creating an own BAdI where a simple customizing table would do.

Do this

Best practices

  • Use a fallback class for default behaviour.
  • Design a stable interface returning messages.
  • Choose filters matching the organisational split.
  • Document the BAdI contract.
  • Catch CX_BADI_NOT_IMPLEMENTED where no fallback exists.

In the interview

Interview angle

Questions: "How do you create your own BAdI?", "What is a fallback class?", "What happens if no implementation exists?"
Strong answer: enhancement spot + BAdI definition (single/multiple use, filter) + interface with IF_BADI_INTERFACE + optional fallback class; call with GET BADI … FILTERS and CALL BADI; fallback provides default behaviour; single-use without implementation raises CX_BADI_NOT_IMPLEMENTED, multiple-use simply calls nothing.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

A single-use custom BAdI has a fallback class. What happens for a filter value with no implementation?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1A new sales organization went live, and suddenly a custom BAdI-based check was not applied to it. The BAdI is filter-dependent by sales organization. What happened, and how should the BAdI be designed?

2Difference between classic and new BAdI.

Try a related Code Lab

This published exercise covers the same SAP topic. Apply the ideas in a hands-on scenario, then return to review your answers.

Open: SELECT Inside BAdI Item Loop →

See it in code

Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.

Was this lesson helpful?

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.