Sub topic 2
Released APIs and stable contracts
This chapter assumes you know what clean core means and why upgrades are the motivation for it. It also assumes you are comfortable with OData and REST, and that you can read short Node.js examples. Here you learn what makes an API "released", how to find one, and how a side-by-side extension on SAP BTP depends on it.
What a stable contract means
An API is a contract. The provider promises that names, types, semantics and behavior stay the same, or change only in ways that do not break consumers. SAP S/4HANA contains thousands of internal objects, such as tables, function modules, CDS views and classes. Almost none of them carry that promise. SAP can rename a table, split a view or remove a field in any release, because only SAP code is supposed to use it.
A released API is an object that SAP has explicitly published for use by customers and partners. SAP commits to keeping it compatible, or to announcing changes ahead of time through a defined lifecycle.
Clean core relies on this distinction. If your extension touches only released objects, SAP can upgrade the core without breaking you. If it touches unreleased objects, every upgrade is a risk you must test for yourself.
Release states and contracts
Each released object has a release state:
| State | Meaning | What you should do |
|---|---|---|
| Released | Stable and supported for the stated use | Use it |
| Deprecated | Still works, but a successor exists | Plan the migration |
| Decommissioned | Removed or no longer supported | Must already be migrated |
| Not released | Internal to SAP | Do not use it from extensions |
An object is not simply "released" in general. It is released for a specific kind of use, and SAP expresses this with release contracts. Two matter most for this tutorial:
- C1 (use system-internally) allows ABAP Cloud code running inside the S/4HANA system to use the object. Developer extensibility depends on it.
- C2 (use as remote API) allows consumers outside the system to call the object over the network. Side-by-side extensions depend on it.
An object can carry both contracts, or only one. A class released with C1 can be used by your ABAP Cloud code, but that does not make it callable from SAP BTP. Always check the contract that matches how you plan to consume the object.
Where released APIs are published
For side-by-side work you usually find APIs in these places:
- SAP Business Accelerator Hub (api.sap.com). It lists OData, SOAP and event interfaces per product, with the EDMX or OpenAPI specification you can download. Pick the entry for your product edition. SAP S/4HANA Cloud Public Edition, Private Edition and on-premise do not always expose identical sets or versions.
- The system itself. Communication scenarios and communication arrangements in S/4HANA Cloud tell you which APIs are exposed for integration, and they are the objects that grant access. In ABAP Development Tools you can inspect the API state of a single object in its properties.
- The Cloudification Repository. SAP publishes a machine-readable list of objects with their release states and successors. Tools and ABAP test checks use it to flag unreleased usage.
The Business Partner service used later in this chapter is API_BUSINESS_PARTNER. It is a released OData V2 API, and you can find it on the Business Accelerator Hub.
How a side-by-side extension depends on the contract
The diagram shows the dependency chain. Your extension code binds only to the downloaded API specification. The destination handles host and credentials, and SAP S/4HANA implements the contract behind it.
The dotted line is the rule. Everything inside the core stays hidden behind the API. SAP can change the internals freely as long as the API behaves as published.
Registering the released API in CAP
Start by downloading the EDMX specification from the Business Accelerator Hub and importing it into your CAP project:
cds import ./API_BUSINESS_PARTNER.edmx --as cdsThis generates a CDS model under srv/external/ that mirrors the API contract. It also registers the service in your project configuration. The result looks like the following fragment, here with a destination name and path added:
{
"cds": {
"requires": {
"API_BUSINESS_PARTNER": {
"kind": "odata-v2",
"model": "srv/external/API_BUSINESS_PARTNER",
"credentials": {
"destination": "S4HC_BP",
"path": "/sap/opu/odata/sap/API_BUSINESS_PARTNER"
}
}
}
}
}Three parts matter here:
kind: "odata-v2"tells CAP to use the OData V2 protocol adapter. Choosing the wrong version is a common cause of failing requests, since the Business Partner API is V2, not V4.modelpoints to the imported contract. CAP validates your queries against it.credentials.destinationnames a BTP destination. The host, authentication type and secrets live in the destination, not in your code. Thepathis appended to the destination URL.
Projecting only what you need
Do not expose the full external entity to your own consumers. Project the few fields you need:
using { API_BUSINESS_PARTNER as bp } from './external/API_BUSINESS_PARTNER';
service PartnerReview {
@readonly
entity BusinessPartners as projection on bp.A_BusinessPartner {
key BusinessPartner,
BusinessPartnerFullName,
BusinessPartnerIsBlocked
};
}This has three benefits. Your public interface stays small and under your control. Only the fields you actually need are requested from S/4HANA. And a change in a field you don't use cannot affect you. @readonly makes the entity reject create, update and delete requests at the framework level, which matches a review scenario that never writes to the core.
Delegating reads to the remote system
The service has no local table. A handler must forward reads to the remote service:
const cds = require('@sap/cds')
module.exports = class PartnerReview extends cds.ApplicationService {
async init() {
const bp = await cds.connect.to('API_BUSINESS_PARTNER')
this.on('READ', 'BusinessPartners', req => bp.run(req.query))
return super.init()
}
}cds.connect.to resolves the name against the requires section. bp.run(req.query) sends the incoming query, rewritten by CAP from your projection onto the remote entity, to S/4HANA. The data stays in the core and is not copied. Each request reflects the current state, and you have no replication job to maintain.
Gotchas and edge cases
Things that commonly go wrong when relying on released APIs:
- A released API can still change. Released does not mean frozen. SAP adds fields and may deprecate a version. Importing a specification pins your model to a snapshot, so re-import and compare when SAP announces a new version. Prefer additive tolerance: do not fail when the response contains fields you did not model.
- Version and edition differences. The same service name can differ between S/4HANA Cloud Public Edition and an on-premise release. Download the specification from the product edition that matches your system.
- Release is not the same as authorization. Even if the API is released, your technical user or destination needs the right communication arrangement, or authorizations in on-premise systems. A 403 usually points here, not at the API.
- Operations on the remote service are limited. Remote services in CAP do not support every query feature. Complex expressions in a projection may not translate to an OData V2 request. If a request fails with an unsupported feature error, simplify the projection or filter in your handler.
- Unreleased shortcuts. Calling a custom RFC, a customer-specific OData service on an internal CDS view, or direct database access is not a released contract. The next chapters classify such cases as anti-patterns and as lower clean core levels.
- Missing API. If no released API covers your need, do not fall back to an internal object. Check for a successor object in the Cloudification Repository, request an API from SAP, or expose your own released-based service through developer extensibility.
Checklist before you build
- Find the API on the Business Accelerator Hub for your exact product edition.
- Confirm its state is Released and not Deprecated, and that it is released as a remote API.
- Download the specification and import it, so your model mirrors the contract.
- Keep credentials in a destination, never in code or
package.json. - Project only the fields you need, and mark the entity
@readonlyif you never write.
Exercise
Your team wants to read sales order data from S/4HANA in a CAP application. A colleague suggests using a class that is released with contract C1 because it is "released". Why is this not sufficient, and what should you look for instead?
Show answer
C1 allows use inside the S/4HANA system, for example from ABAP Cloud code, and does not cover calls from outside. A side-by-side CAP application needs an object released as a remote API (C2), such as a released OData service listed on the SAP Business Accelerator Hub with release state Released. You would download its specification, import it with cds import, and reach it through a destination.
Exercise
In the CAP example, why does the handler forward req.query to the remote service, and what is the benefit compared with copying the data into a local database?
Show answer
The handler passes the query, translated onto the remote entity, to the released API, so the data stays in S/4HANA. Reads always show the current state and there is no replication job or duplicate data to keep consistent. The cost is that each read depends on the availability and latency of the core system.