2018 Jul 16 3:41 AM
Hello Community,
is there a possibility to prevent two DB update inconsistent?
I'm working on a program that want to update two add-on tables at the same time, but sometimes only header table (zheader) commit successfully, item table (zitem) not been update but without any exception.
Is any issue for below code? or I need to use in "update task update" for below update?
MODIFY zheader FROM TABLE it_zheader.
IF sy-subrc = 0.
l_flag = 'X'.
ELSE.
l_flag = ''.
ENDIF.
MODIFY zitem FROM TABLE it_zitem.
IF sy-subrc = 0 AND l_flag = 'X'.
l_flag = 'X'.
ELSE.
l_flag = ''.
ENDIF.
IF l_flag = 'X'.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
MESSAGE s398 DISPLAY LIKE 'I' WITH 'Update table Successfully!'.
ENDIF.
Thank you.
Regards,
Nicole
Hello Community,
is there a possibility to prevent two DB update inconsistent?
I'm working on a program that want to update two add-on tables at the same time, but sometimes only header table (zheader) commit successfully, item table (zitem) not been update but without any exception.
Is any issue for below code? or I need to use in "update task update" for below update?
MODIFY zheader FROM TABLE it_zheader.
IF sy-subrc = 0.
l_flag = 'X'.
ELSE.
l_flag = ''.
ENDIF.
MODIFY zitem FROM TABLE it_zitem.
IF sy-subrc = 0 AND l_flag = 'X'.
l_flag = 'X'.
ELSE.
l_flag = ''.
ENDIF.
IF l_flag = 'X'.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
MESSAGE s398 DISPLAY LIKE 'I' WITH 'Update table Successfully!'.
ENDIF.
Thank you.
Regards,
Nicole
2018 Jul 16 6:02 AM
Please in future use the "code" button in the editor when posting code. I've done it for you this time.
Your coding is poor. First of all, l_flag is not a meaningful name for a variable. How about previous_modify_successful, and use the provided abap_true and abap_false instead of arbitrary '' and 'X'. But the structure is also not good. as you attempt an update of zitem even when the zheader update has already failed.
MODIFY zheader FROM TABLE it_zheader.
IF sy-subrc = 0.
MODIFY zitem FROM TABLE it_zitem.
IF sy-subrc = 0
COMMIT WORK AND WAIT.
db_modify_was_successful = abap_true.
ENDIF.
ENDIF.
If db_modify_was_successful = abap_false.
ROLLBACK WORK.
MESSAGE s398 DISPLAY LIKE 'I' WITH 'Update table Successfully!'.
ENDIF
Do you know it_item isn't empty? Can you reproduce your observed issue? Have you tried debugging?
2018 Jul 16 7:12 AM
Dear Mattehew,
Thanks for your good comments. actually the structure in our production is not like this (this is just a sample), we have the logic in previously form to check it_item empty or not, and this program already run for some time in production environment. don't know why some times item table update failed (we had traced item structure not empty at that moment, no any exception or DB lock occurred).
2018 Jul 16 8:05 AM
2018 Jul 17 2:34 AM
//Correct my code due my typo for message control as below, and highlight that I just need to update the exist record's status in these two tables, not insert new record, tks.
MODIFY zheader FROM TABLE it_zheader.
IF sy-subrc = 0.
l_flag = 'X'.
ELSE.
l_flag = ''.
ENDIF.
MODIFY zitem FROM TABLE it_zitem.
IF sy-subrc = 0 AND l_flag = 'X'.
l_flag = 'X'.
ELSE.
l_flag = ''.
ENDIF.
IF l_flag = 'X'.
COMMIT WORK AND WAIT.
ELSE.
ROLLBACK WORK.
MESSAGE s398 DISPLAY LIKE 'I' WITH 'Update table Error!'.
ENDIF.
2018 Jul 17 2:39 AM
I just want to update some field's value for exist record's in these two tables, and I also can make sure that just no one update the same record at the same time, do I still need to lock the records?
2018 Jul 17 8:09 AM
You must use the SAP locking mechanism if there's a chance of concurrent update.
2018 Jul 17 8:20 AM
2018 Jul 18 3:01 AM
You mean use ENQUEUE and DEQUEUE lock mechanism to lock these two table? or any other?
2018 Jul 18 7:42 AM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |