ERPClimb logoERPClimb
BAdI
ABAP Developmentadvanced 8 min read

BAdI Part 9: Performance and Database Access in BAdIs

Preview · a free account unlocks the full lesson

Key takeaway

Keep BAdI implementations fast: how often methods are called (per item, per field change, per screen round trip), guard conditions, buffering with keyed tables per document, avoiding SELECT in loops and BAPI calls, instance creation modes, and measuring with ST05 and SAT.

In this lessonShow sections

Visual overview

BAdI Part 9: Performance and Database Access in BAdIs — learning sheetFlow: Trace ME21N with 50 items and your BAdI active using ST05 → Identify identical SELECTs and add a keyed buffer → Re-trace and document the improvement. Key ideas: HOW OFTEN IS IT CALLED?; GUARD CONDITIONS; USE WHAT YOU GET; BUFFER BY KEY. Watch out: Buffers in static attributes live for the whole session — key them and refresh them, or you show stale or wrong data.ERPClimb.com / ABAP / LESSON 9/10 / LEARNING SHEETBAdI Part 9: Performance and Database Access in BAdIs1 · HOW IT FLOWS1Trace ME21N with 50 itemsand your BAdI activeusing ST052Identify identicalSELECTs and add a keyedbuffer3Re-trace and document theimprovement2 · KEY IDEAS EXPLAINEDHow Often Is It Called?PROCESS_ITEM in ME_PROCESS_PO_CUST runs for eachitem on every change/check.Pricing and delivery BAdIs run per item and duringcopy, repricing and output.Guard ConditionsExit immediately when the document type, org unitor field is irrelevant: the cheapest code is codethat doesn't run.Use What You GetParameters and objects often contain the data youwant to SELECT (header data, item data, partnerdata). Read them before going to the database.Buffer By KeyHashed table keyed by the lookup key (material,customer).Instance attributes if the BAdI instance is reused(new BAdI instance creation mode"reuse") or a separate buffer class with…3 · REMEMBER · WATCH OUTRememberBAdI methods can be called far more often than you expect — per item,per field change, on every Enter.Guard conditions first, then use data from parameters, then bufferdatabase reads by key.Measure: ST05 (SQL trace) and SAT (runtime analysis) with realisticdocument sizes.!Watch outBuffers in static attributes livefor the whole session — key them andrefresh them, or you show stale orwrong data.4 · IN A REAL PROJECTA PO BAdI validated vendor, material and budget data in PROCESS_ITEM. For a 300-item framework order, ST05showed 9,000 SELECTs, and users waited 40 seconds after every Enter. The team moved vendor checks to CHECK(once per PO), used item data already provided by the item objects, and buffered material data by key. The…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 8 structured the BAdI code; this lesson makes sure that structure doesn't slow the transaction down.

BAdI methods can be called far more often than you'd expect — per item, per field change, on every Enter — so the first rule is to check guard conditions early, then use the data already available in the method's parameters, and only then, as a last resort, buffer any database reads by key.

Measure with ST05 (SQL trace) and SAT (runtime analysis) against realistically sized documents rather than guessing. One trap to watch for: buffers held in static attributes live for the entire session, so they need to be keyed and refreshed properly, or they'll eventually show stale or simply wrong data.

Start by understanding how often your BAdI is actually called. PROCESS_ITEM in ME_PROCESS_PO_CUST, for example, runs for every item on every change or check. Pricing and delivery BAdIs run per item, and again during copy, repricing, and output processing. Mass programs — MASS, uploads, VL10, billing runs — can call the same BAdI thousands of times in a single run. Use SAT, or a simple counter dropped in via the debugger, to find out the real number rather than assuming.

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.