Call Function module IN BACKGROUND TASK - Execute abap code in seperate background process

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.

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


Related Articles

ABAP COLLECT statement syntax to add up all numeric internal table values within SAP
ABAP DELETE statement keyword to delete data from SAP internal and database tables
ABAP DESCRIBE statement keyword to get information about tables and fields
PERFORM TABLES command passing internal table as parameter
ABAP read command to read line of internal table in SAP
ABAP UPDATE command to modify database field values
AUTHORITY-CHECK abap Statement / command
ABAP delete command in SAP
ABAP MODIFY statement to update SAP data within database and internal tables
ABAP WRITE statement command with in SAP to display data report to users
SAP ABAP Statement syntax including basic implementation code
Concatenate ABAP statement syntax for concatenating data objects, sting values or rows of an SAP internal table
ABAP EXPORT data TO MEMORY ID and import it back again
IF, CHECK & WHEN ABAP commends example source code and information
Function module IN UPDATE TASK statement - Execute abap code in seperate unit of work
ABAP STRLEN command to get the value length of a SAP field
SAP ABAP SELECT command and its different uses
SELECT..ENDSELECT command
ABAP FOR ALL ENTRIES SELECT statement addition in SAP data retrieval
ABAP SELECT inner join statement to select from two tables at the same time
SELECT directly into an internal table
SELECT directly into an internal table when field order is different
Function module STARTING NEW TASK statement - Execute abap code in seperate work process