Internal Tables Part 2: Choosing the Right Table Type
Preview · a free account unlocks the full lesson
Pick STANDARD, SORTED or HASHED tables by access pattern: index access, key reads, range processing, uniqueness and data volume — with a decision table and measured examples.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 1 introduced the three kinds of internal table. Now comes the actual decision of which to use — one of the most important performance decisions in classic ABAP.
Each table kind is accessed differently under the hood. On a STANDARD table, index access is fast, but READ … WITH KEY performs a linear search, scanning row by row, unless the table has been sorted and BINARY SEARCH is used instead. STANDARD: sequential processing, index access, small tables, or SORT + BINARY SEARCH.
On a SORTED table, key access is a binary search and therefore logarithmic in cost, LOOP … WHERE on the leading key fields is optimized automatically, and the table maintains its order on insert — which can get expensive if many rows are inserted in random order.
SORTED: frequent key reads, partial-key access and LOOP … WHERE on the leading key fields. On a HASHED table, key access goes through a hash and runs in nearly constant time regardless of table size, but only against the full unique key — there's no index and no ordering at all, so SORT is possible but rarely useful. HASHED: frequent reads by the full unique key on large tables (lookup tables).
A rough decision table helps: to process every row once, in order, use STANDARD. To build a table with APPEND and then just output it, STANDARD again. For many reads by the full unique key — a material master lookup repeated inside a loop, say — HASHED is the clear winner.
For many reads by a partial key or a range — all flights of a given connection — SORTED with a non-unique key fits. And where uniqueness genuinely needs to be enforced, SORTED or HASHED WITH UNIQUE KEY does that: a duplicate insert simply fails, or APPENDing to a sorted table out of order causes a dump.
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.