CALL RFC synchronize and asychronize Examples

同步调用RFC 示例
*&---------------------------------------------------------------------*
*& Report  sapbc415_rfcsync_s1                                         *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT SAPBC415_RFCSYNC_S1  MESSAGE-ID BC415.

TABLES SPFLI.

PARAMETERS: ICARR LIKE SFLIGHT-CARRID DEFAULT 'LH',
            ICONN LIKE SFLIGHT-CONNID DEFAULT '0400',
            DEST  LIKE RFCDES-RFCDEST DEFAULT 'NONE'.

DATA: SYSID LIKE SY-SYSID,
      MESS(80).

CALL FUNCTION 'BC415_RFC_READ_SPFLI'
    DESTINATION DEST
    EXPORTING
       CARRID   = ICARR
       CONNID   = ICONN
    IMPORTING
       EX_SPFLI = SPFLI
       SYS      = SYSID
    EXCEPTIONS
       INVALID_DATA          = 1
       COMMUNICATION_FAILURE = 2  MESSAGE MESS
       SYSTEM_FAILURE        = 3  MESSAGE MESS.

CASE SY-SUBRC.
  WHEN 1.
    WRITE: / TEXT-001.
    EXIT.
  WHEN 2.
    WRITE: / MESS.
    EXIT.
  WHEN 3.
    WRITE: / MESS.
    EXIT.
ENDCASE.

WRITE: / TEXT-004, SYSID COLOR 5.
SKIP.
WRITE: SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM, SPFLI-CITYTO.

异步调用RFC示例
*&---------------------------------------------------------------------*
*&                                                                     *
*& Report  sapbc415_rfcasync_s1                                        *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT SAPBC415_RFCASYNC_S1  MESSAGE-ID BC415.

TABLES SPFLI.

PARAMETERS: ICARR LIKE SFLIGHT-CARRID DEFAULT 'LH',
            ICONN LIKE SFLIGHT-CONNID DEFAULT '0400',
            DEST  LIKE RFCDES-RFCDEST DEFAULT 'NONE'.

DATA: SYSID LIKE SY-SYSID,
      MESS(80),
      FLAG,
      RETCODE LIKE SY-SUBRC.

CALL FUNCTION 'BC415_RFC_READ_SPFLI'
   DESTINATION DEST
   STARTING NEW TASK 'T1'
   PERFORMING BACK ON END OF TASK
   EXPORTING
      CARRID  = ICARR
      CONNID  = ICONN
   EXCEPTIONS
      COMMUNICATION_FAILURE = 2  MESSAGE MESS
      SYSTEM_FAILURE        = 3  MESSAGE MESS.

CASE SY-SUBRC.
  WHEN 2.
    WRITE: / MESS.
    EXIT.
  WHEN 3.
    WRITE: / MESS.
    EXIT.
ENDCASE.

WAIT UNTIL  FLAG = 'X'.

CASE RETCODE.
  WHEN 0.
    WRITE: / TEXT-004, SYSID COLOR 5.
    SKIP.
    WRITE: SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM, SPFLI-CITYTO.
  WHEN 1.
    WRITE: / TEXT-001, / TEXT-002.
  WHEN 2 OR 3.
    WRITE MESS.
ENDCASE.


*---------------------------------------------------------------------*
*       FORM BACK                                                     *
*---------------------------------------------------------------------*
*        -->  T                                                       *
*---------------------------------------------------------------------*
FORM BACK USING T.

  RECEIVE RESULTS FROM FUNCTION 'BC415_RFC_READ_SPFLI'
     IMPORTING
        EX_SPFLI  = SPFLI
        SYS       = SYSID
     EXCEPTIONS
        INVALID_DATA          = 1
        COMMUNICATION_FAILURE = 2  MESSAGE MESS
        SYSTEM_FAILURE        = 3  MESSAGE MESS.

  RETCODE = SY-SUBRC.

  FLAG = 'X'.

ENDFORM.

RFC函数原型
FUNCTION BC415_RFC_READ_SPFLI.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"       IMPORTING
*"             VALUE(CARRID) LIKE  SFLIGHT-CARRID OPTIONAL
*"             VALUE(CONNID) LIKE  SFLIGHT-CONNID OPTIONAL
*"       EXPORTING
*"             VALUE(EX_SPFLI) LIKE  SPFLI STRUCTURE  SPFLI
*"             VALUE(SYS) LIKE  SY-SYSID
*"       EXCEPTIONS
*"              INVALID_DATA
*"----------------------------------------------------------------------
  SELECT SINGLE * FROM  SPFLI INTO SPFLI_WORKAREA
         WHERE  CARRID      = CARRID
         AND    CONNID      = CONNID.
  IF SY-SUBRC EQ 0.
    EX_SPFLI = SPFLI_WORKAREA.
  ELSE.
    MESSAGE E007 RAISING INVALID_DATA.
  ENDIF.
  SYS   = SY-SYSID.
ENDFUNCTION.
相关连接:http://blog.csdn.net/CompassButton/archive/2006/11/15/1385387.aspx

posted on 2006-11-16 13:35  毛小娃  阅读(138)  评论(0编辑  收藏  举报

导航