Internal Tables

Internal tables are a way to store variable datasets of a fixed structure in the working memory of ABAP. The data is stored on a row-by-row basis, where each row has the same structure.

Internal tables provide the functionality of dynamic arrays and relieve the programmer of the expenditure of a program-controlled dynamic memory management (see Memory management of deep data objects. Internal tables are preferably used to store and format the content of database tables from within a program. Furthermore, internal tables in connection with structures are the most important means of defining very complex data structures in an ABAP program.

Data Type of an Internal Table

A table type defined in the ABAP Dictionary or using TYPES or DATA is fully specified by:

Like strings, internal tables are dynamic data objects. As far as row type, table category and table key are concerned, they are always fully specified, but with any number of rows, which is limited only by the capacity limits of the actual system installations (see Maximum size of dynamic data objects).

Accessing Internal Tables

When accessing internal tables, you can address either the entire table or table body or individual rows.

To access the table body, you use special statements such as SORT, but also general statements such as MOVE. To access individual rows, you use special statements such as READ_TABLE, LOOP AT or MODIFY. When accessing individual rows, you either use a work area into which the row content can be read or where it can be modified, or you link a row to a field symbol or a data reference variable and use it to access the row directly.

Notes

Selecting the Table Category

Which table category to use depends on which kind of access to individual rows will be applied most frequently for the table.

Internal Tables with Header Lines

Outside of classes and as long as an internal table is not a component of a structure or row of another internal table, you can create an internal table with a so-called header line (HEADER LINE). A header line is a work area whose data type is the row type of the internal table and whose name is the name of the internal table. You should not use this possibility, because then two data objects with the same name exist in the ABAP program. Instead of a header line, you can simply create an explicit work area using the addition LINE OF of the statements TYPES, DATA etc.

The statements for the access to individual rows use the header line as implicit work area if no explicit work area is specified. In all other cases it depends on the statement and operand position whether the table body or the header line is used for processing when you specify a table name. Usually the header line is addressed. To force access to the table body, you can specify square brackets after the name (for example, itab[]). When passing it to table parameters, table body and header line are passed.