Skip to content

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

Duplicates for Unique Keys

When rows are inserted into internal tables with a unique primary or secondary key, duplicates can occur with regard to one or more of these keys. Depending on whether the insertion operation is taking place as a single record operation or a set operation, the ABAP runtime environment reacts as follows in response to an attempt to insert an entry with duplicate key values:

  • First, it checks whether duplicate key values would occur with regard to the primary key. The system behavior is as follows depending on the operation:
  • When single rows are inserted using the variant

    INSERT wa INTO TABLE itab,

    duplicate entries with regard to the primary key are ignored and sy-subrc is set to 4. This is often used to filter out duplicates when setting up the table.
  • Then the system checks whether duplicate key values would occur with regard to any available unique secondary keys. If so, the system behaves as follows:
  • For the statements INSERT and APPEND, the system triggers an exception in the CX_SY_ITAB_DUPLICATE_KEY class if it is a single record operation.
  • For all other insertion and assignment operations, particularly for all set operations, an ITAB_DUPLICATE_KEY runtime error occurs.

Other versions: 7.31 | 7.40 | 7.54