ABAP Keyword Documentation → ABAP - Reference → Data Interfaces and Communication Interfaces → RFC - Remote Function Call → Examples for Remote Function Call
Parallel asynchronous RFC
This example demonstrates parallel asynchronous RFC processing.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: snd_jobs TYPE i,
exc_flag TYPE i,
indx TYPE c LENGTH 4,
name TYPE c LENGTH 8.
DATA(out) = cl_demo_output=>new( ).
DO 10 TIMES.
indx = sy-index.
name = 'Task' && indx.
CALL FUNCTION 'RFC_SYSTEM_INFO'
STARTING NEW TASK name
DESTINATION IN GROUP DEFAULT
CALLING callbback_meth ON END OF TASK
EXCEPTIONS
system_failure = 1 MESSAGE mess
communication_failure = 2 MESSAGE mess
resource_failure = 3.
CASE sy-subrc.
WHEN 0.
snd_jobs = snd_jobs + 1.
WHEN 1 OR 2.
out->write_text( mess ).
WHEN 3.
IF snd_jobs >= 1 AND
exc_flag = 0.
exc_flag = 1.
WAIT UNTIL rcv_jobs >= snd_jobs
UP TO 5 SECONDS.
ENDIF.
IF sy-subrc = 0.
exc_flag = 0.
ELSE.
out->display( 'Resource failure' ).
ENDIF.
WHEN OTHERS.
out->display( 'Other error' ).
ENDCASE.
ENDDO.
WAIT UNTIL rcv_jobs >= snd_jobs.
out->display( task_list ).
Description
Parallel asynchronous processing of the function module RFC_SYSTEM_INFO using
asynchronous remote function calls. Ten calls with different task IDsname
are made, which each run in a separate
work process. The callback
routine callbback_meth
counts the completed function modules and receives information about the target system.
The addition GROUP DEFAULT
is used to distribute the execution among all
application servers
for the current system. If no further work process is available after at least one successful call,
the system interrupts execution of the program until all function modules that have already been started have been completed. This interruption is limited to a maximum of five seconds.
After starting all function modules, the system waits until all callback routines have been executed.
Then it outputs the internal table task_list
it has filled. The output shows the sequence in which the individual tasks were completed and the application server each one was executed on.