Start of Content Area

Background documentation aRFC Programming Example   Locate the document in its SAP Library structure

This example shows parallel asynchronous processing of function module RFC_SYSTEM_INFO using asynchronous Remote Function Calls.

Ten calls are made, each occurring in separate work processes due to them having different task IDs name. In the callback routine rfc_info, the completed function modules are counted, and information about the target system is received.

Through using the addition GROUP DEFAULT, the execution is distributed across all application servers of the current system. 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 output. The output shows the sequence in which the individual tasks completed, and on which application server each of them was executed.

 

TYPES: BEGIN OF task_type,
         name  TYPE string,
         dest  TYPE string,
       END OF task_type.

DATA: snd_jobs  TYPE i,
      rcv_jobs  TYPE i,
      exc_flag  TYPE i,
      info      TYPE rfcsi,
      mess      TYPE c LENGTH 80,
      indx      TYPE c LENGTH 4,
      name      TYPE c LENGTH 8,
      task_list TYPE STANDARD TABLE OF task_type,
      task_wa   TYPE task_type.

DO 10 TIMES.
  indx = sy-index.
  CONCATENATE 'Task' indx INTO name.
  CALL FUNCTION 'RFC_SYSTEM_INFO'
    STARTING NEW TASK name
    DESTINATION IN GROUP DEFAULT
    PERFORMING rfc_info 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.
      MESSAGE mess TYPE 'I'.
    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.
        MESSAGE 'Resource failure' TYPE 'I'.
      ENDIF.
    WHEN OTHERS.
      MESSAGE 'Other error' TYPE 'I'.
  ENDCASE.
ENDDO.

WAIT UNTIL rcv_jobs >= snd_jobs.
LOOP AT task_list INTO task_wa.
  WRITE: / task_wa-name, task_wa-dest.
ENDLOOP.


FORM rfc_info USING name.
  task_wa-name = name.
  rcv_jobs = rcv_jobs + 1.
  RECEIVE RESULTS FROM FUNCTION 'RFC_SYSTEM_INFO'
    IMPORTING
      rfcsi_export = info
    EXCEPTIONS
      system_failure        = 1 MESSAGE mess
      communication_failure = 2 MESSAGE mess.

  IF sy-subrc = 0.
    task_wa-dest = info-rfcdest.

  ELSE.
    task_wa-dest = mess.
  ENDIF.
  APPEND task_wa TO task_list.
ENDFORM.



 

 

 

 

End of Content Area