Why do we use CALL FUNCTION ..IN BACKGROUND TASK and CALL FUNCTION ...STARTING NEW TASK?

What is the difference?

Answer Posted / sathish kumar

The IN BACKGROUND TASK statement allows you to execute remote enabled function modules in a background task asynchronously. Be careful thought as it might not quite work as it appears too i.e. If you debug the ABAP program logic it will step over the FM onto the next line of code, not waiting for this function module to finish it processing. But this doesn�t mean it has gone off to start the processing at this point as it has not!! It has simply created the background task ready for processing and will not actually be executed until a commit work is reached in the current logical unit of work. 




So basically if you want it to go off and perform this background processing straight away you need to add a commit work after the call function� in background task command. 




Just in case you are interested in the technical details when you make the call using the in background task addition SAP stores the FM name, destination and any parameters in tables ARFCSSTATE & ARFCSDATA for the current Logical unit of work. These entries can also been seen using tcode SE58. Please note this data is not available here after the task has finished processing. 




Although this may seem strange at first it does allow you to perform other functionality first and only triggers the background task if all is well with that and it is committed to the database ok. Also the background tasks will be processed in the order they have been registered. 




AS SEPARATE UNIT 
The �as separate unit� addition is used if you are calling the same FM multiple times or FM�s within the same function group. It basically ensures each call is processed within its own context and is not affected by global data changes from other function calls. 




DESTINATION 
This simple allows you to specify a different RFC destination 




Example ABAP code to Execute FM in background task




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








*IN BACKGROUND TASK additional options
CALL FUNCTION 'Z_FMODULE' IN BACKGROUND TASK
      AS SEPARATE UNIT
      DESTINATION 'NONE'
  EXPORTING
    P_UNAME       = sy-uname.








break-point. "does not wait and continues with next line of ABAP code




Commit Work. "Background task is only triggered at this point.




"loop at itab into wa_itab.
"...
"endloop.

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.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can anyone done BDC/LSMW/BAPI for F-02 and F-04.If yes let me know the processs

1850


When the top-of-page event does get triggered?

678


Hi every one ! You people are doing a great job here , Im going to attend Tata Technologies interivew on this sunday,Can anyone who has already attended this company interivew or other companies interivews in abap pls share ur experience with me and help me to get into job my id ushareddyabap@gmail.com. Thankyou verymcuh

1503


What are the differences between structure and table in data dictionary in abap? : sap abap data dictionary

581


What are the different types of view?

597






What will exactly the hide statement do?

571


What is a type group?

546


what is sales order confirmation and how can do design it in webdynpro. what is Tcode for the same?

1988


Kindly help me to Know the process of mapping in EDI from R/3 to a convertor(third party which translates IDoc flatfile to EDIFACT /XML / FTP /HTTP ) ?

1549


How do you find number of records present in internal table?

564


what is field string ? & where we are using field strings?

1570


What is the difference between synchronous and asynchronous update? : abap bdc

635


What is asap methodology? : sap abap hr

559


There is a situation where there is a field "MATERIAL DESCRIPTION" in say 20 display only transaction. You want that whenever user opens any of these transaction, this particular field is masked with ****. But table does not holds ****. It holds the actual value. What are different ways of doing it? Which is the best way.

924


What is the difference between rfc and bapi function modules? : abap bdc

622