Skip to content

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 += 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 IDs name 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 across all AS Instancess of the current AS ABAP. If no more free work processes are available after at least one successful call, the execution of the program is stopped until all function modules started up to that point have been completed. This stoppage is limited to a maximum of 5 seconds.

After all function modules have been started, the system waits until all callback routines have been executed. After that, the internal table task_list filled there is produced. The output shows the order in which the individual tasks were completed and on which AS Instance.