Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

DBSQL_DUPLICATE_KEY_ERROR

former_member704196
Participant
0 Kudos
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 ?

1 ACCEPTED SOLUTION

kilian_kilger
Active Participant

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.

5 REPLIES 5

kilian_kilger
Active Participant

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.

former_member186660
Participant

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

0 Kudos

Thanks.. Issue resolved

former_member704196
Participant
0 Kudos

Thanks.. Issue resolved

getnikhilk
Employee
Employee
0 Kudos

Hello @Dipin Munjal

How did you solve this issue ? I am also getting similar dump while maintaining the entries from Custom SM30 view.

Regards,

Nikhil Kulkarni