ABAP Keyword Documentation → ABAP - Reference → Declarative statemnts → Data Types and Data Objects → Declaring Data Objects → DATA → DATA - TABLE OF → DATA - tabkeys
DATA - key
Other versions: 7.31 | 7.40 | 7.54
Syntax
... [UNIQUE | NON-UNIQUE]
{ {KEY [primary_key [ALIAS key_name] COMPONENTS] comp1 comp2 ...}
| {DEFAULT KEY} } ... .
Effect
Definition of the primary table key of an internal table. The syntax and semantics of the additions
are the same as for the TYPES statement for stand-alone table types, with the difference that the primary key of a
bound table type must always be completely specified:
-
For standard tables,
only the
NON-UNIQUE KEYaddition can be specified. If the specification of uniqueness is missing, this addition is supplemented implicitly. TheUNIQUE KEYaddition cannot be specified. -
For sorted tables, one
of the two additions
UNIQUE KEYorNON-UNIQUE KEYmust be specified. -
For hashed tables, the
UNIQUE KEYaddition must be specified.
If a primary key is not specified for DATA using WITH,
the WITH NON-UNIQUE DEFAULT KEY additions are supplemented for standard tables, whereby the table has a
standard key that can also be empty. Primary keys must be specified explicitly for sorted tables and hashed tables and must not be empty.
If the name of the primary_key
WITH HEADER LINE must no longer be specified, even outside of classes.
Note
Declaring the primary table key as a standard key can be critical for a variety of reasons and you should therefore specify the key fields explicitly instead. Make sure in particular that the declaration of the standard key is not supplemented accidentally because you forgot to specify the key explicitly.