IT CanvassTalk to an advisor
SAP ABAP development · LessonBy , SAP Trainer, 10 yrs · Published · SAP S/4HANA 2023 · all levels

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.

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.

Practice challenge

+0 XPStreak ×0
Question 1 of 3
Which statement is true of Internal tables?

Frequently asked questions

What does the term Internal tables refer to in SAP?
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.
What is worth remembering about Internal tables in practice?
Choose the table type for the access pattern: hashed/sorted tables make repeated lookups dramatically faster than linear reads on a standard table.
What is another point to note about Internal tables?
An internal table holds multiple rows of a structured type in memory, think of it as a temporary table your program builds and processes.
What tends to go wrong with Internal tables?
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.
Already working on SAP and stuck on a live ticket?Get an expert SAP developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support