1. Importing APIs - SAP-samples/teched2022-AD265 GitHub Wiki

In this exercise, we will integrate the Business Partner Service from SAP S/4HANA Cloud into the Incidents Management application.

Browse SAP API Business Hub

SAP publishes service definitions for its major products on SAP API Business Hub. These service definitions are required to use remote services in CAP. For example, to call a remote service, build projections upon them, and to mesh-up with them.

To download the Business Partner API (A2X) from SAP S/4HANA Cloud, go to section API Resources, select API Specification, and download the EDMX file.

You need to log in first. Use your personal user. Accept the terms and conditions.

Import OData API

Open the download folder containing API_BUSINESS_PARTNER.edmx in Windows Explorer (or MacOS Finder etc.).

Drag and drop the API_BUSINESS_PARTNER.edmx file to the browser window onto folder incidents in the file tree of SAP Business Application Studio. Once you do that, you will see quite some changes in the terminal because of a cds import operation that was executed. If you scroll up in the terminal, you can see it:

[cds] - imported API to srv/external/API_BUSINESS_PARTNER.csn
> use it in your CDS models through the like of:

using { API_BUSINESS_PARTNER as external } from './external/API_BUSINESS_PARTNER';

[cds] - updated ./package.json

If the drag and drop operation didn't work, no worries: from the incidents folder, manually run

cds import API_BUSINESS_PARTNER.edmx

Behind the scenes, the import command has copied the EDMX file to the srv/external folder of your project and converted it to CAP's format CSN. This file is stored there as well (srv/external/API_BUSINESS_PARTNER.csn). It is this csn file that is relevant for CAP, the edmx is no longer used.

Additionally, the API_BUSINESS_PARTNER service is registered as service definition in package.json like this:

"cds": {
  "requires": {
    ...
    "API_BUSINESS_PARTNER": {
    "kind": "odata-v2",
    "model": "srv/external/API_BUSINESS_PARTNER"
  }
}

Service Adaptation

For the first version of the application, you need only a two fields from the A_BusinessPartner entity. To do this, you create a projection on the external service. Since in this example, you are interested in business partners in a role as customer, you use the name Customers for your projection.

Create a file srv/external/index.cds with this content:

using { API_BUSINESS_PARTNER as S4 } from './API_BUSINESS_PARTNER';

namespace s4.simple;

entity Customers as projection on S4.A_BusinessPartner {
  key BusinessPartner as ID,
  BusinessPartnerFullName as name
}

We store this s4.simple.Customers definition in the external folder to promote the idea that such a model could come from a third party, a partner or so. In a later exercise about prebuilt packages you will learn more about it.

Summary

Let's see how you can test the application in the next exercise.