ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Internal Tables → Internal Tables - Overview
Access to Internal Tables
When internal tables are read, either the entire table or table body can be accessed, or individual rows.
- The full table is read using special statements such as SORT, but can also be accessed using general statements where internal tables can be specified at operand positions. Examples are assignments, parameter passing, target or source areas in ABAP SQL and many other statements that return or expect tabular data.
- Individual rows are accessed using
- special statements such as
READ TABLE
, LOOP AT,MODIFY
.
- table expressions
itab[ ... ]
.
- Mesh path expressions
mesh_path
The table category and the table keys are significant when internal tables are edited:
- The primary table index (which always exists) can be used to access index tables (standard tables and sorted tables).
- Primary table keys can be used for optimized access to sorted tables and hashed tables.
- A secondary table index can be used to access any tables with a sorted secondary table index.
- The secondary table key can be used for optimized access to any tables with a secondary sorted key or hash key. Notes
Other versions: 7.31 | 7.40 | 7.54
Notes
- Internal tables must be specified at operand positions for internal tables, both when the statement
is executed and if known statically. Generic formal parameters and field symbols can only be specified
if they are typed with at least the generic type
any table. Only index tables can be specified at operand positions that include index access,
and generic formal parameters and field symbols must be typed with at least the generic type
index table
.
- If the row type of internal tables contains
object reference variables as the components
comp
, the attributes attr of the object to which the reference points can be used as key values for reading, sorting, and modifying table rows. This is always possible for statements that address individual components of the table.
- The content of the primary table key cannot be changed for any writes to individual rows of sorted tables and hashed tables. If writes are performed in writing positions across the entire table row in these tables (for example, as a target field of assignments or as actual parameters for output parameters), an exception is always raised. It is not possible to access entire table rows using field symbols, data references or table expressions.
Example
In the following example, data is written to an internal table with ABAP SQL, sorting takes place, and
reads are demonstrated with the statement READ TABLE
and a
table expression.
DATA scarr_tab
TYPE STANDARD TABLE OF scarr
WITH NON-UNIQUE KEY carrid.
SELECT *
FROM scarr
INTO TABLE @scarr_tab.
SORT scarr_tab BY carrid ASCENDING.
READ TABLE scarr_tab WITH TABLE KEY carrid = 'LH'
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
DATA(idx) = sy-tabix.
TRY.
cl_demo_output=>display( scarr_tab[ idx + 1 ]-carrid ).
CATCH cx_sy_itab_line_not_found.
...
ENDTRY.
ENDIF.