Skip to Content

DBSQL_DUPLICATE_KEY_ERROR

Category           ABAP Programming Error Runtime Errors     DBSQL_DUPLICATE_KEY_ERROR Except.            CX_SY_OPEN_SQL_DB ABAP Program       SAPLZCLM_SLUPDATE

Application Component  Not assigned

Error Analysis :

An exception has occurred which is explained in more detail below. The exception is assigned to class 'CX_SY_OPEN_SQL_DB' and was not caught in procedure"TABLE_DB_UPD" "(FORM)", nor was it propagated by a RAISING clause. Since the caller of the procedure could not have anticipated this exception, the current program was terminated.

The reason for the exception is: When an Open SQL array insert is performed, trying to insert a record into the database table "ZCLM_SLCONTROL" causes the function to terminate if a record with the same key already exists. (When an Open SQL individual record insert is performed, this situation does not cause the function to terminate. SY-SUBRC is set to 4 instead.)

**Start - Handling exceptions for Unique Indexes.                                        

*    TRY.                                                                               

|>>>>>|        INSERT (x_header-maintview) FROM TABLE <mod_elem_tab>.                          

*      CATCH cx_sy_open_sql_db.                                                           

*        MESSAGE i862(sv).                                                                 

*    ENDTRY.                                                                              

** End - Handling.

Could you please suggest how to prevent this issue ?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 20, 2015 at 01:09 PM

    Hi Dipin,

    for this scenario, there is the addition ACCEPTING DUPLICATE KEYS. So you can write:

    INSERT ... FROM TABLE <mod_elem_tab> ACCEPTING DUPLICATE KEYS.


    Then no exception is thrown but the sy-subrc is set to 4. All lines which could be inserted, will be inserted nevertheless.

    Best regards,

    Kilian.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 20, 2015 at 01:28 PM

    Good day Dipin,

    You can use MODIFY table. statement, because if the records exist on the db it will update the current record it won't dump. if the record does not exist it will create a new records.

    syntax:

    MODIFY db_tab  FROM  TABLE Internal table.

    MODIFY db_tab FROM workarea.

    Thanks,

    Regards,

    Tumelo Modise

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 23, 2015 at 11:03 AM

    Thanks.. Issue resolved 😊

    Add comment
    10|10000 characters needed characters exceeded