Skip to content

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

Primary Table Keys

Each internal table has a primary table key that enables access to individual rows in the table by means of a key specification.

  • The standard key, which can be declared both explicitly and implicitly, has a special part to play here.
  • The primary table key of a standard table can also be empty, meaning that it does not contain any key fields.
  • In the case of key accesses for internal tables, the primary key is always used implicitly processing statements as long as no secondary key is specified. In table expressions, the primary key must also always be specified explicitly.
  • The primary key has the predefined name primary_key, with which it can also be addressed explicitly in processing statements. In table expressions, primary_key or an alias name must be specified, if the primary key is to be used explicitly.
  • Access to an internal table using the primary table key is determined by the table category and not the table key. For sorted tables and hashed tables, key access is always optimized using the primary table key. Primary key access to standard tables, however, uses a linear search.
  • The key fields of the primary table key of sorted tables and hashed tables are always read-only.
  • In the case of sorted tables and hashed tables, separate key administration exists for the primary table key, which enables optimized access but also affects the memory requirement of the internal table. There is no separate key administration for the primary table key of standard tables.

Other versions: 7.31 | 7.40 | 7.54


  • Since sorted tables and hashed tables have real key administration for the primary key, unlike standard tables, these tables are also grouped under the term key tables.

  • To achieve optimized key access to standard tables, secondary keys can be used.


Declaration of a hashed table with a unique primary key. The table is filled with data from a database table, read using a table expression with values specified for the primary key.

DATA carrid TYPE spfli-carrid VALUE 'LH'. 
cl_demo_input=>add_field( CHANGING field = carrid ). 
DATA connid TYPE spfli-connid VALUE '0400'. 
cl_demo_input=>request( CHANGING field = connid ). 

DATA spfli_tab 
       WITH UNIQUE KEY primary_key COMPONENTS carrid connid. 

       FROM spfli 
       INTO TABLE @spfli_tab. 

  VALUE #( spfli_tab[ KEY primary_key 
                     carrid = carrid 
                      connid = connid ] OPTIONAL ) ).


Standard Key

Empty Table Key