Skip to Content

Updates

  • 26.11.2014
    • added SAP Note 2038379 as a prerequisite
    • added link to constraints
  • 23.02.2015
    • added information that as of SP7 SEGW should be used
    • added information that for SAP Fiori like scenarios that consume SAP HANA XS OData services a SAP Web Dispatcher or SAP API Management should be used

Constraints

Please be aware of the constraings listed in SAP Help.

OData Services Consumption and Integration – SAP NetWeaver Gateway Foundation (SAP_GWFND) – SAP Library

Overview

In this How-To Guide we want to describe how to consume the Odata sample service from  http://services.odata.org/ that supports read write access.

Since SAP NetWeaver Gateway does not support V3 of OData we will use the V2 version of this service. The service document of the V2 version is accessible via this link

http://services.odata.org/V2/(S(xuh52ptttgitgrkbtjzk1o31))/OData/OData.svc/

Though in this scenario the SAP Gateway Server acts like an OData proxy it is not the recommended way to use SAP Gateway to circumvent same origin policy issues that come up with scenarios where SAP Fiori like applications should consume data from OData service that are published via SAP Gateway and the SAP HANA XS engine. Instead the SAP Web Dispatcher or SAP API Management should be used.

Prerequisites:

  • This scenario has to be implemented on a Gateway Server where also the AddOn IW_BEP is deployed or on a Gateway Server running on SAP NetWeaver 7.40.
    The reason is that the Odata Lib that is part of the hub components is needed for consumption of the 3rd party OData service. This prerequisite is automatically fulfilled by a SAP Netweaver 7.40 SP2 and higher system since the software component SAP_GWFND contains the functionalities of IW_FND, GW_CORE and IW_BEP.
  • This scenario needs to run on SAP NetWeaver Gateway 2.0 SP6 or higher or SAP NetWeaver 7.40 SP2 or higher
  • You have to apply SAP Note 2038379

Let’s start with the configuration on SAP NetWeaver Gateway:

Step 1: Create an RFC destination

We first have to create a RFC destination of type G with the following technical settings:

Target Host: services.odata.org

In our example this RFC destination is called ODATAORG.

Please note that you might have to configure a proxy server.

01_RFC_Destination.PNG

Step 2: Create a System Alias

Now we have to create a System Alias that will be using the above created RFC destination. We call this System Alias OCI_NORTH and configure it such that the flags “Local GW” and “For Local App” are activated.

02_System_Alias.PNG

Step 3: Generate OData Service in SAP NetWeaver Gateway

Only on a SP6 system you have to run transaction /IWBEP/OCI_SRV_GEN.

On systems running on SP7 or later the integration into the SEGW has to be used instead.

Service Namespace = V2/(S(xuh52ptttgitgrkbtjzk1o31))/OData/

Service Name = OData.svc

and acitvate the check box “Configure Gateway Model and Service”.

Choose appropriate names for MPC, DPC, Model and Service and a package (here $TMP)

03_IWFND_OCI_SRV_GEN.PNG

This registers the service in the backend (which is identical with the hub system).

Step 5: Activate Service using /IWFND/MAINT_SERVICE

We register the service in the hub and choose the Technical Service Name ZOSCI_RW_TEST_SRV and register it for the System Alias OCI_NORTH.

04_IWFND_MAINT_SERVICE.PNG

Step 6: Test the service

We can now test the service using the Gateway Client /IWFND/GW_CLIENT. You can simply press the push button GATEWAY CLIENT in the Activate and Maintain Service transcation.

We enter the following URI in the Gateway Client

/sap/opu/odata/sap/ZOSCI_RW_TEST_SRV/Products(0)

and then press the push button “Use as request”.

05_GW_CLIENT_USE_AS_REQUEST.png

Now change the URI to

/sap/opu/odata/sap/ZOSCI_RW_TEST_SRV/Products

and the HTTP method to

POST

and change the values for

ID from “0” to “1000”

Name from “Bread” to “Toast”

and press Execute.

06_Entry_created.PNG

The HTTP status code 201 indicates that a new entry has been created in the collection “Products” and the created entry is shown in the HTTP response window.

You can now verify it also in a new browser window:

http://services.odata.org/V2/(S(xuh52ptttgitgrkbtjzk1o31))/OData/OData.svc/Products(1000)

07_Result_in_browser.PNG

To report this post you need to login first.

51 Comments

You must be Logged on to comment or reply to a post.

  1. Simon Kemp

    Hi Andre,

    This is a use case I hadn’t considered for Gateway before now. In essence in this scenario you are using NWGW as a proxy for another OData service (external service in this case). Can you elaborate on the sort of scenarios where we might encounter this “in the wild” (e.g. are there already customers using NWGW in this way)?

    Thanks for sharing,
    Simon

    (0) 
    1. Krishna Kishor Kammaje

      Hi Simon,

      This is what I can think off.

      I am an online video rental store with various audio/video titles in my store and has an ECC. I want to build a sales Mobile application which provides the current inventory as well as the rental rates to the renter.

      I would need a OData service providing these details from my ECC and in addition I would require generic details of the video title (like author, running length, related videos etc). In this case I can consume the Netflix OData service and enhance it to add rental rate and inventory details (from ECC) into that service and expose a single OData service for the mobile app developer to use. This would simple for the mobile app developer.

      Other option for the app developer would be to create an OData service only with inventory and rate details and the mobile app developer would have to combine/mash this service with the Netflix service at the client.

      Let me know what do you think of this use case

      Thanks

      Krishna

      (0) 
        1. Andre Fischer Post author

          Hi Simon,

          one use case is to consume OData services that are being published by SAP Hana.

          Using composition with other OData services developed in the SAP backend you can create a new service that would allow for a fast data retrieval using SAP Hana and read / write access to SAP Business Suite at the same time.

          Best Regards,

          Andre

          (0) 
  2. Chandrashekhar Mahajan

    Hi Andre,

    This is very useful information and Thanks for sharing it! I was always thinking how we can consume external oData services in NWGW and then combine it with other oData services to build UI mashup application.

    In my blog http://scn.sap.com/community/developer-center/front-end/blog/2013/08/02/creating-sapui5-applications-based-on-public-json-apis-or-web-services I am using public JSON APIs to build SAPUI5 application. Now I am thinking whether it is possible to consume these public APIs in NWGW and how we can leverage public API data along with business suite data.

    Again thanks for nice blog!

    Regards,

    Chandra

    (0) 
  3. Ron Sargeant

    I always found it a bit odd that there wasn’t any support for GW to read its own lingua franca, so it’s great that it has now arrived.

    Thanks for the blog

    Ron.

    (0) 
  4. Sreenivas Pachva

    Hi Andre,

    Excellent blog and it will be helpful for creating Gateway OData services from different backend systems like SAP and NON SAP..

    Could you please let me know, is it applicable(OSCI) for restful Web services ?

    Thanks

    Sreenivas Pachva

    (0) 
    1. Atanu Mallik

      I would suggest that, in RFC configuration you need to enter

      Target Host: test.corp

      Service No: 8001

      Path Prefix:/services/abc

      At this point do a connection test and ensure that it is successful. If you get ‘404 resource not found’ it is also fine.  

      Then in service builder wizard enter only service name which is ‘test123.xsodata’ and try it out..

      Regards,

      Atanu  

      (0) 
  5. TEST1 TEST

    Thanks Atanu for the response,

    In the RFC connection i gave the inputs as you mentioned now i am getting the below msg when i do a test connection.

    Status HTTP Response 303

    and was facing the same error in step 3 after entering the test123.xsodata  in Service Name:


    Error while fetching the source metadata.

    (0) 
    1. Atanu Mallik

      Could you please check once in debug, what is the URL being called. You can check it in class /IWFND/CL_OCI_HTTP_PROCESSOR method /IWFND/IF_OCI_HTTP_WRAPPER~GET.

      Please check the URL once

      Regards,

      Atanu

      (0) 
  6. TEST1 TEST

    Hi Atanu,

    Thanks a lot it is working fine..

    I have given the user and password details in RFC and then it is working as you mentioned and get the response as 404.

    Now i have created the service and trying to add it in transaction /IWFND/MAINT_SERVICE (Step 5) when i  double click on the service to add the service it is giving me short dump and when i checked the dump i found it is due to type mismatch at a function module which is called

    FM: /IWBEP/FM_MGW_GET_OBJ_MODELS

    Structure: /IWBEP/S_MESSAGE_CONTAINER_H

    Issue field : SAP_NOTE_ID

    i guess we have missed some components to install. can you let us know what are the required components to be installed for this to work.

    Till now we have installed the following components

    patch 8 for IW_BEP and

    patch 4 for IW_HDB

    and we are on SAP EHP 2 for SAP NetWeaver 7.0

    (0) 
    1. Atanu Mallik

      I do not think this is something specific to OSCI. If you register any other service you will encounter similar problem.

      I think there are notes to address this issue.

      (0) 
  7. Iwan Santoso

    Hi Andre,

    Do you have updated version for SP07? I could not pass the wizard due to error when handling the model class.

    /wp-content/uploads/2014/07/gateway_error_500408.png

    Thanks,

    Iwan

    (0) 
    1. Andre Fischer Post author

      Does your service name contain small letters and is your service case sensitive?

      There is a known issue with this wizard for these scenarios.

      Best Regards,

      Andre

      (0) 
      1. Iwan Santoso

        Andre,

        Thanks for your respond. I tried to use the same service in your document. I did found that the wizard is not case sensitive just as you mentioned. However, that’s half the issue i encountered.

        The URL is being called is services.odata.org/V2/OData/OData.svc/$metadata, which is working from web browser and in the method /IWFND/IF_OCI_HTTP_WRAPPER~GET of class /IWFND/CL_OCI_HTTP_PROCESSOR it returned Bad Request – Invalid URL (400)

        Then in debug mode I added ‘http://‘ so the url is http://services.odata.org/V2/OData/OData.svc/$metadata and that still has the same issue.

        I tried to include the

        I used services.odata.org S string as per your document and use V3 too eventhough you siad V3 is not supported, it’s the same result.

        I used service.odata.org/Northwind/Northwind.svc it has the same issue until i add the ‘http://‘. This completed step 3 as per your document. All green lights!

        Then during the service registration, I got the following message:

        Service ‘ZTST_CALL_01_SVC’ was created but its metadata could not be loaded.

        I’m guessing it relates to the ‘http://‘ issue during step 3, but not sure where I should add the http:// since I can’t do it in SM59.

        Do you have any idea on resolving this issue?

        Thanks,

        Iwan

        (0) 
        1. Imrankhan P

          Hi Iwan,

          Please check system alias in transaction IWFND/MAINT_SERVICE.This error usually come when we add in correct system alias.

          Regards,

          Imran.

          (0) 
          1. Iwan Santoso

            Hi Imran,

            Can you explain a little bit more? I setup the system alias the same way as per Andre mentioned in the article above.

            Regards,

            Iwan

            (0) 
      2. Iwan Santoso

        Nevermind ­čÖé I added implicit enhancement in CONSTRUCTOR Method of class /IWFND/CL_OCI_HTTP_PROCESSOR. I added this code at the end of the method:

        concatenate http://mv_target_host into mv_target_host.

        So at this point, the issue is only setting up via wizard for case sensitive OData service, since the wizard converted to upper case.

        Regards,

        Iwan

        (0) 
      3. W. Snoep

        hi Andre,

        Great blog, thanks a lot for sharing!

        Will there be a note / fix for the class: /IWFND/CL_OCI_HTTP_PROCESSOR. Regarding the missing ‘http://‘ in the ‘mv_target_host’ ? We ran into this issue when consuming an HANA xsodata service via SAP Gateway. It gives issues when loading metadata but also for reading of entities.

        We rather do not want to go the route of adding the ‘implicit enhancement as Iwan Santoso describes a bit further in this thread.

        Our current gateway version is SP7.

        Thanks!

        Wim

        (0) 
      4. Prabaharan Asokan

        Hi Andre,

          Thanks for the useful blog.

        I followed the steps described the blog and am receiving this error “Could not retrieve the model name and version” when trying to consume the above mentioned external REST service in gateway system(SAP NW 7.4).I am passing RFC destination, Service name in the SEGW tool wizard steps and started in debug mode. I found that in the below standard class RFC destination is getting retrieved as blank value.

        Class = >/IWFND/CL_OCI_REQ_PROCESSOR

        Method=>GET_SRC_METADATA

        Parameter IV_RFC_DESTINATION is null.


        So exception is raised as below snipped will get executed.


        IF iv_rfc_destination IS INITIAL .

        *–  Raise Exception –*

             lv_message  = /iwfnd/cl_oci_common_util=>create_message_key( iv_msgid = /iwfnd/if_oci_common=>gc_message_id  iv_msgno = ‘001’   ) .

             RAISE EXCEPTION TYPE /iwfnd/cx_mgw_tech_exception

               EXPORTING

                 textid = lv_message.

           ENDIF .


        Message class : /IWFND/OCI_MSG

        Error: Enter an RFC Destination


        Gateway service builder didnt pick up the RFC destination passed via the wizard

        Could you give some insights on this error?


        Your help is appreciated.


        Regards

        Prabaharan

        (0) 
  8. Imrankhan P

    Hi Atanu,

    /sap/opu/odata/sap/test/test_parameters(IP_VENDOR=’*’,In_PO_Type=’*’,In_Days=300,In_SCB_Doc_Type=’ZRC1′,’ZRC2′,In_PR_Doc_Type=’*’,In_Hub=’*’,In_Transit_Doc_Type=’*’)/Results?$top=1&$format=xml

    Here in the URL, we are passing two inputs to the same parameter (marked in yellow) and it is giving the following error.


    Thanks in Advance. Kindly help us.

    Image.png

    (0) 
  9. Sagar Joshi

    Has anyone figured out authentication aspects of such ODATA Consumption?

    Is it possible to use named user and OAUTH for consuming the ODATA using OSCI?

    (0) 
  10. Nikolaus Harrich

    Thanks for the Guide.

    At first i want to say i ran into a problem with sm59 and /IWBEP/OCI_SRV_GEN. I had to das the Perfix for the link in sm59 and leave it out in /IWBEP/OCI_SRV_GEN. If i didn’t do that, i’ll get the error “problem while fetching meta data”.

    Now i got a problem at step 6. The Get part is working, will get the entry “Bread”. But when i try to post the new entry, ill run into a 500 error.

    But i cant find the error, may you experts have a look at this:

    <?xml version=”1.0″ encoding=”utf-8″ ?>

    <error xmlns=”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata>

    <code>SY/530</code>

    <message xml:lang=”en>Create Entity failed: 3C68746D6C3E3C686561643E3C7469746C653E4F626A656374206D6F7665643C2F7469746C653E3C2F686561643E3C626F64793E0D0A3C68323E4F626A656374206D6F76656420746F203C6120687265663D222F56322F2853287571356171797061356C6864626A6E7877786363356D746729292F56322F4F446174612F4F446174612E7376632F50726F6475637473223E686572653C2F613E2E3C2F68323E0D0A3C2F626F64793E3C2F68746D6C3E0D0A.</message>

    <innererror>

    <transactionid>A8F29FE456F9F14193EE005056890FEC</transactionid>

    <timestamp>20150119160019.6300000</timestamp>

    <Error_Resolution>

    <SAP_Transaction>Run transaction /IWFND/ERROR_LOG on SAP NW Gateway hub system and search for entries with the timestamp above for more details</SAP_Transaction>

    <SAP_Note>See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)</SAP_Note>

    </Error_Resolution>

    <errordetails>

    <errordetail>

    <code>/IWBEP/CX_OCI_TECH_EXCEPTION</code>

    <message>Create Entity failed: 3C68746D6C3E3C686561643E3C7469746C653E4F626A656374206D6F7665643C2F7469746C653E3C2F686561643E3C626F64793E0D0A3C68323E4F626A656374206D6F76656420746F203C6120687265663D222F56322F2853287571356171797061356C6864626A6E7877786363356D746729292F56322F4F446174612F4F446174612E7376632F50726F6475637473223E686572653C2F613E2E3C2F68323E0D0A3C2F626F64793E3C2F68746D6C3E0D0A.</message>

    <propertyref />

    <severity>error</severity>

    </errordetail>

    </errordetails>

    </innererror>

    </error>


    Br,

    Nikolaus



    (0) 
  11. Nikolaus Harrich

    Hello again,

    Now i come back with an other question.

    I want to use the data from the URI in a zprogram.

    How can i achieve that? How can i use the classes in ABAP.

    Let assume i want to write a report where i to print all of the items thati get from the odata stream.

    Please provide an example if you got one.

    Thansk in advance and best regards,

    Nikolaus

    (0) 
    1. Atanu Mallik

      If the requirement is just to call the URL and get the response in the ABAP program then 

      you can directly use cl_http_client.

      OSCI is for OData consumption.

      (0) 
      1. Roland Spindler

        I have the same problem. If I use cl_http_client, I have to parse the XML-result myself.

        Isn’t the point of generating the ABAP classes to have a nice API (including methods like “get_entity”) without having to care about the underlying XML?

        Roland

        (0) 
    2. Hadrien Paquet

      Hello All,

       

      I have exaclty the same requirement.  How can I then use the differents classes generated in a Zprogram ?

       

      Did you had any way for doing this ?

      thank You

      Hadrien

      (0) 
    3. Dirk Riedel

      You can generate proxy classes for the external ODATA service by using transaction SECATT_ODATA.

      For each entity one class is generated. They can easily be used in order to consume the external ODATA service.

      Regards,

      Thomas

      (0) 
  12. Stephan Ro├čbach

    Hello,

    I tried to follow this tutorial, but I’m stucking unexpected. Step 4 seems not to register the service; I must add it manually, and trying it, I get the error message: “No Model assigned to Service ‘<Servicename>’; assign Model first”.

    Did anyone of you encounter the same problem, and can provide me with a hint on that?

    Thanks in advance,

    Stephan

    (0) 
    1. Nikolaus Harrich

      Get back to step 1 und use the path prefix V2 and at Step4 leave the V2 out in the Service Namespace. Then try again to create the classes.

      Br,

      Nikolaus

      (0) 
      1. Stephan Ro├čbach

        Thx Nikolaus,

        I retried it, yet it doesn’t solve the problem. Funnily, the generation protocols says, that the newly generated service is successfully assigned to the model instance.

        Best regards, Stephan

        (0) 
  13. Iwan Santoso

    I’ve setup the read write service but in 3, it fails to load metadata. I looked at the URL and when I open the url in a browser, it is fine, but when I check the get method, it return 500 value. Is there anything extra I have to do for read write service?

    If I remove (S(xuh… string (read only service), it works fine all the way to testing via gateway client.

    Regards,

    Iwan

    (0) 
    1. Joseph BERTHE

      Hello,

      For the metadata problem you have to set the prefix in the SM59

      And in the /IWBEP/OCI_SRV_GEN set the Service Namespace as blank.

      It sould work ­čśë

       

      Regards

      (0) 
  14. Junaid Hussain

    Hi,

    I have configured xsOdata with Gateway. I am able to do create and get. When i try to do a batch request I get blank response with 202 success message. What could be the issue

    (0) 
  15. Amit Kumar Singh

    @Andre Fischer

    Thanks for the great blog post.

    I want to ask here what if at design time the structure of requested resource from external web service is not known, so what would be approach to consume it.

    Also can you let me know the ABAP APIs to invoke external web service consumed in this case?

    Thanks for your help.

     

    (0) 
  16. Dirk Riedel

    Hi,

    1. why are the Model and Data Provider class empty in the sense that they inherit everything and don’t redefine anything? They are also not used when testing via client. Are they useless?

    2. Why is it not possible to use this service from within ABAP without going back to the XML document. Currently I only see disadvantages compared to SOAP.

    Thanks and regards,

    Thomas

     

    (0) 

Leave a Reply