2023 Mar 31 9:55 AM
Hello, I have the following problem. I am trying to update update several Z DB tables with the following code
INSERT zek_xk_lines FROM TABLE db_xk_lines ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
INSERT zek_xklinkae FROM TABLE db_xk_line_kae ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
IF wa_xk_line-xk_traffic_ticket IS NOT INITIAL.
db_xk_line_traffic = CORRESPONDING #( wa_xk_line-xk_traffic_ticket ).
INSERT zek_xklinedt FROM TABLE db_xk_line_traffic ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
r_result = |Failed to insert in DB TRAFFIC TICKETS (zek_xklinedt)|.
ENDIF.
ENDIF.
IF wa_xk_line-xk_rent IS NOT INITIAL.
db_xk_line_rents = CORRESPONDING #( wa_xk_line-xk_rent ).
INSERT zek_xk_rent FROM TABLE db_xk_line_rents ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
r_result = |Failed to insert in DB RENTS (zek_xk_rents)|.
ENDIF.
ENDIF.
IF wa_xk_line-xk_doses IS NOT INITIAL.
db_xk_line_doses = CORRESPONDING #( wa_xk_line-xk_doses ).
INSERT zdae_migt_doses FROM TABLE db_xk_line_doses ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
r_result = |Failed to insert in DB DOSES (zdae_migt_doses)|.
ENDIF.
ENDIF.
IF r_result = ''.
COMMIT WORK AND WAIT.
ENDIF.
ELSE.
ROLLBACK WORK.
r_result = |Failed to insert in DB KAE|.
ENDIF.
ELSE.
ROLLBACK WORK.
r_result = |Failed to insert in DB LINE|.
ENDIF.
I noticed that when the INSERT of the 2nd table fails subrc=4 because of the duplicate keys, the ROLLBACK WORK is not working and Commits all the inserted records even for the 2nd one.
Does anyone knows why and what to do?
Thanks
Elias
2023 Mar 31 10:47 AM
Hello,
ROLLBACK WORK does not revert changes in the database that were already committed - is this possibly your assumption? Once executed, a COMMIT WORK effects all updates in the database in the LUW done so far. BTW, if you do not use asynchronous updates you should not use the addition AND WAIT.
In the above given source code I would assume that a final COMMIT WORK resp. ROLLBACK WORK at the end would be more fitting to the needs.
Kind regards
Jan
2023 Mar 31 10:47 AM
Hello,
ROLLBACK WORK does not revert changes in the database that were already committed - is this possibly your assumption? Once executed, a COMMIT WORK effects all updates in the database in the LUW done so far. BTW, if you do not use asynchronous updates you should not use the addition AND WAIT.
In the above given source code I would assume that a final COMMIT WORK resp. ROLLBACK WORK at the end would be more fitting to the needs.
Kind regards
Jan
2023 Mar 31 11:55 AM