SAP ITAB STANDARD KEY



Get Example source ABAP code based on a different SAP table
  



ABAP_ITAB - Standard Key
The standard key is a special primary table key of an internal table.
ITOC

Key Fields of the Standard Key
The key fields of the standard key are defined as follows:
In tables with a structured line type, the standard key is formed from all components with character-like and byte-like data types, while resolving any substructures into elementary components. If the line type does not contain any components like these, the standard key is empty for standard tables, meaning it does not contain any key fields.
The standard key for tables with non-structured line types is the entire table line, if the line type itself is not table-like. If the line type is table-like, the standard key is empty for standard tables.
Empty standard keys are not possible for sorted tables and hashed tables, and an error occurs if an attempt is made to create a key like this.



Latest notes:

In tables with non-structured line types, the standard key can also have a numeric type or reference type. This does not apply to the key fields if the line types are structured.
The static boxes of a structured line type are handled like regular components with respect to the standard key.
NON_V5_HINTS
ABAP_HINT_END

Declaration of the Standard Key
The standard key can be declared as follows:
Explicitly, using the additions UNIQUE$|NON-UNIQUE KEY of the statements TYPES, DATA and so on, where the addition DEFAULT KEY is specified instead of the list of components.
Implicitly, if no explicit primary key specification is made in the declaration of a standard table with the statement DATA.
Implicitly, if a standard table type with a generic primary table key is specified behind TYPE in the statement DATA.

Notes on Use
Using standard keys is critical for the following reasons:
It is not usually enough to identify the key fields using their data type and not their semantic properties. This often leads to unexpected behavior in sorts and other accesses.
The fact that standard keys in standard tables can be empty often causes unexpected behavior as well. For example, using keys like this for sorting has no effect, whereas a corresponding read finds the first line.
The standard key often contains too many key fields, which can produce performance problems in key accesses.
If using the standard key and a structured line type, all character-like and byte-like fields of sorted tables and hashed tables are read-only, which can cause unexpected runtime errors.
For this reason, the primary key should be declared by listing the components explicitly, if possible. In particular, the primary key must not be set as the standard key by mistake, the key must not be forgotten in declarations of standard tables using DATA, and the generic table type must not be used unknowingly.

ABAP_EXAMPLE_VX5
Internal table with standard key. In the structure SCARR, all five components meet the requirements for the standard key and are used as key fields. In a key access using a table expression, the syntax check requires that each key field of the primary table key is specified.
ABEXA 01064
ABAP_EXAMPLE_END