You are on page 1of 5

Call Function module IN BACKGROUND TASK - Execute abap

code in separate 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.

How to debug the FM which is called in


background task
3128,912

How to debug the FM which is called in background task

James Zeng    Date: 2012-06-28

Symptom

Today I met one issue that there is one FM-AAA which be called in program BBB in background task way,
now we want to debug the FM-AAA.

The real FM-AAA is ZVXX_IDOC_ASNPP, the caller program is


IDOCS_OUTPUT_TO_OWN_FUNCTION for my real case.
When the program really run, the EDIPOF-FUNCTION will be replaced
with ZVXX_IDOC_ASNPP in my situation.

Solution
1. Set external breakpoint in the FM-AAA (ZVXX_IDOC_ASNPP)
2. Start program-BBB (IDOCS_OUTPUT_TO_OWN_FUNCTION) in debug.
3. When you reach the breakpoint, select menu Settings, Display/Change debugger settings, select the
flag “tRFC (In Background Task): Block Sending”. This flag means that, when the commit work
occurs, the background task (FMs + parameters) is stored into database but not executed.
4. Run the t-code SM58
5. Select the background task you just created, and choose menu edit + debug LUW, the “background
task” will start interactively and the debugger will stop at predefined points by in FM AAA
automatically.

My demo example:

We use one shipment to trigger one output type ZASN to call FM-IDOC_OUTPUT_SHPMNT to create the
shipment IDoc, then based on this shipment IDoc to create the customer ASN IDOC( which will call FM-
ZVXX_IDOC_ASNPP )
After the ‘commit work’ statement called, the background task created in the database

Then use SM58 to search whether any background task created


We debug this background task

Then the logic will stop at the breakpoint we set in the FM- ZVXX_IDOC_ASNPP.

You might also like