‎2020 Jul 28 2:13 PM
Hi Experts,
We have encountered a dump in production where insert statement fails to update a custom database table.The internal table that contains the entries that updates the database table is IT_LABELS. As can be seen in below screenshot, IT_LABELS contains two entries:

Scrolling down*
My question is, are these two entries the contents of table IT_LABELS?

If so, as both entries are identical, is this what's causing the dump. I have checked this entry in the database table, however it still does not exist. Does insert statement fail when the internal table source contains identical entries (same primary keys) even though that entry does not exist in the database yet?
‎2020 Jul 28 2:19 PM
Hello kdarunday
Yes, these are the entries in the IT_LABELS table.
Yes, the INSERT will fail if the primary key or a unique index is violated.
If you try to insert the two entries at the same time, then the INSERT statement will fail regardless if the first record with the same key is already in the DB table or not. Because for the INSERT, the first record is already in the table when trying to insert the second one.
When the statement fails no database change is committed, hence you cannot see any of the records in the DB table.
Kind regards,‎2020 Jul 28 2:19 PM
Hello kdarunday
Yes, these are the entries in the IT_LABELS table.
Yes, the INSERT will fail if the primary key or a unique index is violated.
If you try to insert the two entries at the same time, then the INSERT statement will fail regardless if the first record with the same key is already in the DB table or not. Because for the INSERT, the first record is already in the table when trying to insert the second one.
When the statement fails no database change is committed, hence you cannot see any of the records in the DB table.
Kind regards,‎2020 Jul 28 2:25 PM
Hi Mateusz,
Does this mean the first entry is rolled back? Or is it only at runtime that INSERT considers the first record as already in the table?
Regards,
Katherine
‎2020 Jul 28 2:27 PM
That's exactly what it means, Katherine.
‎2020 Jul 28 2:36 PM
‎2020 Jul 28 2:24 PM
When you insert data from a not checked area (file, human, ...) you could add the parameters ACCEPTING DUPLICATES to the INSERT statement
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abapinsert_source.htm
‎2020 Jul 28 2:33 PM
Hi Frederic,
Thanks for the suggestion, I'm also thinking to delete adjacent duplicates from the internal table. But with accepting duplicates, will both entries be added? or only one but will not encounter a dump upon insert?
Regards,
Kath
‎2020 Jul 28 3:07 PM
kdarunday, with "ACCEPTING DUPLICATE KEYS", in your case if the duplicates are only in your internal table, only the first unique records will be inserted, all duplicate entries will be discarded. If the duplicates already exist in the database and your internal table, all duplicates in the internal table will be discarded.
If you dont use "ACCEPTING DUPLICATE KEYS", you can catch the error with CX_SY_OPEN_SQL_DB, and the insert will be stopped, once a duplicate key is encountered and only the first unique records will be in the database.
If you neither use "ACCEPTING DUPLICATE KEYS" nor catch the error CX_SY_OPEN_SQL_DB, you will end up with the dump that you have encountered and no records will be inserted at all.