Sub topic 16
Extending S/4HANA While Keeping the Core Clean
This chapter assumes you know the module landscape from earlier chapters: Finance, Procurement, Sales, Inventory, and Manufacturing. It also assumes you know what a Fiori app and a CDS view are, and that you have seen the deployment options (Cloud Public Edition, Private Edition, on-premise). Here you will learn how to change S/4HANA behavior without damaging the standard code that SAP delivers and upgrades.
Why the core matters
The core is the SAP-delivered software: standard tables, ABAP code, CDS views, and business logic in every module. SAP ships updates to it. In Cloud Public Edition, updates arrive on a fixed schedule. On-premise systems upgrade on the customer's schedule, but the upgrade still has to work.
Classic ERP projects changed the core directly. Teams modified standard programs, added fields to SAP tables with ad hoc code, and called internal function modules that SAP never promised to keep stable. Each change made the next upgrade harder, because every modification had to be found, retested, and often rewritten.
Clean core is SAP's name for the opposite approach. You keep the standard software unmodified. You put your own logic in layers that use only stable, released interfaces. The result is that upgrades do not break your extensions, and your extensions do not break upgrades.
The three extensibility styles
SAP groups extensions by where the custom code runs and what it may touch.
| Style | Where it runs | Typical use | Upgrade risk |
|---|---|---|---|
| Key user (in-app) extensibility | Inside the S/4HANA system, through Fiori apps | Add a custom field, custom logic hook, custom CDS view, or custom business object | Low |
| Developer (on-stack) extensibility | Inside the S/4HANA system, written in ABAP Cloud | Custom classes, RAP business objects, and released-API calls that need real code | Low to medium |
| Side-by-side extensibility | On SAP Business Technology Platform (BTP), outside S/4HANA | Standalone apps, heavy integration, new user interfaces, event-driven scenarios | Low |
Key user extensibility
Business users or functional consultants make these changes. They use Fiori apps such as Custom Fields, Custom Logic, and Custom CDS Views. No ABAP development tools are needed.
A typical case is adding a "Project Reference" field to the sales order header. The Custom Fields app creates the field, and SAP generates the technical parts: database column, API exposure, and UI placement. The field then appears in the sales order app, in the OData service, and in analytics, because the extension framework wires it through those layers.
Custom Logic uses released extension points called business add-ins (BAdIs). An example is a validation that rejects a sales order when the project reference is empty.
Developer extensibility
Developers use ABAP Cloud, a restricted version of ABAP. Two rules define it:
- You may call only objects that SAP has released for use. A released object carries a release contract, such as "C1" for use in custom code, which tells you SAP will keep it stable.
- You may use only the language features allowed in the ABAP Cloud language version.
The ABAP Test Cockpit (ATC) enforces these rules. If your class reads an unreleased table or calls an unreleased function module, the check fails.
This is why the data-access examples from earlier chapters need care. A query such as the following works in an old-style report, but it reads the unreleased table directly:
SELECT FROM vbak
INNER JOIN vbap ON vbap~vbeln = vbak~vbeln
FIELDS vbak~vbeln, vbak~kunnr, vbap~posnr, vbap~matnr, vbap~netwr
WHERE vbak~vkorg = '1010'
INTO TABLE @DATA(order_items)
UP TO 100 ROWS.In ABAP Cloud, you read the same data through a released CDS view, for example a sales order interface view such as I_SalesOrder and its item counterpart. The released view is the contract. SAP may change the tables beneath it, and it keeps the view stable.
Side-by-side extensibility
Some solutions do not belong inside the ERP system. Examples are a supplier onboarding portal, a mobile app for warehouse staff, or a machine-learning service that reads order history. These run on SAP BTP and talk to S/4HANA through released OData or SOAP APIs, and through business events.
Side-by-side extensions have three advantages:
- They have their own lifecycle, so they can be updated without touching the ERP release.
- A fault in them cannot take down the ERP system.
- They can serve users and systems outside the company.
The cost is operational. You run another platform, handle authentication between systems, and accept network latency for each call.
How extensions plug into the modules
Earlier chapters described integration flows such as order-to-cash. Extensions hook into these flows at defined points, not anywhere you like.
The most common extension needs map to a short list:
- Extra data on a document. Use a custom field. The framework carries it from the sales order to follow-on documents where SAP supports field propagation.
- Extra checks or derivations. Use Custom Logic with a BAdI at a released extension point.
- Extra reports. Build a custom CDS view on top of released views, then expose it in a Fiori app or analytical tool.
- A new business object. Use a RAP (RESTful ABAP Programming Model) business object, either on-stack or on BTP.
- A new app or a process outside the ERP core. Build it side-by-side and consume events or APIs.
Extending analytics safely
Embedded analytics, covered earlier, is built from CDS views. A custom view should select from released views, not from tables such as ACDOCA directly. The reason is stability: the Universal Journal's structure is a SAP implementation detail, and released views such as I_JournalEntryItem expose it through a contract.
The following sketch shows the shape of a custom CDS view entity in ABAP Cloud. The view reads a released interface view and adds a calculated field.
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Journal items by account'
define view entity ZI_JournalByAccount
as select from I_JournalEntryItem
{
key CompanyCode,
key FiscalYear,
key AccountingDocument,
key LedgerGLLineItem,
GLAccount,
AmountInCompanyCodeCurrency,
CompanyCodeCurrency
}
where Ledger = '0L'Check the exact field names against the released view in your system. Field names and key structure can differ between releases, so ADT's code completion is the safest source.
Decision criteria
Choose the style by asking these questions in order:
- Can a standard setting, configuration, or an existing SAP app solve it? If yes, do that first. No extension is cheapest.
- Does it only add a field, a small rule, or a report? Use key user extensibility.
- Does it need real code that stays close to ERP data and transactions? Use developer extensibility with ABAP Cloud.
- Does it serve outside users, need its own release cycle, or use non-ABAP technology? Use side-by-side on BTP.
Deployment option changes your choices. Cloud Public Edition permits only the clean-core styles above. Private Edition and on-premise systems still allow classic ABAP, which gives flexibility and also lets old habits return. Many teams in those systems choose to write all new code in ABAP Cloud anyway and to keep a list of legacy modifications to retire.
Common errors and gotchas
- Reading tables directly. Code that selects from VBAK, ACDOCA, or MARA works today and may fail an upgrade or an ATC check. Use released CDS views.
- Mixing styles carelessly. A custom field made through key user tools and a duplicate column added through a database append can disagree. Pick one mechanism.
- Ignoring authorizations. A custom CDS view with no access control can expose data. Set an authorization check and define a matching access control object.
- Side-by-side chatty calls. Calling an API once per line item causes latency and rate-limit problems. Batch requests, or use events to push changes.
- Treating clean core as a one-time cleanup. New code accumulates. Run ATC checks for clean core compliance in your pipeline and review the results on a schedule.
- Modifying instead of extending. If you find yourself copying a standard program to change one line, look for a BAdI, an event, or a released API first.
Exercise
A company on Private Edition wants to (1) add a "Project Reference" field to the sales order header, (2) reject orders where that field is empty for one sales organization, and (3) offer customers an external portal where they check order status. Which extensibility style fits each requirement, and why?
Show answer
(1) Key user extensibility, using the Custom Fields app, because it only adds a field and SAP generates the database, API, and UI parts. (2) Key user extensibility with Custom Logic at a released BAdI, because it is a small validation rule inside the order process. Developer extensibility is needed only if the rule requires more code than the logic editor supports. (3) Side-by-side extensibility on SAP BTP, because the users are outside the company, the portal needs its own lifecycle, and it can read order status through released APIs without exposing the ERP system.
Exercise
A developer's ABAP Cloud class selects directly from table MARA and the ATC check fails. What is the likely cause, and what is the fix?
Show answer
MARA is not released for use in ABAP Cloud, so the clean core check rejects it. The fix is to read material data through a released CDS view, such as a product interface view, after confirming its API State in ADT.