Ansicht
Dokumentation

ABENRFC_EXAMPLE - RFC EXAMPLE

ABENRFC_EXAMPLE - RFC EXAMPLE

PERFORM Short Reference   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.
SAP E-Book

RFC Example

Parallel asynchronous processing of the function module RFC_SYSTEM_INFO using asynchronous Remote Function Calls. Ten calls take place, each of which runs with a different task name name in a separate work process. In the callback routine rfc_info, the completed function modules are counted and information about the target system is received.

By using the AB>GROUP DEFAULT addition, the execution is spread across all application servers in the current system. If no free work process is availeble after at least one successful call, the execution of the program is interrupted until all function modules that were started up to this point are completed. This interruption 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. The internal table filled there (task_list) is then displayed. The output shows the order in which the individual tasks were completed and on which application server they were 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.






Fill RESBD Structure from EBP Component Structure   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 5608 Date: 20240423 Time: 165253     sap01-206 ( 30 ms )