ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Internal Tables - Overview →  Table Keys → 

Secondary Table Keys

From Release 7.0, EhP2, hash keys and sorted keys can be declared as secondary table keys. For each sorted key, an additional secondary table index is created.

Access to an internal table using a secondary key is always optimized. This allows additional optimized keys to be introduced for sorted and hashed tables as well as optimized key accesses for standard tables.

For data types declared in ABAP programs, a secondary table key is declared using additions UNIQUE|NON-UNIQUE KEY key_name COMPONENTS of statements TYPES, DATA and so on. For table types created in the ABAP Dictionary, the tool provides the corresponding functions.
During key accesses to internal tables, addition WITH [TABLE] KEY key_name can be used to specify which secondary table key to use. During index accesses, you can use USING KEY keyname to specify which secondary key's table index to use. Secondary keys are not selected automatically. If no secondary key is specified during a processing statement, the primary key or primary table index is always used. Statements where secondary keys can be specified are:
If the system field sy-tabix is set by this type of access, and a sorted secondary key is used, the row number refers to the associated secondary table index. In statements that these additions has not been introduced for, like SORT, COLLECT, or PROVIDE, secondary keys are not explicitly supported.

The key fields of a secondary table key are only write-protected if the secondary table key is in use in a LOOP loop or in a MODIFY statement. Otherwise, the secondary key fields are not write-protected.

Notes

Example

Program DEMO_SECONDARY_KEYS demonstrates the specification of a secondary table key and the resulting performance gain.

Other Topics



Continue
Updating Secondary Keys
Using Secondary Keys
Restrictions for Secondary Keys