Internal tables
Quick answer
Choose the table type for the access pattern: hashed/sorted tables make repeated lookups dramatically faster than linear reads on a standard table.
Key takeaways
- 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.
Want to learn this properly?
Our live, instructor-led SAP Training covers this hands-on, with real projects and a certification path.
Check your understanding
Which statement is true of Internal tables?
- A. The software prerequisites for an SAP installation, the operating system, database, kernel, and supporting…
- B. ECC (SAP ERP Central Component) release notes cover the previous-generation ERP, delivered largely through…
- C. You SELECT database rows into an internal table, then loop, read, sort, filter and aggregate in memory, which…
Show answer
C. You SELECT database rows into an internal table, then loop, read, sort, filter and aggregate in memory, which…
Covered in the “What an internal table is” section of this lesson.
Which of these also applies to Internal tables?
- A. Confusing storage location with WM bins, different levels of detail.
- B. For big lookups inside loops, a hashed table (or sorted with binary search) instead of a repeated linear READ…
- C. Following steps without understanding the concept.
Show answer
B. For big lookups inside loops, a hashed table (or sorted with binary search) instead of a repeated linear READ…
Covered in the “Performance choices” section of this lesson.
Which part of the Learn SAP curriculum covers Internal tables?
- A. SAP ABAP development
- B. SAP architecture
- C. SAP modules hub
Show answer
A. SAP ABAP development
This lesson sits in the SAP ABAP development section of the Learn SAP course.