When it comes to exposing the data to outside world this is easily done by OData service.
In SAP we
have numerous RFC’s and BAPI’s available in several functional areas to get the data. Here we are
creating an OData service based on a table structure.
Create an OData Service in SAP ECC - Gateway
Step 1 – SAP Netweaver Gateway Service Builder
First go to transaction SEGW where you will be able to build your service
Step 2 – Create project
Next using the create button you have to create a project to store all your data models, implementations,
entity types, entity sets etc. Don't worry too much about the terminology at this stage, all will become
clear.
Step 3 – Enter project details
Enter a name, description and package. Leave everything else as default unless you know you need
something specific.
Step 4 – Import DDIC structure
We are going to base this example on a subset of the standard SAP table EKKO. Within the newly created
project, right click on the "Data Model" node and select Import->DDIC Structure
Enter EKKO within the ABAP structure field and enter an object a name i.e. PurchaseOrder
We are just going to use the top few fields
Entity Type and Entity Set are created.
Save and generate runtime objects.
Step 5 - Register the service
Double click on Service Maintenance tab. Register the service
Service is registered successfully.
Step 6 Test the service
Go to SAP Gateway Client and test the service
/sap/opu/odata/SAP/ZTEST_CPI_PURCHASEORDERS_SRV/PurchaseOrderSet?sap-ds-debug=true
Now change the URI to have "/purchaseOrderSet?sap-ds-debug=true" at the end so that we can target the
data of the entity set PurchaseOrders
When you press execute you should get the following error as we have not implemented the method that
populates this data yet
Implement “GetEntitySet”method
Now return to the SEGW transaction and find the service implementation methods created before. Find
the one called GetEntitySet(Query) and right click on it. Then select "Go to ABAP Workbench"
You will now be taken to tcode SE80. Within the object list on the left find the
PURCHASEORDERSET_GET_ENTITYSET method within Methods->Inherited Methods.
Once you have found this, right click on it and select Redefine
Within the method code that appears simply add the following ABAP select statement
Save and activate.
Now test the service using the URI
/sap/opu/odata/SAP/ZTEST_CPI_PURCHASEORDERS_SRV/PurchaseOrderSet?sap-ds-debug=true
You should get some data returned as shown below.
ODATA URI for getting Entity Set:
[Link]
Expose the SAP Gateway service as OData API in CPI
SAP Cloud Platform Integration helps you import a model definition from an OData service, which is
created on an on-premise SAP Gateway system. SAP Gateway has a component called Backend
Provisioning Component or IW_BEP. This component resides on SAP Business Suite and is used to build
OData services from data sources like RFCs, BAPIs, and so on. SAP Cloud Platform
Integration communicates with the IW_BEP component in SAP Gateway through OData Channel or
ODC protocol, which is an SAP proprietary protocol.
You can use this procedure to create an OData model or build up an existing one by importing the model
definition from an OData service created in IW_BEP (ODC).
Choose an existing package / create a new package
Edit the package and add an OData service
Specify the name and namespace. Default namespace is SAP
Go into the ODats service aftifact and edit it,
Click on Import Model Wizard
Import Wizard opens
Select Data Source type. Here we can select either ODATA/ ODC to import service from SAP Backend
In the Select Data Source Type page, select ODC as data source type.
Enter the connection details as listed in the following table.
Connection Description
Details
Address Endpoint URI of the target system
Client Client of the target system
Connection Description
Details
Namespace Logical grouping of the service implementation
Service Name Name of the service implementation
Version Version of the service implementation
Proxy Type The type of proxy that you are using to connect to the target system:
Select On-Premise if you are connecting to an on-premise system using the SAP
Cloud Connector.
This option is only available if you have chosen SAP Cloud Platform Integration as
the product profile.
If you select this option, the Address field of the adapter refers to a virtual address
that has to be configured in the SAP Cloud Connector settings.
Authentication Select Basic if you want to use user credentials to connect to the target system.
Credential Name Name of the user credentials artifact deployed on the tenant
If we are using ODATA as data source, import the EDMX file of the OData service from File system.
In step 2, select the fields needed
In step 3, review and finish
In the created set, click on Binding and add mapping
An integration flow is automatically created for the operation for which we did the binding
We can modify the script and mappings according to our requirements
Save and deploy the OData artifact
Go to Operations View. Select the OData Artifact from “Manage Integration Content” tile
Copy the endpoint and call it from a browser.
[Link]
[Link]/gw/odata/SAP/TG_ODATASERVICE_EXPOSINGBAC
KENDSERVICE;v=1
You will get the Entity Set information
You need to configure the OData Artifact for other operations as well, as per your needs
Integrate the OData service created in Gateway using SAP CPI
Instead of exposing the back end OData service as OData API in CPI, we can directly integrate the
Gateway service using an OData receiver channel, by creating an Integration flow.
Create a new package / select an existing package
Go to Design tab in CPI tenant and Edit /Create a package
Add an integration flow to the package
Give a name to the iFLow and save it.
Select the iFlow and edit it
We will use an HTTP service to send data to CPI.
Connect the Sender to Send Message event and select HTTPS as the adapter
Configure the HTTPS channel to have a unique endpoint.
Add a Content Modifier to the iFlow.
We are adding 2 properties in Content Modifier to fetch the Values from the incoming XML message
Connect the End Message event to Receiver component
Select OData as the adapter type
Configure the OData channel
Give the OData service root URL as address. If you are selecting ON-Premise as Proxy type, you need to
give the Virtual host and port configured in cloud connector
Select Entity set name and Fields
Save and deploy the iFlow
Go to Operation View and select the deployed iFlow artifact from “Manage Integration Content” tile
Copy the Endpoint
[Link]
We are using postman tool to test the iFlow
Send the message from Postman as shown below
We are using the sample XML given below
<?xml version="1.0" encoding="UTF-8"?>
<GetPurchaseOrderDetails >
<Mandt>100</Mandt>
<Ebeln>4500000000</Ebeln>
</GetPurchaseOrderDetails>
We got the response back from OData API in the SAP Gateway
Go to Message Processing tab in Operation view of CPI tenant
We can see the successfully processed message as shown above.