sapdev logo background
sapdev logo sapdev logo
Comments

Function module IN UPDATE TASK statement - Execute abap code in seperate unit of work




The IN UPDATE TASK statement allows you to call a function module but it will not be executed until an update task is initiated by the 'COMMIT WORK' statement. This means that the program logic after calling the FM will immediately continue with the next line of ABAP code and the FM will sit and wait for the commit work. This also allows you to execute several sections of code asynchronously by calling the ABAP function module with the IN UPDATE TASK statement then performing the commit work command. See example below!

If you are thinking of using this functionality please consider if it is actually an update task you want rather than a background task. The 'IN BACKGROUND TASK' works in exactly the same but performs the final processing in background rather than using one of the update processes available on your SAP system.

Your SAP system will have X number of update process and X number of background processes available. If the processing takes a long time and it is a program that is used by many people you could quite easily use up all the available update processes causing any other important database updates to be queued up behind these. Update processes really should be very quick, i.e. if you update your personnel details this should be committed to the database within an update task and should take seconds or even milliseconds. If you are processing a lot of data which takes minutes you might need to consider if it really should be an update task and if a background task wouldn't be more appropriate.

Example ABAP code to execute FM in update task within separate unit of work

CALL FUNCTION 'Z_FMODULE' IN UPDATE TASK
 EXPORTING
    P_UNAME       = sy-uname.

commit work. "Commits all work to database and also starts all FM's running in update task

"loop at it_ekko. "program continues with next line of ABAP without waiting for update and FM to finish
"...
"endloop.

Also see:
STARTING NEW TASK
IN UPDATE TASK
IN BACKGROUND TASK




comments powered by Disqus