Synchronous call RFC example
*&---------------------------------------------------------------------*
* & Report sapbc1__rfcsync_s1 *
*&*
*&---------------------------------------------------------------------*
Report sapbc1__rfcsync_s1 message-ID bc1.
Tables spfli.
Parameters: icarr like SFLIGHT-CARRID default 'lh ',
Iconn like SFLIGHT-CONNID default '20140901 ',
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.
Example of asynchronous call to RFC
*&---------------------------------------------------------------------*
*&*
* & Report sapbc1__rfcasync_s1 *
*&*
*&---------------------------------------------------------------------*
Report sapbc1__rfcasync_s1 message-ID bc1.
Tables spfli.
Parameters: icarr like SFLIGHT-CARRID default 'lh ',
Iconn like SFLIGHT-CONNID default '20140901 ',
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'
Asynchronous 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 prototype
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.
Related connection: http://blog.csdn.net/CompassButton/archive/2006/11/15/1385387.aspx