ERPClimb logoERPClimb
Performance Tuning
ABAP Developmentintermediate 9 min read

Performance Part 6: Internal Tables — Standard, Sorted and Hashed

Preview · a free account unlocks the full lesson

Key takeaway

Choose the right internal table type for performance: linear search on standard tables, binary search and sorted tables, hashed tables for key lookups, secondary keys, nested loops with WHERE on sorted tables, parallel cursor technique, and memory aspects.

In this lessonShow sections

Visual overview

Performance Part 6: Internal Tables — Standard, Sorted and Hashed — learning sheetFlow: Run the code example with the inner table as STANDARD and as SORTED; compare with GET RUN TIME → Replace a READ on a standard table in a loop with a hashed lookup → Check with SAT that internal table operations dropped. Key ideas: TABLE TYPES; CHOOSING; NESTED LOOPS; SECONDARY KEYS. Watch out: Nested loops over two large standard tables are the most common ABAP-side (CPU) performance problem after database issues.ERPClimb.com / ABAP / LESSON 6/10 / LEARNING SHEETPerformance Part 6: Internal Tables — Standard, Sorted andHashed1 · HOW IT FLOWS1Run the code example withthe inner table asSTANDARD and as SORTED…2Replace a READ on astandard table in a loopwith a hashed lookup3Check with SAT thatinternal table operationsdropped2 · KEY IDEAS EXPLAINEDTable TypesSTANDARD: index access, fast APPEND; key searchlinear unless sorted + BINARY SEARCH.SORTED: always sorted by key (unique ornon-unique); key and prefix searches binary; LOOPWHERE with key prefix optimised.ChoosingLookup by full unique key (e.g. material masterdata) → HASHED.Range/prefix access or ordered processing,possibly non-unique (e.g. items per order) →SORTED.Nested LoopsLOOP AT headers … LOOP AT items WHERE vbeln =header-vbeln: with items as SORTED by vbeln posnr→ fast; as STANDARD → full scan per header.Parallel cursor (classic technique on sortedstandard tables): READ first matching item withBINARY SEARCH, then LOOP FROM that index and EXIT…Secondary KeysTables can have secondary sorted/hashed keys for asecond access path (7.02+); keep in mindmaintenance cost when the table changes often.3 · REMEMBER · WATCH OUTRememberStandard table + READ TABLE WITH KEY = linear search: cost grows withtable size; inside a loop it becomes quadratic.Sorted tables (or sorted standard + BINARY SEARCH) give logarithmicaccess; hashed tables give constant-time access by the full unique…Nested LOOP … WHERE on a sorted inner table (key prefix) is optimised;on a standard table it scans the whole inner table every time.!Watch outNested loops over two large standardtables are the most common ABAP-side(CPU) performance problem afterdatabase issues.4 · IN A REAL PROJECTA pricing simulation looped over 60,000 items and, for each, looped over a 200,000-line condition table withWHERE on a standard table. The CPU-bound job took 5 hours; STAD showed almost no DB time. Changing thecondition table to a sorted table with the lookup key as prefix reduced the inner loop cost dramatically; the…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Parts 4 and 5 moved data reads out of loops; now the lookups that happen inside those loops need to be fast too, which is where choosing the right internal table type matters.

A standard table combined with READ TABLE WITH KEY performs a linear search, whose cost grows with the size of the table — and when that read sits inside another loop, the overall cost becomes quadratic.

Sorted tables, or standard tables that are explicitly sorted and read with BINARY SEARCH, give logarithmic access instead, while hashed tables give constant-time access, but only when read by their full unique key. A nested LOOP ...

WHERE is optimized automatically when the inner table is sorted by a key that matches the WHERE condition as a prefix; on a plain standard table, the same construct scans the entire inner table on every single pass of the outer loop.

After database issues, nested loops over two large standard tables are the most common source of ABAP-side CPU performance problems.

The three table types behave quite differently. A STANDARD table supports fast index access and fast APPEND, but key searches are linear unless the table is sorted and read with BINARY SEARCH. A SORTED table is always kept sorted by its key, whether unique or non-unique, so both exact-key and key-prefix searches are binary, and a LOOP ...

WHERE that matches a key prefix is optimized. A HASHED table only supports a unique key, but reading with the full key is constant time, and it offers no index access 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

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.