Performance Part 6: Internal Tables — Standard, Sorted and Hashed
Preview · a free account unlocks the full lesson
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 sectionsHide sections
Visual overview
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.
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
Interview questions on this topic
Related SAP topics
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.