sapdev logo background
sapdev logo sapdev logo
Comments

SAP ITAB KEY DUPLICATES documentation, setup help and example usage



Return to SAP documentation index


ARTICLE

Duplicate Unique Keys
When rows are inserted into internal tables with a unique primary key or unique secondary key, duplicates can occur with respect to one or more of these keys. Depending on whether the insert takes place as a single record operation or a mass operation, the ABAP runtime environment responds as follows to an attempt to insert an entry with duplicate key values:
  • First, it checks whether duplicate key values would occur with respect 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 with respect to the primary key are ignored and sy-subrc
    is set to 4. This is often used to filter out duplicates when the table is constructed.
  • In all other cases, such as


  • INSERT ... INTO itab INDEX idx
    INSERT LINES OF (mass operation)
    APPEND
    COLLECT
    = , IMPORT
    (mass operations)

    the runtime error ITAB_DUPLICATE_KEY occurs.
  • A check is then made to see whether duplicate key values would occur with respect to any existing unique secondary keys. If this is the case,

  • an exception of the class

  • CX_SY_ITAB_DUPLICATE_KEY is raised for the statements INSERT and APPEND
    , if the operation is a single record operation.
  • For all other insert and assignment operations, particularly for all mass operations, the runtime error ITAB_DUPLICATE_KEY occurs.
    Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




  • ITAB_KEY
    ITAB_KEY_MEMORY




    comments powered by Disqus