sapdev logo background
sapdev logo sapdev logo
Comments

Function module STARTING NEW TASK statement - Execute abap code in seperate work process



The STARTING NEW TASK statement allows you to call a function module but it will be executed in a separate processing task asynchronously so the ABAP program logic does not wait for this FM to finish its processing but continues with the next line of abap code. The clever thing about this statement is that once the FM has finished processing it will then execute the specified FORM within the original program to continue processing.

This small example is actually the basis for reports which auto-refresh themselves. i.e. the program calls a function module in a new task which then waits a few seconds (WAIT 10 seconds). Once it returns to the program and performs the return form it basically re-runs the whole report again. This especially creates an endless loop so report keeps updating itself until it is cancelled by the user.

Execute FM in update task within separate unit of work

CALL FUNCTION 'Z_FMODULE'
  starting new task 'UPDATE'
             destination 'NONE'
              performing processing_done on end of task
  EXPORTING
    P_UNAME       = sy-uname.

"program does not wait for FM to finish processing and continues with next line of ABAP code
break-point.
"...perform display_report.



FORM processing_done.
* In the mean time once processing of FM Z_FMODULE is complete this abap FORM is then executed.
WIthin here you can perform any processing you like, including re-displaying a report

"...perform display_report.
ENDFORM.

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



comments powered by Disqus


Can't find something on ERPWorkbench? A quick search should fix that: