Sub topic 8
Side-by-side extensions on SAP BTP
This chapter assumes you know the basics of SAP S/4HANA business processes, REST and OData APIs, and OAuth 2.0. You should also be able to read simple JavaScript. Earlier chapters covered the clean core principle and released APIs. Here you see how a side-by-side extension applies them.
What a side-by-side extension is
A side-by-side extension is an application that runs outside the S/4HANA system, on SAP Business Technology Platform (SAP BTP). It talks to S/4HANA only through released, stable interfaces such as OData APIs and business events. The S/4HANA system is unaware of the extension's internals, and the extension has no access to S/4HANA code or database tables.
This separation is what keeps the core clean. Upgrades of S/4HANA do not touch your extension code. The extension has its own release cycle, its own scaling, and its own technology stack.
SAP S/4HANA Cloud and SAP BTP are separate systems with separate lifecycles. A side-by-side extension is therefore not "inside" the ERP system in any sense. It is a different application that happens to work with ERP data.
When side-by-side fits
Side-by-side is usually the right choice when one or more of these hold:
- The extension needs its own data model, persistence, or user interface that has no home in the S/4HANA data model.
- It combines data from several systems, for example S/4HANA, SuccessFactors, and a third-party service.
- It serves users who are not S/4HANA users, such as suppliers, customers, or field staff.
- It needs a different technology than ABAP, such as Node.js, Java, or an AI service.
- It must scale or release independently of the ERP system.
- It runs long processes, such as workflows or approvals, across systems.
It is a poor fit when the logic must run inside the same database transaction as the standard process. For example, a validation that must reject a sales order save belongs in the core, through in-app or developer extensibility. A remote call cannot take part in the S/4HANA commit.
Building blocks
Most side-by-side extensions on SAP BTP combine the following parts.
| Building block | Role in the extension |
|---|---|
| Runtime | Runs your code: Cloud Foundry, Kyma, or ABAP environment (covered in the next chapter) |
| Destination service | Stores the target URL and authentication for S/4HANA |
| Connectivity | Reaches systems, including on-premise ones through the Cloud Connector |
| Identity (XSUAA or IAS) | Authenticates users and issues tokens |
| CAP | Provides the programming model for services, data, and remote calls |
| Event Mesh or similar | Delivers business events from S/4HANA |
| UI layer | SAP Fiori elements, SAPUI5, or SAP Build Work Zone for launching |
You do not need all of them. A small extension might use only a CAP service, a destination, and a Fiori elements app.
Architecture
The diagram shows a typical request path. The user works in a browser. The extension on SAP BTP authenticates the user, then calls S/4HANA through a destination.
Two integration directions appear here. The extension pulls data and writes data through APIs (synchronous). S/4HANA pushes events to the extension (asynchronous). Later chapters treat both in detail.
A first look at the code
A side-by-side extension that reads business partners needs three things: a remote service definition, a projection, and a handler. The SAP Cloud Application Programming Model (CAP) supports this directly.
First, register the released API as a remote service. The credentials block points to a destination, so the host and secrets stay out of the code.
{
"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"
}
}
}
}
}Second, expose only the fields you need. The projection ties your extension to the stable API contract and nothing else.
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
};
}Third, forward reads to the remote system. Data stays in S/4HANA and is not copied into the extension.
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()
}
}The handler uses req.query, so filters, paging, and sorting from the UI are translated into the OData request. Without this handler, CAP would try to read the entity from a local database table that does not exist, and the request would fail.
Data strategy: call it or copy it
The code above reads data live from S/4HANA. This is one of two strategies, and the choice affects performance and resilience.
| Strategy | Benefits | Costs |
|---|---|---|
| Read live through the API | Always current, no duplicate data, simple | Latency on every request, extension depends on S/4HANA availability, API rate limits apply |
| Replicate into the extension | Fast reads, works when S/4HANA is down, allows joins with local data | Data can be stale, you need sync logic and storage, more compliance scope |
A common middle path is to read live for detail views and keep a small local copy of fields needed for joins or search. Replication is usually kept current with business events, so the extension updates after a change instead of polling.
Whichever you pick, decide it per entity, not per project. A business partner name may be fine to cache. A credit limit is not.
Writing back to the core
Extensions often need to change S/4HANA data too. Rules for doing this safely:
- Use only released APIs that support the operation. If no released API allows the write, the extension is not a clean core candidate for that step.
- Make calls idempotent where possible. Network retries can send the same request twice.
- Handle partial failure. The extension's own database commit and the S/4HANA call are not one transaction. If the remote call fails after you saved local data, you need a compensation step or a status field such as
PENDINGandFAILED. - Respect the API's draft or validation behavior. Business rules in S/4HANA still apply, and error messages come back as OData errors that you should pass on to the user in readable form.
Common errors and gotchas
- Wrong authentication in the destination. A 401 or 403 from S/4HANA often means the destination uses a technical user without the right communication scenario, or user propagation is not set up. Check the communication arrangement in S/4HANA first.
- Calling an unreleased API. If an OData service is not listed as released for your system type, it can change without notice. This breaks the clean core promise even though the call technically works.
- Missing handler. A CAP projection on a remote entity without a
READhandler fails, as described above. - Pulling too much data. Selecting all fields and all rows from a large entity is slow. Project only what you need and use
$topand$filter. - Hard-coded hosts and secrets. Keep them in destinations, never in source code or in
package.jsonvalues. - Ignoring tenant and landscape differences. Development, test, and production S/4HANA systems need separate destinations. Name them consistently so deployment does not need code changes.
Operating a side-by-side extension
Because the extension is its own application, you also own its operations:
- Monitoring and logging, for example through SAP Cloud Logging.
- Security patches for your dependencies.
- Subscription and cost management on SAP BTP, since usage is metered.
- Transport and deployment, usually through a pipeline such as SAP Continuous Integration and Delivery with Multitarget Application (MTA) archives.
This is the main trade-off. You gain independence from the ERP release cycle and pay with additional operational work. Teams with no capacity for that work may prefer in-app or developer extensibility for simple needs.
Summary
A side-by-side extension runs on SAP BTP and uses only released APIs and events, so S/4HANA upgrades do not break it. It suits independent data models, multi-system scenarios, outside users, and non-ABAP technology. It does not suit logic that must be part of the core transaction. Decide per entity between live reads and replication, plan for partial failures when writing back, and budget for running the application yourself.
Exercise
A team wants to block saving a sales order when a custom credit rule fails. The rule needs data from an external credit agency. They propose a side-by-side extension that S/4HANA calls during the save. Name two problems with this design and suggest an alternative split.
Show answer
First, the save transaction in S/4HANA cannot include the remote extension in its commit, so a slow or failed call either blocks users or lets invalid orders through. Second, it makes the core's availability depend on an external application. A better split is to implement the blocking check in the core with developer or in-app extensibility, using locally available data. The side-by-side extension fetches and prepares the credit agency data ahead of time, for example by updating a released field or sending an event, so the core check does not wait on a remote call.
Exercise
Your CAP service defines a projection on a remote entity but returns an error when the UI requests data. The destination test succeeds. What is the most likely cause, and how do you fix it?
Show answer
The service has no READ handler for the remote entity, so CAP looks for a local database table. Connect to the remote service with cds.connect.to and register this.on('READ', 'BusinessPartners', req => bp.run(req.query)) in the service's init method.