Ms.S.Sudha Packiyam, SAP Integration Consultant, Smartsoft.
This document provides step-by-step instructions on how to integrate an external service with SAP’s Core Data Services (CDS). By following these guidelines, you will enable your CDS-based application to seamlessly interact with external services, enhancing its capabilities and extending its functionality.
Set-up the Connection between external service and CAPM Application
Step – 1: Download EDMX file from Accelerator Hub
- Go to SAP Business Accelerator Hub.
- Login with your SAP credentials.
- Navigate to “SAP S/4HANA Cloud Public Edition” under the “Products” section.
- Go to the “APIs” tab and select “ODATA V2” from the filter options.
- Search for “Business Partner” and select “Business Partner (A2X)” from the results.
- Download the EDMX file from the “API Specification” section under the API Resources.
Step – 2: Import the EDMX file into your CAPM Application
Place the downloaded EDMX file into the “srv/external” directory of your CAPM Application. If the “external” folder doesn’t exist, you’ll need to create it.
- Navigate to the root directory of your CAPM Application in your SAP BAS terminal.
- Use “cds import srv/external/<external API – edmx file>”, this command will generate :
- csn file in the srv/external.
- The necessary entries have been added under the “cds.requires” section. This should include the “kind” and “impl” fields for the external service.
- Then check “@sap-cloud-sdk/http-client and @sap-cloud-sdk/util” packages installed in your CAPM Application.
Step – 3: Configure the External Service URL
- Go back to the SAP Accelerator Hub and Copy the “API Key” from top right corner “Show API Key” button & sandox URL from “Configuration Details” under the API Resources.
Update the cds.requires.API_Business_Partner with sandbox URL and apikey.
Handling GET requests for Integrating OData Service with CDS in Sandbox Environment
Step – 1: Project the API_BUSINESS_PARTNER in service.cds
- Navigate to the ‘service.cds’ file under your ‘srv’ folder.
- You can use the following example, assuming that the main entity you want to expose is BusinessPartners.
Step – 2: Connect to the API_BUSINESS_PARTNER in service.js
- Open service.js file under your ‘srv’ folder.
- Use the ‘connect.to’ method to establish a connection to the ‘API_BUSINESS_PARTNER’ service.
- Modify the service.js file to include the following handler :
- Run your Application using ‘cds watch –profile sandbox’, then you got an output like this:
Handling PUT Requests for Integrating External Service with CDS using ‘send’ Method (only for deployment)
Step – 1: Connect the Cloud Connector
- Log into your Cloud Connector.
- Navigate to “Cloud to On-Premises”
- Create “Access Control” and also ensure that the resource path for your OData service is correctly specified then check that is ‘Reachable’.
Step – 2: Create a destination in SAP BTP Cockpit
- Go to the ‘Destination’ section under connectivity.
Create a destination and test the destination to ensure it is connected successfully.
Step – 3: Update package.json
- Ensure your ‘json’ includes the credentials for accessing the external service.
- If you encounter an ‘csrf missing error’, you can update your package.json file as follows.
Step – 4: PUT request to S/4HANA
- This sends a ‘PUT’ request with the updated ‘FirstName’ value for selected ‘BusinessPartner’.
- By using ‘method, path and data’, you can make any request like ‘PUT’, ‘POST’, ‘PATCH’ to S/4HANA as per your wish.
Conclusion
Integrating an external service with the SAP Cloud Application Programming Model (CAPM) allows you to enhance your applications by utilizing the comprehensive features of external systems like SAP S/4HANA. This guide has provided a step-by-step process to establish a seamless connection, configure your CAPM project, and handle PUT requests to update data on the external service.