Sub topic 10
Connecting BTP to SAP S/4HANA with destinations
This chapter assumes you know OAuth 2.0 basics, how OData APIs are called, and what a BTP subaccount is. You will learn how a side-by-side extension finds and calls an SAP S/4HANA system without hard-coded hosts or credentials.
Why destinations exist
A side-by-side extension runs outside S/4HANA. It must know the target URL, the authentication method, and the credentials. Putting these in code or environment variables ties the app to one system and leaks secrets into source control.
A destination is a named configuration object in the SAP BTP Destination service. It holds the URL, authentication type, and credentials for one remote system. The application refers only to the name, for example S4HC_BP. Each landscape (dev, test, prod) defines its own destination with that name, so the same code runs in all of them.
How a call flows
The application asks the Destination service for the destination by name. The service returns the URL and, depending on the authentication type, a token or headers. The application then calls S/4HANA directly. With CAP, the runtime does these steps for you.
Key destination properties
| Property | Meaning | Example |
|---|---|---|
| Name | The identifier your code uses | `S4HC_BP` |
| URL | Base URL of the target system | `https://my-system-api.s4hana.cloud.sap` |
| Proxy Type | `Internet` for cloud systems, `OnPremise` through Cloud Connector | `Internet` |
| Authentication | How the call is authenticated | `OAuth2SAMLBearerAssertion` |
Choosing the authentication type
The authentication type decides whose identity S/4HANA sees.
- BasicAuthentication sends a fixed technical user and password. It is simple but offers no user context and requires password rotation. Use it for testing only.
- OAuth2ClientCredentials uses a technical client. All calls run as the same technical user. It suits background jobs.
- OAuth2SAMLBearerAssertion and OAuth2JWTBearer pass the logged-in user's identity to S/4HANA, so its authorizations and audit logs apply to that person. The next chapter covers this in detail.
- PrincipalPropagation forwards the user through the Cloud Connector to an on-premise system.
Reaching on-premise systems
S/4HANA Cloud systems are reachable over the internet, so Proxy Type = Internet works. A system in a private network needs the Cloud Connector, a small agent installed in your network. It opens an outbound tunnel to BTP, so no inbound firewall ports are needed. The destination then uses Proxy Type = OnPremise and a virtual host name that the Cloud Connector maps to the real host.
Using the destination from CAP
In the credentials block of your CAP configuration, give only the destination name and the API path. CAP resolves the rest at runtime.
{
"cds": {
"requires": {
"API_BUSINESS_PARTNER": {
"kind": "odata-v2",
"credentials": {
"destination": "S4HC_BP",
"path": "/sap/opu/odata/sap/API_BUSINESS_PARTNER"
}
}
}
}
}The destination URL should hold only the host. The service path stays in your configuration, so one destination can serve several APIs on the same system.
Common errors
- Destination not found: the app is not bound to a Destination service instance, or the name differs in case or spelling.
- 401 or 403 from S/4HANA: the technical user or communication arrangement lacks the scope for the API. Check that a communication arrangement exists for the released API.
- Path doubled or missing: the destination URL already includes the service path, and CAP appends it again.
- Connection timeout: the Cloud Connector is offline or the virtual host mapping is missing.
Exercise
Your app passes the destination S4HC_BP with URL https://host/sap/opu/odata/sap/API_BUSINESS_PARTNER, and your CAP configuration also sets path to /sap/opu/odata/sap/API_BUSINESS_PARTNER. Calls fail with 404. What is the likely cause, and how do you fix it?
Show answer
The service path is appended twice. Change the destination URL to the host only, https://host, and keep the path in the CAP credentials block.