2020 Aug 25 11:45 AM
Hi all,
I updated my database table ZTD_RQ001 with new status = 03 and set to send email based on new status 03. However during the send email part, the retrieval from the table seems to be still previous status 02.
However...after checking the status in the DB table using SE16n the status is indeed 03.
Is there any time delay in from the time of my commit work and wait....commit work then select from ZTD_RQ001?
Is there anything wrong with my commit work and wait? I thought it supposed to update the status to 03 then only continue the codes below? Anyone have any idea?
I simplify the flow as shown in the code below.
gw_rq001-status ='03'.
MODIFY ztd_rq001 FROM gw_rq001.
IF sy-subrc <> 0.
re_error = 'X'. ROLLBACK WORK.
lv_message = 'Error during update into the table'.
wd_comp_controller->message_manager->report_error_message(
message_text = lv_message
cancel_navigation = abap_true ).
EXIT.
ELSE.
COMMIT WORK AND WAIT.
ENDIF.
COMMIT WORK.
****send email part
****the ls_rq001-status from this point still seems to be 02
SELECT SINGLE * INTO ls_rq001
FROM ztd_rq001
WHERE bukrs = wd_this->bukrs
AND werks = wd_this->werks
AND tdrnr = wd_this->tdrnr.
IF sy-subrc <> 0.
RETURN.
ENDIF.
2020 Aug 25 11:54 AM
Dear Siong,
I assume that you have made a select to chose the data you want to modify, before the modify statement, right?
so before this :
gw_rq001-status ='03'.MODIFY ztd_rq001 FROM gw_rq001.
you should have :
SELECT *INTO table gt_rq001
FROM ztd_rq001
WHERE bukrs = wd_this->bukrs
AND werks = wd_this->werks
AND tdrnr = wd_this->tdrnr.
loop at gt_rq001 into gw_rq001.
*inside here your code
gw_rq001-status ='03'.
MODIFY ztd_rq001 FROM gw_rq001.
endloop.
let me know if it works.
Roxani
2020 Aug 25 12:12 PM
Hi Roxani,
No. It is I update the table with status 03 first then only I select. I assume the table should be updated with 03 now. The problem here is the value is still 02 during the select time. This scenario does not happens everytime.
2020 Aug 25 1:00 PM
2020 Aug 25 1:01 PM
Hi,
No need to write Commit 2 times,use the stmt like Commit work and Wait up to 3 seconds.it will resolve your issue.
2020 Aug 25 1:25 PM
There's no delay. COMMIT WORK AND WAIT is not needed (AND WAIT is not for the direct database update as yours, it's to be used only if you have used CALL FUNCTION 'XXX' IN UPDATE TASK).
There's an issue in your code somewhere. Are you sure of the origin of the "status" that you use for the email processing? Do you execute UPDATE/SELECT in different asynchronous threads?
2020 Aug 26 2:26 AM
Hi Sandra,
As you can see above there is 2 commit statement before I re-select the ZTD_RQ001 table again assuming the status field will be updated with 03 value. But let say, if the SAP system is slow or there is network issue on the day...there seems to be the value is still not updated with 03 at the select part.
Is commit work and wait up to xx seconds is the only solution here?
1. I dont know how many seconds I need to put
2. It will make the system slow
Is this a solution left only?
2020 Aug 26 8:02 AM
Is there parallel activities expected writing the content of the database table?
(From an update task to an asynchronous call to an external system with an RFC call back etc., or to another user?)
If not, a simple COMMIT WORK should be sufficient as all OpenSQL database requests are synchronous. COMMIT WORK AND WAIT is for the case when you need to wait for update processing, however I see no CALL FUNCTION IN UPDATE TASK in your code snippet.
If there are parallel activities, lock handling might be badly missing.
(There is a potential consistency issue with the change being committed even if there is an error sending the mail. I assume this is not the issue you are looking for.)
2023 Mar 23 10:07 AM
2023 Mar 23 10:28 AM
A tip - if you're leaving a program block, use RETURN rather than EXIT. EXIT behaves differently depending on context - RETURN always leaves the program block.
Anyway...
Can you not simply use the contents of gw_rq001 to generate the email? Why are you reading the same data back from the database?
2023 Mar 23 12:25 PM
Did you check that fields from gw_rq001 are equal to wd_this->bukrs werks tdrnr?
Or in other words are you sure you select the entry you updated?
2023 Mar 23 5:27 PM
Hi Siong,
Better to split the update & email program's rather than having it in same program.
This is due to update timing issues.
Try writing the email code in a separate include program.
If it still doesn't work write the email logic in a separate program and execute them sequentially.