Fighting Problems of Asynchronous Processing in ABAP - Hello World!
Fighting Problems of Asynchronous Processing in ABAP - Hello World!
Hello World!
My thoughts on SAP development, technology and more…
In most Standard SAP applications, changes to data are not directly (“synchronously”) written back to the database.
Instead, SAP Netweaver buffers these changes and writes them at a later time (“asynchronously”).
On many occasions, you won’t notice this asynchronous nature and it won’t cause any problems. Even
better, asynchronous processing is good for performance! However, sometimes you’ll want to continue
processing only when the database is completely up-to-date. For example:
When you are trying to get additional data not returned by the BAPI or Function Module you just called;
When you want to run another BAPI or Function Module that depends on the database being completely up to
date after the previous call.
Especially in interface programming, I have seen some cumbersome solutions. The good news is: There are good
solutions to enforce synchronous processing. This post lists these options.
During development or even during testing, some developers notice the asynchronous behaviour and try to fight it –
with varying success. One approach I have seen (and even used myself!) is to use a WAIT statement to let the
program in the current work process sleep for several seconds:
* Step 2: Wait for some period of time that you see fit
WAIT UP TO 15 SECONDS.
While this example functions, there are some serious downsides to this ‘solution’:
Rather than changing the processing mode itself, it is fighting a symptom of asynchronous processing;
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
It is difficult to decide how long you should wait. A time interval that is long enough on your oversized
To find out more, including how to control cookies, see here: Cookie Policy
Close and accept
development system, might be too short on your crowded production system.
https://wilcomenge.wordpress.com/2011/01/31/synchronous-processing-abap/ 1/8
2/28/24, 1:17 PM Fighting problems of asynchronous processing in ABAP | Hello World!
The performance of your system and the overall user experience goes down the drain as the current
process becomes unresponsive and waits for a period that is almost certainly far too long.
The following solutions can be successful in changing an asynchronous processing mode to a synchronous
processing mode:
By using the SET UPDATE TASK LOCAL statement, SAP Netweaver executes database updates in the current work
process instead of a separate background process. Then, by using the COMMIT WORK statement, you force all
updates in the current process to finish before continuing.
In most situations, all databases updates are finished after this point.
https://wilcomenge.wordpress.com/2011/01/31/synchronous-processing-abap/ 2/8
2/28/24, 1:17 PM Fighting problems of asynchronous processing in ABAP | Hello World!
* Main effect: All commits of all work processes in the
* the remote session will executed
* Side effects:
* -A next RFC call will be started in a new session.
* -This resets the globals data in the function group.
CALL FUNCTION 'RFC_CONNECTION_CLOSE'
EXPORTING destination = 'NONE'
EXCEPTIONS OTHERS = 0.
It is necessary to use the BAPI_TRANSACTION_COMMIT Function Module instead of the regular COMMIT WORK
AND WAIT statement. This is because the COMMIT has to take place in the ‘remote’ work process and not in the
local process.
Peter
on March 21, 2011 at 14:14 said:
Hi
thanks
is the DESTINATION ‘NONE’ actually needed in the first solution or just the 2nd?
Peter
wilcomenge
on March 21, 2011 at 15:12 said:
Nope, you’re right! I admit: its a typo and I have just fixed it.
Bernd
on April 4, 2011 at 13:37 said:
Heey Wilco,
Bernd
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
https://wilcomenge.wordpress.com/2011/01/31/synchronous-processing-abap/ 3/8
2/28/24, 1:17 PM Fighting problems of asynchronous processing in ABAP | Hello World!
manuelecheverry
on October 2, 2014 at 00:14 said:
Abaper
on January 13, 2015 at 07:36 said:
wilcomenge
on May 18, 2015 at 09:58 said:
The first solution has the least impact. Normally, the actual DB update is done in a seperate process.
This way, the user doesn’t have to wait for the actual DB operation. But: in some cases you *do* want
to wait for the DB update to finish. In that case, try one of the solutions mentioned here.
Sravanthi
on May 17, 2015 at 05:00 said:
I have used the first solution you suggested. But, instead of COMMIT WORK AND WAIT, I used
BAPI_TRANSACTION_COMMIT (without a wait). Does that make a difference?
The problem still persists. In the production system, sometimes the release does not commit to database.
Please note that it is happening randomly ( like once or twice in a month), not able to find the cause.
Also, I am working on a single system, so there is no remote system. In that case, does it make sense to try
the second solution? (RFC_CONNECTION_CLOSE)
wilcomenge
on May 18, 2015 at 10:19 said:
Using COMMIT WORK AND WAIT or BAPI_TRANSACTION_COMMIT shoulnd’t make a real differ-
ence, since the last one is just a wrapper for COMMIT WORK.
It is indeed possible that the problem in my blog occurs randomly: Sometimes the database is under
light load and the update happens fast enough, sometimes the update is slower. However: in all
cases, the update occurs eventually. Is this also the case in your situation?
On you last remark: Yes, it makes sense to try the second solution (RFC_CONNECTION_CLOSE),
even in a single system: You actually do a remote call the the same system, forcing all update logic in
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
https://wilcomenge.wordpress.com/2011/01/31/synchronous-processing-abap/ 4/8
2/28/24, 1:17 PM Fighting problems of asynchronous processing in ABAP | Hello World!
a new session. This way, when the other session has been closed, you can be sure that all database
operations are finished.
Sravanthi
on May 17, 2015 at 05:00 said:
I have used the first solution you suggested. But, instead of COMMIT WORK AND WAIT, I used
BAPI_TRANSACTION_COMMIT (without a wait). Does that make a difference?
The problem still persists. In the production system, sometimes the release does not commit to database.
Please note that it is happening randomly ( like once or twice in a month), not able to find the cause.
Also, I am working on a single system, so there is no remote system. In that case, does it make sense to try
the second solution? (RFC_CONNECTION_CLOSE).
Hariny
on October 18, 2017 at 08:04 said:
Thanks for the post. When I use the first solution, I get a GUI screen for Update control and each time in loop
I need to press back button. Any idea how to avoid this?
wilcomenge
on October 18, 2017 at 09:13 said:
That is probably caused by some of the code that you are calling. I think you should try one of the
other solutions mentioned in the post. Your mileage may vary.
mks49443
on February 8, 2018 at 01:06 said:
HI Wilcomenge,
Thanks for the nice blog.
I got a problem here.. I am using the Solution 1, for example if 5 items in a sales order it creates 4 items and
one item comes out an error message ‘Sales document XXXX is currently being processed by user’ .
Please advise the solution to resolve this isues.
Warm regards
Chandra
wilcomenge
on February
Privacy & Cookies: This site uses cookies. 8,
By2018 at 08:45
continuing said:this website, you agree to their use.
to use
To find out more, including how to control cookies, see here: Cookie Policy
https://wilcomenge.wordpress.com/2011/01/31/synchronous-processing-abap/ 5/8
2/28/24, 1:17 PM Fighting problems of asynchronous processing in ABAP | Hello World!
It sounds like you are first trying to save the order header and create the items in subsequent Function
Module calls. Is that correct? I would expect that whatever Function Module you are calling is able to
create the header and all items in one call, preventing the application lock.
mks49443
on February 9, 2018 at 01:22 said:
I have exhausted all the solutions and implemented your first solution but still no joy.
The code snippets is as shown below:
Please advise.
Warm regards
Chandra
CREATION OF ORDER
SET UPDATE TASK LOCAL.
https://wilcomenge.wordpress.com/2011/01/31/synchronous-processing-abap/ 6/8
2/28/24, 1:17 PM Fighting problems of asynchronous processing in ABAP | Hello World!
foreign_lock = 02
system_failure = 03.
* Check whether lock was successful
IF sy-subrc = 0.
* Successful lock so exit do loop
CALL FUNCTION ‘DEQUEUE_EVVBAKE’
EXPORTING
VBELN = lv_VBELN.
EXIT.
ELSE.
* Unsuccessful lock so wait 1 second and retry
WAIT UP TO 1 SECONDS.
ENDIF.
ENDDO.
LOOP AT lt_bapiret2 INTO ls_bapiret2.
APPEND ls_bapiret2 TO return_tab.
* Check if there is an error in BAPI returned messages
IF ls_bapiret2-type = lc_e.
lv_error = lc_x.
* Begin of insert by MarkYang LD4K900464
* rollback material data created above
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.
* End of insert LD4K900464
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
DESTINATION ‘NONE’
EXPORTING
wait = ‘X’
IMPORTING
return = ls_bapiret2.
ENDIF.
ENDLOOP.
CHANGE OF ORDER
https://wilcomenge.wordpress.com/2011/01/31/synchronous-processing-abap/ 7/8
2/28/24, 1:17 PM Fighting problems of asynchronous processing in ABAP | Hello World!
vbeln = lp_VBELN
EXCEPTIONS
foreign_lock = 02
system_failure = 03.
* Check whether lock was successful
IF sy-subrc = 0.
* Successful lock so exit do loop
CALL FUNCTION ‘DEQUEUE_EVVBAKE’
EXPORTING
VBELN = lp_VBELN.
EXIT.
ELSE.
* Unsuccessful lock so wait 1 second and retry
WAIT UP TO 1 SECONDS.
ENDIF.
ENDDO.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
https://wilcomenge.wordpress.com/2011/01/31/synchronous-processing-abap/ 8/8