异步RFC实例

   异步RFC不等调用的RFM返回就往下执行,用STARTING NEW TASK TASKNAME启动,
调用时不能指定IMPORT输出参数,在RFM内部不能抛出除SYSTEM_FAILURE和COMMUNICATION_FAILURE以外的其他异常,可以用PERFORMING FORMNAME ON  END OF TASK 指定用于回调的FORM,在回调FORM里面用RECEVING RESULTS FROM FUNCTION rfc_name,还有如果是被调用的函数里面出现dialog,则在调用系统中出现的新的会话,所以如果调用系统的会话数超过6个就会触发SYSTEM_FAILURE异常。
实例:RFM如下:
FUNCTION ZRFC_USER_READ.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(USER_NAME) TYPE  XUBNAME
*"  EXPORTING
*"     VALUE(USER_ADDR) TYPE  USR03
*"     VALUE(SYSTEM_ID) TYPE  SYSYSID
*"  TABLES
*"      USER_PARA STRUCTURE  USR05
*"----------------------------------------------------------------------
SELECT SINGLE * INTO USER_ADDR FROM USR03
    WHERE BNAME = USER_NAME.

  SELECT  * INTO TABLE USER_PARA FROM USR05
    WHERE BNAME = USER_NAME.

  SYSTEM_ID = SY-SYSID.




ENDFUNCTION.



测试程序,调用异步RFC
*&---------------------------------------------------------------------*
*& Report  ZTCXHTEST_GETRESULT_RETURN
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTCXHTEST_GETRESULT_RETURN.

DATA: user_addr TYPE user_addr,
      system_id TYPE sysysid,
      user_para LIKE TABLE OF usr05 WITH HEADER LINE,
      msg_text(128).

CALL FUNCTION 'ZRFC_USER_READ'
  "DESTINATION 'lhlinux_DEV_00'
  STARTING NEW TASK 'B1'
  PERFORMING return_user ON END OF TASK
  EXPORTING
    user_name             = 'CXH'
  EXCEPTIONS
    communication_failure = 1  MESSAGE msg_text
    system_failure        = 2  MESSAGE msg_text.
IF sy-subrc = 0.
  WRITE: 'Wait for reply.'.
ELSE.
  WRITE msg_text.
ENDIF.

* Varify the FORM routine RETURN_USER is not called yet
IF user_para IS INITIAL.
  WRITE:/ 'Destination not ready yet.'.
ELSE.
  WRITE:/ 'Destination is reached.'.
ENDIF.

AT USER-COMMAND.
* Return from FORM routine RETURN_USER via SET USER-COMMAND
  IF sy-ucomm = 'OKCD'.
    IF msg_text = space.
      WRITE: / 'Destination system', system_id.
      LOOP AT user_para.
        WRITE:/ user_para-bname,
                user_para-parid,
                user_para-parva.
      ENDLOOP.
    ELSE.
      WRITE msg_text.
    ENDIF.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  RETURN_USER
*&---------------------------------------------------------------------*
FORM return_user USING taskname.
  RECEIVE RESULTS FROM FUNCTION 'ZRFC_USER_READ'
    IMPORTING
      user_addr       = user_addr
      system_id       = system_id
    TABLES
      user_para       = user_para
    EXCEPTIONS
      communication_failure  = 1 MESSAGE msg_text
      system_failure         = 2 MESSAGE msg_text.
  SET USER-COMMAND 'OKCD'.
ENDFORM.                    "return_info

你可能感兴趣的:(实例)