API Creation Process in SAP S/4HANA: From CDS View to OData Service
api creation process in sap s4 hana
Also searched as
- create custom odata service s4hana
- sap cds view odata service binding
- create api in sap s4hana
- sap rap service definition binding
Short answer
The modern process to create an API in SAP S/4HANA is to model data in a CDS view entity in ABAP Development Tools (ADT), expose it with a service definition, publish it with a service binding (OData V4 Web API or V2), activate it, and secure it with an access control and role authorizations. Always check the SAP Business Accelerator Hub first, since a released standard API may already exist.
Applies to: SAP S/4HANA on-premise (recent releases) and the ABAP environment. Older systems use SEGW for OData V2; names of the V4 admin tools vary by release.
How to create a custom OData API from a CDS view
- 1Search the SAP Business Accelerator Hub (formerly API Business Hub) for a released API. Use a standard one if it covers your need.
- 2In ADT (Eclipse), create a CDS view entity over the tables or released CDS views you need, with the fields and associations the API should expose.
- 3Create an access control (DCL) so the view returns only data the caller is authorized to see.
- 4Create a service definition that lists the CDS entities to expose.
- 5Create a service binding with the right type (OData V4 Web API for system integration, or OData V2 where consumers require it) and activate it.
- 6Register and test the service: for V2 use /IWFND/MAINT_SERVICE, for V4 use the V4 service administration tool; then call the service document and entity set in a browser or API tool.
- 7Assign authorization for the service to the technical user or role, and secure transport (HTTPS) with the right authentication.
- 8Transport the objects with your change request and document the API contract.
Which approach to use
For new development, the ABAP RESTful Application Programming Model (RAP) with CDS is the recommended path. It gives you read-only query APIs from a CDS view, or full create, update and delete with a behavior definition. For older landscapes, SEGW (Gateway Service Builder) still builds OData V2 services but is not the strategic direction.
Where SAP offers a released API, use it. Released APIs carry stability promises across upgrades, while custom APIs over internal tables can break when SAP changes structures, particularly in S/4HANA where tables are replaced by compatibility views.
Security and operations
An exposed API is an attack surface. Use a dedicated technical user with the minimum role, enforce DCL access control, enable CSRF protection for writes, and rate limit at the gateway. Avoid basic authentication with a dialog user. Prefer OAuth or certificate authentication where your gateway supports it.
Monitor usage through the gateway logs and error log (for example /IWFND/ERROR_LOG), and version the API when contracts change so consumers are not broken.
@AccessControl.authorizationCheck: #CHECK
define view entity ZI_OpenPO as select from I_PurchaseOrderAPI01 {key PurchaseOrder,
Supplier,
PurchaseOrderDate,
DocumentCurrency
}
Calling the API
Once active, consumers call the OData endpoint with a GET for reads and standard OData query options such as $filter, $select and $top. Writes require the behavior definition and a CSRF token fetch before POST or PATCH.
For integration patterns from Python or middleware, see the page on calling SAP OData with authentication and pagination. For on-premise landscapes, route calls through SAP Cloud Connector or your own API gateway rather than exposing the system directly.
Try it here, free
ABAP CDS View Skeleton Generator
Fill in table, fields, aliases and one association to get CDS view DDL in both the classic DDIC-based and the view entity syntax.
Common pitfalls
- !Building a custom API over a table SAP later changes, instead of a released CDS view.
- !Skipping access control, so every caller sees every row.
- !Exposing the service with a powerful dialog user for convenience.
- !Forgetting to activate the binding in the gateway, so the URL returns 404.
- !Returning large unfiltered entity sets without server-side paging.
How an ERP-grounded AI assistant handles this
Once APIs exist, a grounded AI layer can use them as governed tools: read-only by default, running under the user's role, with the call shown. Netray's ERPray and custom builds connect to S/4HANA OData and CDS services this way, and can run with open-weight models on-prem so ERP payloads never reach a public API.
Frequently asked questions
How do I create an OData service in S/4HANA?
Model a CDS view entity in ADT, create a service definition that exposes it, create and activate a service binding (V4 or V2), then test the service. Add an access control and assign service authorization to the calling user or role.
Should I use SEGW or RAP?
Use RAP with CDS for new work, since it is SAP's strategic model and works across on-premise and cloud ABAP. SEGW is still available for OData V2 on older landscapes, but it is not where new features land.
Where do I find standard SAP APIs?
In the SAP Business Accelerator Hub, which lists released APIs with their documentation and sandbox. Using a released API is safer than building your own over internal tables.
How do I secure a custom S/4HANA API?
Use HTTPS, a technical user with minimal roles, DCL access control on the CDS view, service-level authorization, CSRF handling for writes, and gateway-level rate limiting. Prefer OAuth or certificates over shared passwords.
Related
SAP S/4HANA API Documentation: Where It Is and How to Use It
S/4HANA API documentation lives on the SAP Business Accelerator Hub (api.sap.com), under the S/4HANA Cloud or S/4HANA on-premise package. Most APIs are OData (v2, and v4 for newer ones) plus SOAP for some integrations. In public cloud you authorize an external caller with communication arrangements; on-premise you activate the service in the Gateway and use basic, OAuth or certificate authentication.
How-toSAP S/4HANA API Guide: Business Hub, OData, Public Cloud and Business Partner
S/4HANA APIs are discovered in the SAP Business Accelerator Hub and mostly delivered as A2X OData services such as API_BUSINESS_PARTNER. On-premise you activate them in the Gateway; in the public cloud you create a communication user, system and arrangement for a communication scenario. PI/PO or Integration Suite sit in between for orchestration, and SAP Digital Manufacturing has its own APIs on BTP.
How-toCalling SAP APIs from Python: OData with requests, Authentication and PyRFC
The simplest way to call SAP from Python is OData over HTTPS with the requests library: send a GET to the service with $select, $filter and $top, authenticate with basic or OAuth, and follow the next-page link. For writes fetch a CSRF token first. Use PyRFC only for functions that have no OData service, and accept the extra SAP NW RFC SDK dependency.
Error fixSAP M7 021: Deficit of SL Stock Quantity
M7 021 fires during a goods issue, delivery, or confirmation when SAP checks the unrestricted-use (SL) stock for the exact plant, storage location and batch combination and finds less than what you are trying to post out. Fix the entry (batch, storage location, quantity) first; only enable negative stock or downgrade the message to a warning if the business genuinely needs to post ahead of a receipt.
Error fixSAP IDoc Status 51: Application Document Not Posted
Status 51 tells you the IDoc reached the application layer and failed to post, but the status text itself is not the error - the real cause sits in the status record's long text or the linked application log. Fix the underlying data or configuration, then reprocess the IDoc through BD87 rather than editing the status.
Error fixSAP Short Dump TIME_OUT: Maximum Runtime Exceeded
A TIME_OUT runtime error means a dialog (or RFC) work process ran longer than the maximum allowed runtime, controlled by profile parameter rdisp/max_wprun_time (600 seconds by default). The fix is almost always to move the long-running work to background processing or tune the underlying program, not to raise the timeout.
AI for ERPAI for SAP S/4HANA, Running On-Prem or in Your Private Cloud
Run AI on SAP S/4HANA without sending ERP data to a public API. On-prem and private-cloud architecture, CDS views, OData, and honest deployment trade-offs.
AI for ERPSAP BTP and a Private LLM: Where the Generative AI Hub Fits and Where It Doesn't
Where SAP BTP's Generative AI Hub fits and where a self-hosted LLM belongs instead. CAP, Integration Suite, and an architecture decision framework.
Stuck on SAP S/4HANA?
Talk to engineers who work inside SAP S/4HANA every week, and who build private AI that answers these questions from your own ERP data.
Keep exploring
Free tools
- ABAP CDS View Skeleton GeneratorFill in table, fields, aliases and one association to get CDS view DDL in both the classic DDIC-based and the view entity syntax.
- SAP API Business Hub Request GeneratorBuild a ready-to-run cURL or HTTP request for an SAP API Business Hub sandbox or your own S/4HANA Cloud tenant, with the right headers and query options.
- SAP OData Service URL BuilderGenerate a correct SAP Gateway OData V2 request URL with query options, test it in a browser or REST client, then reuse it in your code.
ERP fixes and how-tos
- SAP S/4HANA API Documentation: Where It Is and How to Use ItWhere to find S/4HANA API documentation (SAP Business Accelerator Hub), OData vs SOAP, authentication on cloud and on-prem, and key manufacturing APIs.
- SAP S/4HANA API Guide: Business Hub, OData, Public Cloud and Business PartnerA guide to SAP S/4HANA APIs: the Business Accelerator Hub, A2X OData, the Business Partner API, public cloud communication arrangements, PI/PO and Digital Manufacturing.
- SAP S/4HANA Standard Reports: Fiori, Embedded Analytics and CDS ViewsWhere standard reports live in SAP S/4HANA: Fiori analytical apps, embedded analytics and CDS views, with examples for sales reporting and Group Reporting in finance.
AI on your ERP
- AI for SAP S/4HANA, Running On-Prem or in Your Private CloudRun AI on SAP S/4HANA without sending ERP data to a public API. On-prem and private-cloud architecture, CDS views, OData, and honest deployment trade-offs.
- AI for SAP Business One, Without Sending Your Books to a Public APIAdd AI to SAP Business One without sending customer data or financials to a public API. Service Layer and DI API integration, sized for an SMB budget.
Integrations
- How to connect Power BI to SAP S/4HANAConnect Power BI to SAP S/4HANA using the HANA connector, OData or a warehouse, set up the on-prem gateway, and build manufacturing dashboards with AI Q&A.
- How to connect ChatGPT to SAP S/4HANAConnect ChatGPT to SAP S/4HANA with custom GPT actions over OData, or with exports. Compare live access, enterprise data controls and a private model option.