異步RFC調用實例

2021-02-24 14:22:54 浏览数 (1)

異步RFC:在異步RFC中,執行不依賴與RFC服務器是否可用。被調用的遠程功能啟動后,調用程序繼續運行,遠程功能和調用程序處理相互分離。遠程功能的結果可以延時接收。 RFC異步調用只能使用Tables、Exporting和Exceptions參數。調用程序不等待Function返回結果,不能直接從被調用的函數中返回結果,可以在後續的回調子程序中獲取結果。

代码语言:javascript复制
PARAMETERS: plnum LIKE plaf-plnum.
DATA: l_return LIKE bapireturn1,
      l_header LIKE bapiplaf_e1,
      l_ca     LIKE bapi_kbko,
      l_ca1    LIKE bapi_kbko,
      l_ca2    LIKE bapi_kbko,
      l_com    LIKE TABLE OF bapi_pldordcomp_e1 WITH HEADER LINE,
      l_capa   LIKE TABLE OF bapi_pldordcapa_e1 WITH HEADER LINE,
      l_capa1  LIKE TABLE OF bapi_pldordcapa_e1 WITH HEADER LINE,
      l_capa2  LIKE TABLE OF bapi_pldordcapa_e1 WITH HEADER LINE.

CALL FUNCTION 'BAPI_PLANNEDORDER_GET_DETAIL'
  DESTINATION '目標系統'
  STARTING NEW TASK 'B1'//指明異步調用模式
  PERFORMING return ON END OF TASK//調用子程序接收返回結果
  EXPORTING
    plannedorder          = plnum.
IF sy-subrc = 0.
  write:/'Success call'.
ENDIF.
AT USER-COMMAND.
  IF sy-ucomm = 'OK'.
    WRITE:/ 'Header Info'.
    ULINE.
    WRITE:/ l_header-plannedorder_num,
            l_header-material,
            l_header-plan_plant,
            l_header-prod_plant ,
            l_header-order_type,
            l_header-total_plord_qty,
            l_header-order_start_date,
            l_header-order_fin_date.
    ULINE.
    WRITE:/ 'Companentsdata Info'.
    ULINE.
    LOOP AT l_com.
      WRITE:/ l_com-material.
    ENDLOOP.
  ENDIF.
FORM return USING taskname.
  RECEIVE RESULTS FROM FUNCTION 'BAPI_PLANNEDORDER_GET_DETAIL'
  keeping task//使已加載的遠程上下文保持至調用程序結束,直到遠程連接終止。
 IMPORTING
   return                    = l_return
   headerdata                = l_header
   capacityheaderdata1       = l_ca
   capacityheaderdata2       = l_ca1
   capacityheaderdata3       = l_ca2
 TABLES
   componentsdata            = l_com
   capacitydata1             = l_capa
   capacitydata2             = l_capa1
   capacitydata3             = l_capa2.
  SET USER-COMMAND 'OK'.
ENDFORM.

通常情況下,回調子程序不會自動運行,只有出現對話步驟或調用程序進入內存暫時掛起狀態時,才會觸發該子程序。

0 人点赞