Internal tables
Internal tables are ABAP’s in-memory tables, the central data structure for working with sets of rows (like query results) inside a program. Mastering internal tables is arguably the most important ABAP skill.
Choose the table type for the access pattern: hashed/sorted tables make repeated lookups dramatically faster than linear reads on a standard table.
- An internal table holds multiple rows of a structured type in memory, think of it as a temporary table your program builds and…
- Standard: general purpose, indexed access.
- Sorted: kept in key order, fast binary-search reads.
- Watch out: Linear READ in a loop on a big standard table; use sorted/hashed.
What an internal table is
An internal table holds multiple rows of a structured type in memory, think of it as a temporary table your program builds and processes. You SELECT database rows into an internal table, then loop, read, sort, filter and aggregate in memory, which is fast and central to nearly every report and interface.
Table types
- Standard: general purpose, indexed access.
- Sorted: kept in key order, fast binary-search reads.
- Hashed: keyed, near-constant-time single-row access for large lookups.
Core operations
DATA lt_mara TYPE STANDARD TABLE OF mara.
SELECT * FROM mara INTO TABLE @lt_mara UP TO 100 ROWS.
SORT lt_mara BY matnr.
READ TABLE lt_mara INTO DATA(ls) WITH KEY matnr = 'X' BINARY SEARCH.
DELETE lt_mara WHERE mtart = 'ROH'.
DATA(lv_count) = lines( lt_mara ).Performance choices
Choose the table type for the access pattern: hashed/sorted tables make repeated lookups dramatically faster than linear reads on a standard table. For big lookups inside loops, a hashed table (or sorted with binary search) instead of a repeated linear READ is a major optimisation.
Common pitfalls
- Linear READ in a loop on a big standard table; use sorted/hashed.
- Wrong table type for the access pattern.
- Reading the DB per row instead of into a table once.