ERPClimb logoERPClimb
Performance Tuning
ABAP Developmentadvanced 7 min read

Performance Part 10: Indexes, Selectivity and WHERE Conditions

Preview · a free account unlocks the full lesson

Key takeaway

Understand how indexes serve WHERE conditions: primary key and secondary indexes (SE11), field order and leading fields, selectivity, conditions that prevent index use (NOT, < , leading wildcards, functions), client field, checking the execution plan in ST05, HANA specifics, and when (not) to create a new index.

In this lessonShow sections

Visual overview

Performance Part 10: Indexes, Selectivity and WHERE Conditions — learning sheetFlow: Look at the indexes of VBAK in SE11 → Trace a SELECT by ERDAT and one by KUNNR in ST05 and compare the execution plans → Rewrite a query to use an existing index table or a more selective leading field. Key ideas: PRIMARY KEY AND SECONDARY INDEXES; LEADING FIELDS; CONDITIONS THAT HURT; ALTERNATIVE ACCESS PATHS. Watch out: New secondary indexes cost insert/update performance and storage; on HANA, column store scans are often fast enough — create indexes only after measurement and with Basis/DBA alignment.ERPClimb.com / ABAP / LESSON 10/10 / LEARNING SHEETPerformance Part 10: Indexes, Selectivity and WHEREConditions1 · HOW IT FLOWS1Look at the indexes ofVBAK in SE112Trace a SELECT by ERDATand one by KUNNR in ST05and compare the execution…3Rewrite a query to use anexisting index table or amore selective leading…2 · KEY IDEAS EXPLAINEDPrimary Key And Secondary IndexesPrimary index: key fields in table order (e.g.VBAP: MANDT, VBELN, POSNR).Secondary indexes in SE11 (Indexes button): e.g.BSEG, VBAK~A (ERDAT) depending on release; checkwhat exists before designing WHERE.Leading FieldsIndex on (MANDT, KUNNR, ERDAT): WHERE kunnr = …AND erdat IN … → good; WHERE erdat IN … only →cannot use leading KUNNR efficiently.Open SQL adds MANDT automatically (clienthandling).Conditions That HurtNOT, <>, NOT IN on indexed fields.LIKE '%abc' (leading wildcard).Alternative Access PathsUse existing index tables instead of the bigtable: e.g. VBAK by customer via VAKPA, FI openitems via BSID/BSAD (ECC) or suitable CDS views in…Document flow via VBFA with preceding documentkey.3 · REMEMBER · WATCH OUTRememberAn index helps only if the WHERE condition specifies its leadingfields (in order: MANDT, then the first key fields) with selective…Selectivity matters: a condition that matches 1% of rows benefits froman index; a condition matching 50% usually doesn't.Use ST05 "Explain" to see which index the database actuallyuses — don't guess.!Watch outNew secondary indexes costinsert/update performance andstorage; on HANA, column store scansare often fast enough — createindexes only after measurement andwith Basis/DBA alignment.4 · IN A REAL PROJECTA customer service transaction searched orders by purchase order number (BSTNK) with LIKE '%…'. On a large ECCsystem each search took 40 seconds with a full table scan. The team changed the search to require thebeginning of the PO number (no leading wildcard), used an existing secondary index on BSTNK after checking…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Parts 1 through 9 of this series reduced the number of database calls and the volume of data moved; the last piece is making sure each remaining SELECT finds its rows efficiently, which comes down to indexes, selectivity, and how a WHERE condition is written.

Every table has a primary index built from its key fields in table order — for VBAP, that's MANDT, VBELN, POSNR — and may also have secondary indexes, visible in SE11 via the Indexes button (for example, an index on BSEG, or VBAK~A on ERDAT, depending on release); check what already exists before designing a WHERE clause.

An index only helps if the WHERE condition specifies its leading fields, in order, with selective values. For an index on (MANDT, KUNNR, ERDAT), a condition like WHERE kunnr = … AND erdat IN … uses the index well, but WHERE erdat IN … alone cannot use the leading KUNNR field efficiently, since it skips over it. Open SQL adds MANDT automatically as part of client handling, so you never need to write it yourself.

Selectivity itself matters a great deal: a condition that matches around 1% of a table's rows benefits strongly from an index, while one matching 50% of the rows usually doesn't, because scanning everything ends up being just as fast. Certain conditions actively hurt index usage: NOT, <>, and NOT IN on indexed fields; LIKE '%abc' with a leading wildcard; very broad ranges or IN lists with many values; and selecting through non-key text fields, such as names, with no index behind them at all.

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.