Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables 

Internal Tables - keyname

The name of the table key can be specified in a range of statements and in table expressions for the editing of internal tables. The table key name can used to access a table row or to control processing. The following syntax applies to the name keyname:

Other versions: 7.31 | 7.40 | 7.54

Syntax


... key_name | (name)  ...

Effect

The name of a table key can either be specified directly, as key_name, or dynamically, as the contents of a parenthesized character-like data object name (not case-sensitive). If the name is specified directly, it must be known statically that the internal table has this key. With generic data types, the name can only be specified dynamically. If the name is specified dynamically and is incorrect, this raises a non-handleable exception.

The following can be specified:

  • the table key used in a LOOP-loop using its predefined name loop_key. In this case, the statement must be executed within the loop.


Notes

  • Normally secondary table keys are specified. Only if searches are to be performed explicitly in a table expression using the primary table key does the key need be specified using its predefined name primary_key or an alias name.

  • When specifying the primary table key using primary_key, it is important to note that it may be empty for standard tables. This can produce unexpected behavior in statements where the key is used to specify the rows to be processed.

Example

Dynamic specification of the key according to which the LOOP loop is executed. The loop can be executed with the entries skey and primary_key (not case sensitive). Any other entries produce a runtime error.

DATA(key) = `skey`. 
cl_demo_input=>request( CHANGING field = key ). 

DATA itab TYPE TABLE OF i 
          WITH NON-UNIQUE KEY primary_key COMPONENTS table_line 
          WITH NON-UNIQUE SORTED KEY skey COMPONENTS table_line. 

itab = VALUE #( ( 3 ) ( 2 ) ( 1 ) ). 

LOOP AT itab INTO DATA(wa) USING KEY (key). 
  cl_demo_output=>write( wa ). 
ENDLOOP. 
cl_demo_output=>display( ).