RFC to Webservices Sap Technical

download RFC to Webservices Sap Technical

of 12

Transcript of RFC to Webservices Sap Technical

  • 8/10/2019 RFC to Webservices Sap Technical

    1/12

    RFC-to-Web Service Scenario

    by Neeraja

    This document describes how the Custom RFC client application in SAP R/3 System invokes a free

    Web service (that is hosted over the internet) using SAP XI. For our demo purpose, we have used afree web service available on the Internet. Details for the same are provided in the next section.

    About the web service:

    In this example scenario we will be using GetQuote method of Web service DelayedStockQuote.This method retrieves the Stock quote for the given S tock symbol. The method GetQuote has aninput that takes in two parameters Stock Symbol and License Key and returns the followinginformation.

    StockSymbol,

    LastTradeAmount,

    LastTradeDateTime, StockChange,

    OpenAmount,

    DayHigh,

    DayLow,

    StockVolume,

    PrevCls,

    ChangePercent,

    FiftyTwoWeekRange,

    EarnPerShare,

    PE,

    CompanyName.

    Link to webservice:

    http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?op=GetQuote

    WSDL of the webservice:

    http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDL

    Download WSDL from the above link.

    1. Configurations at the Sender System (SAP R/3)

    1.1 Create RFC destination:To create the RFC go to TCODE: SM59

    Create new destination of type T (TCP/IP)Make sure you select Registered Server Program option before writing your program IDWrite your program ID (remember it's case-sensitive)In the gateway host and gateway service write the values of your "Application system" -

    business system (R/3 System)

    http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?op=GetQuotehttp://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?op=GetQuotehttp://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDLhttp://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDLhttp://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDLhttp://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?op=GetQuote
  • 8/10/2019 RFC to Webservices Sap Technical

    2/12

    1.2 Create Remote function module

    Create Remote Function module in R/3 system with the following parameters.

    Import:

    Export:

  • 8/10/2019 RFC to Webservices Sap Technical

    3/12

    Sourcecode:

    1.3 Create Report Program

  • 8/10/2019 RFC to Webservices Sap Technical

    4/12

    Create a report program in the R/3 system which makes Synchronous call of a remote-enabledfunction module ZN_GET_QUOTE.

    Code snippet

    REPORT ZTEST_WEBSERVICE.

    parameters: p_stsym(30).

    data:StockSymbol type char30,LastTradeAmount type char30,LastTradeDateTime type char30,StockChange type char30,OpenAmount type char30,DayHigh type char30,DayLow type char30,StockVolume type char30,PrevCls type char30,EarnPerShare type char30,companyname type char30,QuoteError type char30.

    CALL FUNCTION 'ZN_GET_QUOTE' destination 'RFC'EXPORTING ST_SYM = p_stsym LKEY = '0' IMPORTINGStockSymbol = StockSymbolLastTradeAmount = LastTradeAmountStockChange = StockChangeOpenAmount = OpenAmountDayHigh = DayHighDayLow = DayLowStockVolume = StockVolumePrevCls = PrevClsEarnPerShare = EarnPerSharecompanyname = companyname

    QUOTEERROR = QuoteError.

    if quoteerror NE 'true' and quoteerror NE 'TRUE'.write:/'StockSymbol:',StockSymbol,/'LastTradeAmount:',LastTradeAmount,/'LastTradeDateTime:',LastTradeDateTime,/'StockChange:',StockChange,/'OpenAmount:',OpenAmount,/'DayHigh:',DayHigh,/'DayLow:',DayLow,/'StockVolume:',StockVolume ,/'PrevCls:',PrevCls,/'EarnPerShare:',EarnPerShare,/'companyname:',companyname,/'QuoteError:',QuoteError.else.write:/ 'Invalid Stock symbol'.endif.

    2. Configurations in the Integration Repository

    2.1 Import the WSDL:

  • 8/10/2019 RFC to Webservices Sap Technical

    5/12

    Import the WSDL of the webservice as an External Definition; these structures are needed as weneed to accomplish the mapping between the RFC.Request to SOAP.Request and SOAP Responseto RFC Response.

    Note: Usually when we import the WSDL as an External Definition, we get the relevant messages forthe request and response structures along with it.

    2.2 Import RFC

  • 8/10/2019 RFC to Webservices Sap Technical

    6/12

    Import the RFC ZN_GET_QUOTE created in the previous step from R/3 system.

    Note: Usually when we import the RFC from R/3 system, we get the relevant messages for therequest and response structures along with it.

    2.3 Define Message Interface

    As imported WSDL and RFC messages can be used as Data types, Message types and outboundmessage interface we dont require creating those.

    Define inbound synchronous message Interface

    2.4 Create Message Mappings

  • 8/10/2019 RFC to Webservices Sap Technical

    7/12

    Here we need to create two mappings, first between RFC Request (ZN_GET_QUOTE.Request) toSOAP Request (GetQuoteSoapIn) and second between SOAP Response (GetQuoteSoapOut) toRFC Response (ZN_GET_QUOTE.Response).

    2.5 Define Interface Mapping

    Define Interface mapping for the above created mappings.

  • 8/10/2019 RFC to Webservices Sap Technical

    8/12

    Request mapping

    Response mapping

    Continued...

    3. Configurations in the Integration Directory

    3.1 Create sender communication channel

    http://www.saptechnical.com/Tutorials/XI/RFC2WebService/Page3.htmhttp://www.saptechnical.com/Tutorials/XI/RFC2WebService/Page3.htmhttp://www.saptechnical.com/Tutorials/XI/RFC2WebService/Page3.htm
  • 8/10/2019 RFC to Webservices Sap Technical

    9/12

    Create Sender Communication channel (RFC adapter) under the Sender Business system

    Make sure the Program id specified here and the Program id specified in the RFC destination createdabove are same.

    3.2 Create receiver communication channel

    Create Receiver communication channel (SOAP adapter) under the Receiver business service.

  • 8/10/2019 RFC to Webservices Sap Technical

    10/12

    We need to specify the following in the SOAP adapter;

    1. Target Url:http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDL

    2. Configure Proxy:If your network has a proxy setup you need to provide the details of the same.3. Configure proxy User Authentication:to be specified in case.

    4. SOAP Action:we can find out the SOAP Action for the GetQuote method of the WebserviceDelayedStockQuote in WSDL.

    3.3 Create Sender Agreement

    Sender adapter in the sender agreement converts the message into XML format

    3.4 Create Receiver Agreement

    Receiver Agreement defines to which receiver the message, has to be routed.

    http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDLhttp://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDLhttp://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDLhttp://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?WSDL
  • 8/10/2019 RFC to Webservices Sap Technical

    11/12

    3.6 Create Interface Determination

    Interface Determination identifies the Mapping between the sender interface and Receiver interface.

    3.5 Create Receiver Determination

    Receiver Determination defines the possible receivers for a sender and an outbound interfacecombination.

  • 8/10/2019 RFC to Webservices Sap Technical

    12/12

    4. Testing the Scenario

    In the Sender R/3 system Execute the Report program we have created earlier. When the program isexecuted with Stock symbol it should get the details of that stock symbol from the Webservice.

    Below is the screenshot of the output we got when the program is executed with the StockSymbol R