‎2019 Jun 11 3:17 PM
So, we've got code like this:
DATA my_data type hashed table of ztable with unique key keyfield.
...
DELETE FROM ztable. "#EC CI_NOWHERE
INSERT ztable FROM TABLE my_data.
And at the insert, we're getting the dump SAPSQL_ARRAY_INSERT_DUPREC.
Database is Oracle. ztable contains ~200 records before the delete, my_data is of a similar size.
‎2019 Jun 21 9:12 AM
The reason for the dump is that the table was buffered, and it wasn't synced across application servers.
Thanks all for your thoughts.
‎2019 Jun 11 3:54 PM
‎2019 Jun 11 4:32 PM
‎2019 Jun 12 8:04 AM
raymond.giuseppi corrected, thank you.
No, there are no duplicates in my internal table. There can't be - it's hashed. The key of the internal table is identical to the key of the db table.
No database triggers.
‎2019 Jun 12 8:40 AM
‎2019 Jun 12 9:53 AM
I think you need a commit work after the delete because, otherwise, the command is still between your report and the database.
If you follow in debug the code, stopping 1-2 seconds after the delete, you still have the error?
‎2019 Jun 12 10:31 AM
‎2019 Jun 12 1:32 PM
Why should you need a commit within the same database session? If it were true, then the following code would be useless:
DELETE FROM ztable. "#EC CI_NOWHERE
IF sy-subrc IS INITIAL.
INSERT ztable FROM TABLE my_data ACCEPTING DUPLICATE ROWS.
IF sy-subrc IS INITIAL.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
ELSE.
ROLLBACK WORK.
ENDIF.
If the insert failed, we'd be left with an empty table, which is not what we want.
‎2019 Jun 12 10:34 AM
I'm beginning to think it's a timing issue. But we should be able to stack SQL - otherwise the rollback mechanism is pointless - we'd be unable to do this:
DELETE FROM ztable. "#EC CI_NOWHERE
IF sy-subrc IS INITIAL.
INSERT ztable FROM TABLE my_data ACCEPTING DUPLICATE ROWS.
IF sy-subrc IS INITIAL.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
ELSE.
ROLLBACK WORK.
ENDIF.Maybe I should put the db updates into an update FM.
‎2019 Jun 12 2:40 PM
The internal table maybe of type hash with a unique key but it could create a duplicate if the DB table key is not equivalent.
‎2019 Jun 12 2:53 PM
‎2019 Jun 12 3:10 PM
If you really want to always prevent any exception, you may be required to read current data in a old_records_itab and match it with new records to identify records to create, update, delete or ignore, then execute the 3 statements. Many update FM expect such internal table as parameters.
Meanwhile, did you check values of sy-subrc and sy-dbcnt after each abap sql statement?
‎2019 Jun 21 9:12 AM
The reason for the dump is that the table was buffered, and it wasn't synced across application servers.
Thanks all for your thoughts.