cancel
Showing results for 
Search instead for 
Did you mean: 

Consume on-premise Odata service from CAPM project

SaranyaSampath
Participant
0 Kudos

Hi,

In my CAPM application I am accessing HANA cloud tables and its working fine, as well I have to consume S4 HANA on premise Odata service.

Kindly suggest how to access on-premise s4 system from CAPM app

Thanks and regards

Saranya

View Entire Topic
ibibhu
Product and Topic Expert
Product and Topic Expert

To consume an S4 HANA on-premise OData service in your CAP application, you will need to perform the following steps: 1.Configure the destination in your Cloud Foundry environment that points to your S4 HANA on-premise system. 2.Use the destination in your CAP application to create a service instance that connects to the OData service. 3.Use the service instance to call the OData service and retrieve data. 4.Use the data in your CAP application as needed. You can use the npm package @sap/cds-odata-v2-adapter-proxy to create a proxy between your CAP Application and the S4 HANA on premise system. This package is a standard adapter that allows to connect to OData services of the SAP S/4HANA on-premise system. It's also important to note that you may need to configure appropriate authentication and authorization mechanisms to access the OData service, depending on your specific setup.

const cds = require('@sap/cds');
const proxy = require('@sap/cds-odata-v2-adapter-proxy');

// Create a new cds.Server
const server = new cds.Server();

// Define the data model
const db = cds.db;
const { BusinessPartner } = cds.entities;

// Define the OData service
server.on('odata', proxy({
    model: db,
    target: '<your S4 HANA on-premise system URL>',
    credentials: {
        user: '<your username>',
        password: '<your password>'
    },
    services: {
        'BusinessPartner': ['BusinessPartner']
    }
}));

// Start the server
server.listen();

This example creates a new cds.Server, defines the data model and the OData service, and starts the server.
You can replace the <your S4 HANA on-premise system URL>, <your username>, and <your password> placeholders with the appropriate values for your system.You can test this service by running the following command and see the json response on browser or postman :curl http://localhost:4004/odata/BusinessPartnerPlease note that this is just a basic example and you may need to add additional code to handle authentication and authorization, error handling, and other requirements specific to your application.
Khabir-Raja
Discoverer
0 Kudos

Hi ibibhu, there is another similar npm package @cap-js-community/odata-v2-adapter  https://cap.cloud.sap/docs/advanced/odata#odata-v2-proxy-node

What are the differences? I want to use OData v2 for my Fiori Element UI in CAP. Default is v4 for CAP Fiori UI. But the problem is that OData annotation from OnPremise System is not interpreted precisely to Fiori Elements if the UI is built on v4.