ERPClimb logoERPClimb
BAdI
ABAP Developmentadvanced 8 min read

BAdI Part 8: Implementation Design — Keep BAdI Logic Clean

Preview · a free account unlocks the full lesson

Key takeaway

Design BAdI implementations that stay maintainable: thin implementing classes delegating to service classes, clear responsibilities per method, message handling, no UI and no COMMIT, testability with ABAP Unit, and naming/documentation standards.

In this lessonShow sections

Visual overview

BAdI Part 8: Implementation Design — Keep BAdI Logic Clean — learning sheetFlow: Take a long existing BAdI method and identify data access, rules and message handling → Extract the rule into a class and write two unit tests → Reduce the BAdI method to mapping + call + result mapping. Key ideas: ADAPTER PATTERN; SEPARATE RESPONSIBILITIES; CONTRACT RULES; TESTABILITY. Watch out: A 600-line BAdI method with SELECTs, rules and messages mixed together is the most common maintenance problem in enhancement code.ERPClimb.com / ABAP / LESSON 8/10 / LEARNING SHEETBAdI Part 8: Implementation Design — Keep BAdI Logic Clean1 · HOW IT FLOWS1Take a long existing BAdImethod and identify dataaccess, rules and message…2Extract the rule into aclass and write two unittests3Reduce the BAdI method tomapping + call + resultmapping2 · KEY IDEAS EXPLAINEDAdapter PatternBAdI method → read what it needs fromparameters/objects → map to a simple structure →call ZCL_…_RULES=>check( ) → map results back…Separate ResponsibilitiesData access in DAO classes (with buffering, Part9).Rules in rule classes (no dependencies on the BAdIinterface).Contract RulesUse only the method's intended purpose: CHECKmethods check, PROCESS methods change data, POSTmethods run at save.Errors: interface exceptions (e.g.APPLICATION_ERROR), CHANGING flags, applicationmessage macros — as documented.TestabilityRule classes with injected DAOs (OOP Part 9) →ABAP Unit tests.The adapter stays small enough that a manualtransaction test covers it.3 · REMEMBER · WATCH OUTRememberThe implementing class is an adapter: it translates BAdI parametersinto calls to your own service classes.Business rules live in reusable, unit-tested classes — the same rulecan then serve a report, OData service or another BAdI.Respect the BAdI's contract: use its error mechanism, don't COMMIT,don't display dialogs unless the method is meant for it.!Watch outA 600-line BAdI method with SELECTs,rules and messages mixed together isthe most common maintenance problemin enhancement code.4 · IN A REAL PROJECTA purchase order BAdI had grown to 900 lines over five years: approvals, budget checks, vendor rules and emailnotifications. Every change caused regressions, and nobody dared to touch it. The team split it into anadapter plus four rule classes with unit tests, and moved the email notification to an event after save…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Parts 1 through 7 covered the mechanics of implementing BAdIs. This lesson is about code quality inside those implementations — the thing that separates maintainable extension code from the most common maintenance problem in enhancement code: a 600-line BAdI method with SELECTs, rules and messages all mixed together.

The core idea is to treat the implementing class as an adapter: it reads what it needs from the BAdI's parameters and objects, maps that into a simple structure, calls out to your own service class — something like ZCL_…_RULES=>check( ) — and then maps the results back into whatever form the BAdI expects, whether that's CH_FAILED, an exception, a message, or a CHANGING parameter. The implementing class is an adapter: it translates BAdI parameters into calls to your own service classes.

This naturally separates responsibilities. Data access belongs in DAO classes, which can also handle buffering, as covered in Part 9. Business rules belong in rule classes that have no dependency on the BAdI interface at all. Business rules live in reusable, unit-tested classes — the same rule can then serve a report, OData service or another BAdI. Message conversion deserves its own single place too. Keeping these separate is what makes the rules themselves unit-testable without needing to start ME21N or VA01 just to exercise them.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

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.