Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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 ?

Tags:
replied

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.

1 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question