Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarations →  Declaration Statements →  Data Types and Data Objects →  Declaring Data Objects →  DATA →  DATA - TABLE OF →  DATA - tabkeys 

DATA - secondary_key

Short Reference

Other versions: 7.31 | 7.40 | 7.54


    KEY key_name COMPONENTS comp1 comp2 ...


Defines a secondary table key of an internal table. The syntax and semantics of the additions are the same as those for the TYPES statement for standalone table types.

Programming Guideline

Use secondary keys in a way that benefits the table.


  • When internal tables are accessed using the statements READ TABLE itab, LOOP AT itab, MODIFY itab and DELETE itab or using table expressions and in mesh types and mesh paths, a secondary key can be used to specify the rows to be processed or the processing order. To do this, the additions WITH [TABLE] KEY ... COMPONENTS or USING KEY must be specified in the statements and KEY in table expressions. A secondary key is never used implicitly.
  • The INSERT itab statement determines the insert position using the primary key and primary index only. A secondary key can be specified only for the source table from which multiple rows are copied. The latter also applies to the APPEND statement.
  • If a secondary key is defined, the addition WITH HEADER LINE can no longer be specified, even outside classes.
  • If different table keys for an internal table contain the same components, the syntax check issues a warning (which can be hidden using a pragma). In the case of references to a non-generic table type defined using TYPES, a specified pragma is also applied to the DATA statement. In the case of references to a generic table type for which no primary table key is defined, the specified pragma is not applied to the DATA statement, since this statement uses a complete table type implicitly and the pragma must also be specified in the case of DATA.
  • For more information, see TYPES.


The DEMO_SECONDARY_KEYS program demonstrates the declaration and use of a secondary table key and the resulting performance gains.