ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Internal Tables → Internal Tables - Overview
Data Type of an Internal Table
A table type defined in
ABAP Dictionary or using TYPES
or DATA
is specified fully using:
- Row Type
The row type of an internal table can be any data type. If the row type is structured, the individual components of a row are also known as the columns of the internal table.
- Table Category
The table category defines how an internal table is administered and how its individual rows can be accessed. There are three table categories:
- Standard tables are administered internally using a primary table index. If required, this primary table index can be implemented using a logical index. The table can be accessed using either a table index or a table key. The primary key of a standard table is always non-unique. The response time for accessing the table using the primary key is proportional to the number of entries in the table. Secondary table keys can be defined to make key access to standard tables more efficient.
- Sorted tables are also administered internally using a
primary table index. They are always sorted according to the
primary table key. Sorting is in ascending order by size according to the
comparison rules for the data types of the key fields
and returns the same result as the
SORT
statement without additions. The table can be accessed using either a table index or a table key. The primary key of a sorted table can be either unique or non-unique. The response time for accessing the table using the primary key is logarithmically proportional to the number of table entries, since a binary search is used.
- Hashed tables are administered internally using a hash algorithm. Hashed tables can be accessed using a table key or a secondary table index. The primary key of hashed tables is always unique. The response time for primary key access is constant and independent of the number of entries in the table.
- Table Key
A table key is used to identify rows in a table (see below). There are two possible key types for internal tables, primary keys and optional secondary keys. Every internal table has a primary key, which is either the standard key or a self-defined key. Depending on the table category, the primary key is unique or non-unique. A secondary key is either a sorted key, which can be unique or non-unique, or a unique hash key. If keys are unique, a row with a specific content in the key fields can exist only once in the internal table. A table key can consist of components of the row type or of the entire row ( pseudo component table_line), if they are not internal tables or do not contain internal tables. When a table key is defined, the order of the key fields is significant.
Unlike all other self-defined data types, a table type defined in ABAP Dictionary or using
TYPES
does not have to be specified in full. Either only the keys or the row type and the keys can be omitted from the definition. This makes the type generic and it can be used only for
typings of field symbols and formal parameters. The predefined
generic ABAP types ANY
TABLE and INDEX TABLE
can be used for these purposes. The first type includes all table categories, the second type includes standard tables and sorted tables, known as
index tables.
Like strings, internal tables are dynamic data objects. Their row type, table category, and table key are always specified in full, but the number of rows is variable and restricted only by the capacity of the system installation (see Maximum Size of Dynamic Data Objects).
Other versions: 7.31 | 7.40 | 7.54
Note
Table keys are evaluated when typings are checked. Only actual parameters that have the same type can be assigned to a formal parameter or a field symbol whose table type has a non-generic primary key or one or more secondary keys.
Example
Definition of a table type spfli_tab
with the structured row type SPFLI
from the ABAP Dictionary, the table category hash table, a unique primary key, and exactly one non-unique sorted secondary key cities
.
TYPES spfli_tab
TYPE HASHED TABLE OF spfli
WITH UNIQUE KEY carrid connid
WITH NON-UNIQUE SORTED KEY cities COMPONENTS cityfrom cityto
WITHOUT FURTHER SECONDARY KEYS.