ERPClimb logoERPClimb
Internal Tables
ABAP Developmentintermediate 9 min read

Internal Tables Part 2: Choosing the Right Table Type

Preview · a free account unlocks the full lesson

Key takeaway

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 sections

Visual overview

Internal Tables Part 2: Choosing the Right Table Type — learning sheetFlow: Run the code example: it measures reading 20,000 flights with a standard table vs a hashed table (GET RUN TIME) → Compare the runtimes → Change the access to a partial key and use a sorted table. Key ideas: HOW EACH KIND IS ACCESSED; DECISION TABLE; A TYPICAL CLASSIC PATTERN; KEYS. Watch out: Table kind matters most for large tables and reads inside loops.ERPClimb.com / ABAP / LESSON 2/10 / LEARNING SHEETInternal Tables Part 2: Choosing the Right Table Type1 · HOW IT FLOWS1Run the code exampleit measures reading 20,000 flightswith a standard table vs a hashed…2Compare the runtimes3Change the access to apartial key and use asorted table2 · KEY IDEAS EXPLAINEDHow Each Kind Is AccessedSTANDARD: index access fast; READ … WITH KEY =linear search (reads row by row) unless you SORTand use BINARY SEARCH.SORTED: key access is a binary search(logarithmic); LOOP … WHERE on leading key fieldsis optimized; inserting keeps order (costly for…Decision TableProcess every row once, in order → STANDARD.Build a table by APPEND and output it → STANDARD.A Typical Classic PatternSTANDARD + READ WITH KEY → up to 5 billioncomparisons (minutes).HASHED + READ WITH TABLE KEY → 100,000 hashlookups (milliseconds).KeysDefault key of standard tables (no explicit key) =all character-like fields — often wrong; definekeys explicitly or use WITH EMPTY KEY for pure…Sorted/hashed tables need a key definition.3 · REMEMBER · WATCH OUTRememberSTANDARD: sequential processing, index access, small tables, or SORT +BINARY SEARCH.SORTED: frequent key reads, partial-key access and LOOP … WHERE on theleading key fields.HASHED: frequent reads by the full unique key on large tables (lookuptables).!Watch outTable kind matters most for largetables and reads inside loops.4 · IN A REAL PROJECTA billing report looped over 200,000 invoice items and read the customer master from a standard internal tablewith READ … WITH KEY for each item. Runtime grew from minutes to over an hour as the customer base grew.Changing the customer table to a HASHED table with a unique key and using READ … WITH TABLE KEY reduced the…Original ERPClimb learning sheet • Verify against your SAP release and edition

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.

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.