How to consume an OData service using OData Services Consumption and Integration (OSCI)
- added SAP Note 2038379 as a prerequisite
- added link to constraints
- 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
- added new recommendation to use SAP Web Dispatcher as a proxy instead of SAP Gateway
Recommendation: Use SAP Web Dispatcher
In the scenario described in this article SAP Gateway is used as an OData proxy for an external OData Service.
The main reason why customers asked for such a scenario was that they wanted to use the SAP Gateway Hub as the single point of entry for the consumption of OData services, so that a SAP Fiori App that is deployed on a SAP Fiori Frontend Server can consume OData Services from just one location.
The same result but with a much cleaner technical approach can be achieved by using the SAP Web Dispatcher as described in the following Wiki page (sectionConfiguring WDP for Fiori s4HANA Applications )
As you can see from the numerous questions and comments to this post you can see that this does not work well. In addition to the technical constraints (see below) also performance should be considered. So Web Dispatcher is your best friend.
Please be aware of the constraings listed in SAP Help.
OData Services Consumption and Integration – SAP NetWeaver Gateway Foundation (SAP_GWFND) – SAP Library
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
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.
- 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.
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.
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)
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.
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
and then press the push button “Use as request”.
Now change the URI to
and the HTTP method to
and change the values for
ID from “0” to “1000”
Name from “Bread” to “Toast”
and press Execute.
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:
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,
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
That sounds cool, like a sort of OData Mashup 😎 .
Thanks for sharing.
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.
Excellent blog. This will help developers and business to value position oData and SAP Gateway.
Thanks Andre to put this together.
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!
very interesting blog 🙂
Do you know more hidden functions ?
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
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 ?
We have a requirement to create a gateway service to consume HANA ODATA service and our url look like below...
In Step 3: can you please let us know what details we should provide for service Namespace and service name.
we are getting the error in this step as shown.
Error while fetching the source metadata.
I would suggest that, in RFC configuration you need to enter
Target Host: test.corp
Service No: 8001
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..
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.
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
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
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
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.
nice blog 🙂
Do you have updated version for SP07? I could not pass the wizard due to error when handling the model class.
Does your service name contain small letters and is your service case sensitive?
There is a known issue with this wizard for these scenarios.
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?
Please check system alias in transaction IWFND/MAINT_SERVICE.This error usually come when we add in correct system alias.
Can you explain a little bit more? I setup the system alias the same way as per Andre mentioned in the article above.
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.
Have you found a solution for the case sensitive problem? I'm in the same situation as u were.
Hi Dominik, sorry for late reply. just have a chance to revisit this blog. I think OSS note 2038379 should fixed that issue .
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.
W. Snoep, not sure if it still relevant. I'm at SP9 and the http:// issue still there.
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
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
textid = lv_message.
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.
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.
You can not pass two values for a key field, use filter instead
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?
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" ?>
one possible reason of error may be the the framework could not parse the payload. Check the payload that you are using for post.
Getting the same error here, did you manage to fix it?
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,
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.
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?
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 ?
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.
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,
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.
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
I just came out of this same error.
I had forgotten to maintain the HTTP RFC destination in the system alias with which I am registering the service.
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.
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 😉
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
I have netveawer gateway SP13. While I'm trying to create the service I'm getting following dump. Is anyone familiar with this dump.
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.
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,
Hi, I tried to execute the PUT method but got an error. Can you please help me? Thank you
Why aren't you using a web dispatcher and access the OData ressource directly?
The OSCI integration has limited functionality and will not developed any further.
I have studied your blog for some time looking for the best approach to consume an external ODATA service from a Fiori App but also make it available in the SAP Gateway, for ABAP internal consults.
OSCI integration was my first approach, but you say here that could be better to use a Web Dispatcher and consume the ODATA directly? Where can I find more info on this, do you know?
If that is the case, just adding the destination to the SAP Cloud Cockpit wouldn't suffice?
In my case I need to provide the ODATA to a Fiori App and also create a way for ABAP programs to access it? Can this be done with the Dispatcher or OSCI should be better? I would appreciate any advice, I'm an ABAP developer and UI5 enthusiast and this is the first time that I'm required to connect to 3rd party ODATA.
neither OSCI nor the Web Dispatcher approach are suitable for a programmatic approach to access a third party OData service.
For this you would have to write code yourself.
What might be helpful is the following tool:
Though it is meant to help you to test OData services you can take the generated classes and use them in your own OData service.
I am trying to develop Fiori application using Fiori template ( OV page and ALP) with HANA xsodata as datasource and take web dispatcher approach . Fiori template require higher UI5 runtime version more that 1.38. I have XS Classic that has UI5 Runtime version of 1.28 and to get to higher runtime I have no other way but to go on XS Advance, XSA migration and higher versions of hana DB and it make web-dispatcher approach more complicated.
Will this OSCI approach help me to use my xs classic xsodata and deploy fiori template based fiori applications on gateway ?
the Web Dispatcher Scenario should enable you to deploy the app on SAP Gateway (thereby leveraging an up to date SAP UI5 library) and call an OData Service published via an xs classic engine.
The Web Dispatcher would then take care of redirecting the OData calls to the xs engine.
Is this procedure valid also for consuming HANA XS OData services exposed by using SAP Cloud Platform?
I can't really recommend using this integration scenario since it has lots of technical restrictions and I do not see why would want to use it to consume HANA XS OData services.
I would rather use a web dispatcher instead.
We have requirement from our external team to expose the data from SAP ECC to PowerBI via ODATA service. Could you please provide me any document and the procedure to follow for this work.
we are facing issue while registering External OData service via /IWBEP/OCI_SRV_GEN . we have
created RFC Destination of type G and maintained host name and port name in the destination.
we are getting Error while fetching Metadata Error while at the odata generation step.
we have followed below Document for consuming the external odata service.
Can someone please help us in removing this error .
You should use SAP Web Dispatcher for your scenario. See my updates in this blog post.
Can you please share some document which has steps to configure this scenario via SAP web Dispatcher?
I went through the blog but couldn't find any document for the same.
It was a Wiki page I am referring to above, not a blog and this Wiki page is full of links describing how to configure SAP Web Dispatcher.
Hi Andre Fischer
We have tried using the OSCI approach for C4C Odata services, but it fails on the /IWFND/MAINT_SERVICE step due to (apparently) naming issues.
Would the SAP Web Dispatcher work in this case? (Proxying calls from an on-premise GW to C4C in the cloud?)
Hi Andre Fischer, All
We have a similar requirement and we are in SP09. We followed the same process and able to register the service based of XSODATA.
During the testing via Gateway client we are able to retrieve the metadata correctly.. But when we execute the entity set we are getting 'Unable to perform Query operation :Format application/atom+xml;type=feed not support'. We have passed "?$format=json" in the request string and tried but still getting the same error. We even tried to change the request header Content-Type to application/json but still no luck.
Could please advice if any additional logic/setting needs to do in XSODATA side or Gateway side?
As I wrote above my recommendation is not to use SAP Gateway just for the sole requirement to act as a proxy for another OData service.
Wouldn't it be possible to use the Web Dispatcher instead?
My requirement is retrieving an external ODATA service as everyone in here. Let me explain my RFC configuration at first;
Path Prefix: /api/outbound/odata/v1/com.app.gttft1.gttft1Service
Also, I created a service with a empty namespace and service name successfully.
At the end of the day, I am able to retrieve metadata and entity list from this service when I debug in /IWFND/CL_OCI_REQ_PROCESSOR class.
But during adding service in TX: /iwfnd/maint_service I receive an error as below.
What would you suggest in order to skip this step without error? Which step do I mistake?
Thanks in advance.
What is the basis release you are working on?
740, 750, 751, 752 or newer?
And what do you mean by "...requirement is retrieving an external ODATA service ".
When you want to consume an OData service that seems to reside in the Cloud I am wondering what the benefit it is to use an on premise based SAP Gateway as a proxy ?
Why aren't you consuming the service directly ?
Basis release: 755.
The product is running on the Cloud and provides ODATA service. But customer wants a generic custom Fiori application that is embedded in SAP Gateway Launchpad with other TM applications.
When I consume the service directly and push the Cloud, there is already no problem, it is working. If it is there any way to consume the service directly in SAP Gateway, it also works for me.