ERPClimb logoERPClimb
Service Bindings
RAP / CDS / ODatabeginner 11 min read

Service Bindings Part 1: From Business Object to OData Service

Free sample lesson · open to everyone

Key takeaway

Understand where a service binding fits in RAP: projection views, service definition and service binding, what each one decides, the binding types available, and how the binding turns your business object into a callable OData endpoint.

In this lessonShow sections

Expert visual walkthrough

RAP · CDS · ODATA ACADEMY · Integration pathERPClimb.com

From Business Object to OData Service

Service Bindings · Chapter-specific technical teaching map

Integration path

1Concept

Service definition

2Concept

Binding type

3Concept

Activate and publish

4Concept

Metadata and consumer

Tutor's chapter takeaway

Understand where a service binding fits in RAP: projection views, service definition and service binding, what each one decides, the binding types available, and how the binding turns your business object into a callable OData endpoint.

In a real project

A developer finished a RAP business object and created a service definition that exposed only the root projection ZC_PurchReq. The binding activated without error, and the list page worked in preview. But the object page…

Watch out for

• Thinking the service binding contains logic — it only publishes; behavior lives in the BDEF, fields in the projection. • Exposing ZR_ base views instead of ZC_ projections. • Forgetting to expose child entities, which…

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

The situation: a real project scenario

A developer finished a RAP business object and created a service definition that exposed only the root projection ZC_PurchReq. The binding activated without error, and the list page worked in preview. But the object page showed no Items section, and adding an item failed. The team spent a day checking the behavior definition and draft tables.

The cause was one missing line: ZC_PurchReqItem was not exposed in the service definition, so the _Item navigation had no target entity set in the service. Adding "expose ZC_PurchReqItem as PurchaseRequestItem;" and reactivating the definition and binding fixed it immediately.
Afterwards the team added a checklist item: every entity reachable through a composition must be exposed in the service definition.

Explanation

This part walks through the exposure chain that turns a RAP business object into an OData service: business object flows into a projection, which flows into a service definition, which flows into a service binding, which produces the actual OData service. The service definition decides WHAT is exposed, while the binding decides HOW — the protocol, and whether it's a UI or an API. The rule is to always expose the projections (ZC_/ZA_), never the base R_ views, and to keep one binding per protocol and consumer type.

This series exposes the Purchase Request business object built in the Managed RAP series as an OData V4 service and a Fiori Elements app. You can follow it with any RAP business object, but the examples use ZR_PurchReq and its projection ZC_PurchReq from Managed RAP Part 5.

The six parts cover: Part 1, the exposure chain and what a binding is; Part 2, creating, activating, publishing and testing a binding in ADT; Part 3, moving bindings through DEV, QAS and PRD; Part 4, UI versus Web API bindings and OData V2 versus V4; Part 5, troubleshooting 404, 403, metadata and cache problems; and Part 6, preview, metadata and Fiori Elements annotations.

The problem a service binding solves is that a RAP business object is pure ABAP — CDS views, a behavior definition and classes — and a browser, a Fiori app or another system cannot call ABAP directly; they speak HTTP and OData. Something has to decide which entities are visible, which protocol is used, and at which URL the service lives. That's the job of the last two objects in the RAP stack.

The exposure chain involves four objects making four separate decisions. First, the business object (ZR_PurchReq plus its BDEF) defines what the data is and what can happen to it, built once and reused by every consumer. Second, the projection (ZC_PurchReq plus the projection BDEF) decides which fields and operations a particular consumer gets, along with UI annotations.

Third, the service definition (ZUI_PURCHREQ) decides which entities form one service and under what names — it is protocol-neutral, simply stating "expose ZC_PurchReq as PurchaseRequest" with nothing about OData.

Fourth, the service binding (ZUI_PURCHREQ_O4) decides how and for whom the service is offered: the protocol (OData V2 or V4, plus some other types), the purpose (UI or Web API), and the runtime registration that produces an actual URL.

This chain runs in one direction: a binding points to exactly one service definition, but one service definition can have several bindings — for example a V4 UI binding and a V2 UI binding side by side during a migration.

The service definition groups the root and child projections into one service; everything the consumer navigates to must be exposed here, so if ZC_PurchReqItem isn't exposed, the Items navigation simply won't work. It also gives each entity its external name — the entity set name in OData — and these names should be business-readable since they appear in URLs and client code. The service definition itself contains no logic and no protocol settings.

The service binding, by contrast, binds the service definition to a protocol and a binding type. Once activated, it shows in ADT the service version, the entity sets and their associations, and a Preview button per entity. Once published (covered in Part 2), it registers the service in the OData runtime (SAP Gateway) so it gets a real URL, something like …/sap/opu/odata4/sap/zui_purchreq_o4/srvd/sap/zui_purchreq/0001/ — always copy this URL from the binding editor rather than typing it by hand.

There are several binding types to choose from. OData V4 – UI suits Fiori Elements and SAPUI5 apps, includes UI annotations, supports draft, and is the default choice for new transactional apps. OData V4 – Web API suits system-to-system integration, has no UI annotations, and is meant for stable programmatic contracts.

OData V2 – UI and OData V2 – Web API represent the older protocol version, used only when a consumer requires V2, such as older apps, certain tools, or some integration adapters. Some releases offer further types, such as InA for analytical queries or SQL for SQL-based access, but those sit outside this series. Part 4 goes into this choice in more detail.

A consistent naming convention avoids confusion later: service definitions are named ZUI_<object> for UI services and ZAPI_<object> for APIs, while service bindings take the service definition's name plus a suffix for the protocol — _O4 for OData V4 or _O2 for OData V2 — giving names like ZUI_PURCHREQ_O4.

To build this yourself: first confirm the projection ZC_PurchReq, ZC_PurchReqItem and the projection BDEF are active, as set up in Managed RAP Part 5. Then right-click ZC_PurchReq, choose New → Service Definition, name it ZUI_PURCHREQ, add both entities as shown in the code example, and activate.

Next, right-click ZUI_PURCHREQ and choose New Service Binding, name it ZUI_PURCHREQ_O4 with binding type OData V4 – UI, and activate. In the resulting editor you'll see the service version 0001, the entity sets PurchaseRequest and PurchaseRequestItem, and the navigation between them — publishing and testing it comes in Part 2.

By the end of Part 1 you have a clear mental model of the four layers, plus an active service definition and binding. Keep in mind that activation alone does not make the service callable in an on-premise system — that requires the publish step covered in Part 2.

Code example

ABAP Code
// ===== Service definition ZUI_PURCHREQ =====@EndUserText.label: 'Purchase Request - UI service'      // shown as the service description in the binding editor / catalogdefine service ZUI_PURCHREQ {                            // defines WHICH projections become OData entity sets, not how they're served  expose ZC_PurchReq     as PurchaseRequest;              // root entity set name seen by clients; need not match the CDS view name  expose ZC_PurchReqItem as PurchaseRequestItem;          // child must be exposed too, or $expand/navigation to it fails} // ===== The full exposure chain for this example =====////  ZPR_HEAD / ZPR_ITEM            database tables//        |//  ZR_PurchReq / ZR_PurchReqItem  business object (CDS + managed BDEF)//        |//  ZC_PurchReq / ZC_PurchReqItem  projection (CDS + projection BDEF + UI annotations)//        |//  ZUI_PURCHREQ                   service definition  -> WHICH entities, external names//        |//  ZUI_PURCHREQ_O4                service binding     -> HOW: OData V4, UI, published URL//        |//  Fiori Elements app / API client//// Service binding editor (after activation + publish) shows e.g.://   Binding type : OData V4 - UI//   Service      : ZUI_PURCHREQ  version 0001//   Entity sets  : PurchaseRequest -> _Item -> PurchaseRequestItem//   Service URL  : /sap/opu/odata4/sap/zui_purchreq_o4/srvd/sap/zui_purchreq/0001///// Typical calls against that URL://   GET  .../0001/$metadata                               service description//   GET  .../0001/PurchaseRequest?$top=10                 list//   GET  .../0001/PurchaseRequest(RequestUUID=...,IsActiveEntity=true)?$expand=_Item//                                                         one request with items (draft-enabled key)

Watch out

Common mistakes

  • Thinking the service binding contains logic — it only publishes; behavior lives in the BDEF, fields in the projection.
  • Exposing ZR_ base views instead of ZC_ projections.
  • Forgetting to expose child entities, which breaks navigation and create-by-association.
  • Using technical or cryptic external names in the service definition — they become part of every URL and client.
  • Choosing OData V2 for a new app out of habit when V4 is the current standard.
  • Assuming "activated" means "callable" — in on-premise systems the binding must also be published.

Do this

Best practices

  • Keep the chain clean: tables → ZR_ BO → ZC_ projection → service definition → binding.
  • One service definition per use case (one app or one API), not one giant service for everything.
  • Expose every entity of the composition tree the consumer needs.
  • Use business names in the service definition and a consistent binding naming pattern (_O4 / _O2).
  • Default to OData V4 – UI for new Fiori Elements apps; use Web API bindings for integrations.
  • Copy the service URL from the binding editor instead of constructing it by hand.

Apply it: production case clinic

Two decisions · one practical outcome

Use a fictional SAP incident to practise choosing the next safe investigation. This is a worked diagnostic exercise, separate from the lesson's existing knowledge-check questions.

ERPClimb SAP case file · SERVICE BINDINGS

Separate the roles of projection, service definition and binding.

Incident brief

A developer activates a RAP behavior definition in ADT and expects an external REST endpoint to appear automatically, without defining an exposed service.

Evidence available

  • CDS projection and behavior projection activate
  • No service definition or binding has been created
  • No OData endpoint is visible

Decision 1 of 2

Which missing artifacts are necessary for external RAP service exposure?

Apply in a permitted SAP DEV / test environment

Sketch the artifact path BO → projection → service definition → binding → OData; find each corresponding object in a sandbox ADT project.

Evidence of success: You can name what each layer controls and locate the exposed entity set in service metadata.

Release consideration: Binding type and publication controls differ among SAP BTP ABAP environment and on-premise ABAP releases.

Consult official SAP guidance (opens new tab)

Local, self-directed practice only. No SAP system is connected, no persistent grade is awarded, and no production changes are made.

In the interview

Interview angle

Very common question: "What is the difference between a service definition and a service binding?" Answer: the service definition decides which projected entities form a service and their external names, independent of protocol; the service binding binds that definition to a protocol and purpose (OData V2/V4, UI or Web API) and registers it so it gets an endpoint. One definition can have several bindings.

Follow-ups: "What are the RAP layers from table to app?" (tables, BO, projection, service definition, service binding, consumer), and "Which binding type for a Fiori Elements app?" (OData V4 – UI, because it supports draft and UI annotations). Mentioning that activation and publishing are separate steps on-premise shows hands-on experience.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

Which RAP object decides whether a service is offered as OData V4 or OData V2, and for UI or Web API use?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1What is the difference between a service definition and a service binding in RAP? Can one service definition have several bindings?

2Your RAP list report works in preview, but the object page shows no Items section and adding an item fails. The behavior definition supports items. What is the most likely cause?

See it in code

Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.

Was this lesson helpful?

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.