Service Definitions Part 1: What a Service Definition Does
Learn what a service definition is in RAP, what it contains and what it does not, and where it sits between projections and service bindings.
What this complete series covers
Learn Service Definitions in a clear, practical sequence — from the basic idea to real project use, troubleshooting, and interview-ready understanding.
- Who it is for
- Best for SAP consultants, developers, and learners who want a practical understanding of Service Definitions.
- Prerequisites
- Basic ABAP and ADT in Eclipse are recommended. The series explains the RAP/CDS/OData concepts as they are introduced.
- Final outcome
- By the end, you should be able to explain Service Definitions clearly, follow the main end-to-end flow, apply it in a project scenario, and troubleshoot the most common issues.
- Part 1: Service Definitions Part 1: What a Service Definition Does
Learn how a RAP service definition defines the public set of projection entities that belong to one business service without containing implementation logic.
- Part 2: Service Definitions Part 2: Exposing Projection Entities as a Business Service
Use a service definition to group the RAP projection entities that form a protocol-independent business service while keeping interface and persistence internals private.
- Part 3: Service Definitions Part 3: API Boundary, Naming and Versioning
Treat service definitions as API products with stable business naming, minimal exposed surface and an explicit compatibility and versioning policy.
- Part 4: Service Definitions Part 4: Troubleshooting Activation and Exposure Gaps
Diagnose missing entities or actions by following the artifact chain from CDS projection and projection behavior to service definition, binding and generated metadata.
- Part 5: Service Definitions Part 5: UI vs Integration APIs — Reuse or Separate?
Choose shared or separate service contracts by comparing draft, annotations, stability, throughput and security requirements instead of defaulting to one service.
- Part 6: Service Definitions Part 6: Exposing Multiple Entities and Navigation
Expose a coherent graph of root, child and selected reference entities while preserving association semantics, cardinality and performance.
System and release assumptions: Examples target recent SAP S/4HANA / ABAP Cloud capabilities. RAP, CDS, OData, and Fiori Elements syntax and tooling can differ by ABAP platform release.
Explanation
📌 KEY POINTS
✅ A service definition lists WHICH entities a service exposes: define service … { expose … as …; }.
✅ It contains no logic and no protocol — the binding decides OData V2/V4, UI or API.
✅ Expose projection views (ZC_/ZA_), not base R_ views or tables.
⚠️ Entities not exposed are invisible to consumers — including navigation targets.
━━━━━━━━━━━━━━━━━━━━
▶ WHAT THIS SERIES COVERS
- Part 1 — what a service definition does (this lesson)
- Part 2 — exposing projections as a business service
- Part 3 — API boundary, naming and versioning
- Part 4 — troubleshooting activation and exposure gaps
- Part 5 — UI vs integration APIs: one service or two?
- Part 6 — exposing multiple entities, navigation and value helps
Next topic after this series: Service Bindings.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE IT SITS
Table → CDS base view (ZR_) + BDEF → projection (ZC_) + projection BDEF → SERVICE DEFINITION → service binding → OData service → Fiori app / API client.
The service definition is the first object that answers the consumer's question: "what can I access in this service?"
━━━━━━━━━━━━━━━━━━━━
▶ WHAT IT CONTAINS
define service ZUI_PURCHREQ {
expose ZC_PurchReq as PurchaseRequest;
expose ZC_PurchReqItem as PurchaseRequestItem;
}
- "expose <CDS entity> as <alias>" — each exposed entity becomes an entity set in OData.
- The alias is the name consumers see — choose business names.
- Optional header annotations like @EndUserText.label.
━━━━━━━━━━━━━━━━━━━━
▶ WHAT IT DOES NOT CONTAIN
- No behavior — operations come from the projection BDEF.
- No UI — layout comes from annotations/metadata extensions.
- No protocol or URL — that is the service binding (OData V2/V4, UI/Web API).
- No authorization — handled by the BO, CDS access control and roles.
━━━━━━━━━━━━━━━━━━━━
▶ WHY IT IS A SEPARATE OBJECT
One service definition can be bound several times (e.g. V4 UI and V4 Web API bindings), and several service definitions can reuse the same projections. Keeping "what" (definition) and "how" (binding) separate lets you change the protocol without touching the content.
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- In ADT, right-click ZC_PurchReq → New → Service Definition.
- Name: ZUI_PURCHREQ, description "Purchase Request UI service".
- Expose the root and item projections with business aliases (code example).
- Activate. Next step: create the binding (Service Bindings Part 2).
✅ CHECKPOINT: you can write a service definition and explain its role in one sentence: it defines the content of a service, nothing else.
Code example
// ===== Minimal RAP service definition =====@EndUserText.label: 'Purchase Request - UI service'define service ZUI_PURCHREQ { expose ZC_PurchReq as PurchaseRequest; // root projection -> entity set expose ZC_PurchReqItem as PurchaseRequestItem; // child projection -> entity set} // ===== The chain around it =====// ZPR_HEAD / ZPR_ITEM tables// ZR_PurchReq / ZR_PurchReqItem base BO (CDS + BDEF)// ZC_PurchReq / ZC_PurchReqItem projections (CDS + projection BDEF)// ZUI_PURCHREQ service definition <- WHAT is exposed// ZUI_PURCHREQ_O4 service binding <- HOW (OData V4 - UI) // ===== WRONG =====// expose ZR_PurchReq as PurchaseRequest; // base BO exposed: no projection control// expose zpr_head as PurchaseRequest; // tables cannot be exposedReal project scenario
A new team member was asked to "add OData V2 for the old UI5 app" and started copying the whole service definition, projections included. The lead explained that the service definition only describes content; the protocol is a binding property.
He created a second binding (OData V2 – UI) on the existing ZUI_PURCHREQ definition — ten minutes of work, no duplicated objects, and both apps received exactly the same entities.
Common mistakes
- Exposing base R_ views instead of projections.
- Expecting the service definition to control operations or UI.
- Copying service definitions just to change the protocol.
- Technical aliases (ZC_PURCHREQ) instead of business names.
- Forgetting to expose child or navigation target entities.
Best practices
- One service definition per business service and consumer type.
- Expose only projections, with business aliases.
- Keep protocol decisions in bindings.
- Label the service definition with @EndUserText.label.
- Name consistently: ZUI_… for UI services, ZAPI_… for APIs.
Interview angle
Questions: "What is a service definition?", "Service definition vs binding?", "What can be exposed?"
Strong answer: a service definition lists the CDS entities (projections) exposed by a service, with aliases; it has no behavior, UI or protocol — the binding defines protocol (OData V2/V4) and type (UI/Web API). One definition can have several bindings. Base views and tables should not be exposed.
Practice this lesson
Quick check
1. What does a RAP service definition specify?
2. Which object should normally be exposed in a RAP service definition?
3. Which binding type fits a system-to-system integration using a RAP service?
Interview questions
1. Describe the complete path from a RAP business object to a running OData service.
Answer it in your own words first, then compare.
2. What is a RAP service definition, and how does it differ from a service binding?
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.
More lessons in this topic
- Service Definitions Part 2: Exposing Projection Entities as a Business Service
- Service Definitions Part 3: API Boundary, Naming and Versioning
- Service Definitions Part 4: Troubleshooting Activation and Exposure Gaps
- Service Definitions Part 5: UI vs Integration APIs — Reuse or Separate?
- Service Definitions Part 6: Exposing Multiple Entities and Navigation