RAP Basics Part 8: Service Definition, Service Binding and OData Exposure
Expose a RAP BO: service definition (which projections, with aliases), service binding types (OData V2/V4, UI/Web API), publishing locally or via transport, the Fiori Elements preview, released APIs, and why UI and API consumers get separate services.
Explanation
📌 KEY POINTS
✅ Service definition = what is exposed (expose ZC_Travel as Travel); service binding = how (protocol and purpose).
✅ Binding types: OData V4 – UI, OData V2 – UI, OData V4 – Web API, OData V2 – Web API (plus InA/SQL for analytics).
✅ UI bindings carry UI annotations for Fiori Elements; Web API bindings are for machine consumers and ignore UI metadata.
✅ Publishing registers the service (on-premise: local publish in ADT or via /IWFND/V4_ADMIN for V4 service groups) — no SEGW, no /IWFND/MAINT_SERVICE for V4.
⚠️ Exposing the UI projection as the integration API ties partners to UI changes — use a separate API projection and binding.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Parts 2–7 built the BO. Now we make it reachable.
━━━━━━━━━━━━━━━━━━━━
▶ 1. SERVICE DEFINITION
- define service ZUI_TRAVEL { expose ZC_Travel as Travel; expose ZC_Booking as Booking; }
- Also expose value-help views used in the projection if needed.
- Aliases become entity set names in $metadata.
━━━━━━━━━━━━━━━━━━━━
▶ 2. SERVICE BINDING
- Created in ADT from the service definition; choose binding type.
- OData V4 – UI is the default for new Fiori Elements apps (draft works best with V4).
- OData V2 – UI only if the UI technology requires V2.
- Web API: for integration (CPI, external systems); no Fiori preview.
━━━━━━━━━━━━━━━━━━━━
▶ 3. PUBLISHING
- ADT: Publish button on the binding (on-premise: local service endpoint).
- Transport: the binding is transported; in each system it must be published (V4: /IWFND/V4_ADMIN service group, V2: /IWFND/MAINT_SERVICE).
- BTP ABAP Environment: publish and create a communication scenario/arrangement for Web APIs.
━━━━━━━━━━━━━━━━━━━━
▶ 4. PREVIEW AND TEST
- Preview button on an entity set in the binding opens a Fiori Elements app — no UI5 code.
- Check $metadata; test with Gateway client or Postman.
━━━━━━━━━━━━━━━━━━━━
▶ 5. API DESIGN
- One API projection (ZA_* or ZAPI_*) with stable field names, its own service definition and Web API binding.
- Version: new incompatible changes → new service version, not silent changes.
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- Create service definition ZUI_TRAVEL exposing the projection views.
- Create binding ZUI_TRAVEL_O4 (OData V4 – UI) and publish.
- Open the Fiori Elements preview and test create/edit/actions.
- For integration: create ZAPI_TRAVEL service definition + Web API binding.
✅ CHECKPOINT: the preview shows the list report and object page, and $metadata lists Travel and Booking.
Code example
// ===== STEP 1: UI service definition =====@EndUserText.label: 'Travel - UI service'define service ZUI_TRAVEL { expose ZC_Travel as Travel; expose ZC_Booking as Booking; expose /DMO/I_Agency_VH as Agency;} // ===== STEP 2: API projection with stable names (separate from UI) =====@EndUserText.label: 'Travel - API projection'@AccessControl.authorizationCheck: #CHECKdefine root view entity ZA_Travel provider contract transactional_interface as projection on ZI_Travel{ key TravelUUID, TravelID, AgencyID, CustomerID, TotalPrice, CurrencyCode, OverallStatus, LocalLastChangedAt} // ===== STEP 3: API service definition =====@EndUserText.label: 'Travel - Web API'define service ZAPI_TRAVEL { expose ZA_Travel as Travel;} // ===== STEP 4: bindings (created in ADT, not source code) =====// ZUI_TRAVEL_O4 : OData V4 - UI -> Publish -> Preview (Fiori Elements)// ZAPI_TRAVEL_O4 : OData V4 - Web API -> Publish -> test with Postman / CPI// On-premise V4 after transport: /IWFND/V4_ADMIN -> publish service group// Test URL pattern:// /sap/opu/odata4/sap/zui_travel_o4/srvd/sap/zui_travel/0001/TravelReal project scenario
A client exposed its RAP UI service directly to a logistics partner through CPI. Six months later a UI enhancement renamed two fields in the projection for better Fiori labels, and the partner interface failed overnight. The architect introduced a dedicated API projection (provider contract transactional_interface) with its own service definition and Web API binding, documented as a stable contract. From then on, UI changes happened freely in ZC_* views while ZA_* stayed unchanged; incompatible API changes went into a new service version.
Common mistakes
- Using the UI service for integration partners, coupling them to UI changes.
- Forgetting to publish the binding in the target system after transport.
- Choosing OData V2 for new draft-enabled Fiori Elements apps without a reason.
- Not exposing value-help views, so value helps are empty in the app.
- Looking for the V4 service in /IWFND/MAINT_SERVICE instead of /IWFND/V4_ADMIN.
Best practices
- Separate UI (ZUI_*) and API (ZAPI_*) service definitions and bindings.
- Default to OData V4 – UI for new Fiori Elements apps.
- Include publishing steps in the cutover/transport checklist.
- Use the Fiori Elements preview early to validate annotations.
- Version APIs explicitly; never silently change a released contract.
Interview angle
Questions: "Difference between service definition and service binding?", "Which binding type would you choose for a Fiori app and for an integration?", "How do you publish a V4 service on-premise?"
Strong answer: service definition lists the exposed projections; the binding chooses protocol and purpose (V4/V2, UI/Web API). OData V4 – UI for new Fiori Elements apps, Web API bindings on a separate API projection for integration. On-premise V4 services are published via ADT or /IWFND/V4_ADMIN service groups; the binding must be published in each system.
Practice this lesson
Quick check
1. A partner integration needs a stable API on a RAP BO whose Fiori UI changes frequently. What is the recommended exposure?
2. What does a RAP service definition contain?
3. On-premise, after transporting an OData V4 service binding, where is the service group published in the target system?
Interview questions
1. How do you expose a RAP service to Fiori?
Answer it in your own words first, then compare.
2. A RAP UI service (OData V4 – UI binding) was given to a logistics partner for integration. After a UI enhancement renamed fields in the projection, the partner interface failed. How do you set up exposure correctly?
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
- RAP Basics Part 1: RAP Architecture — Layers, Artifacts and When RAP Fits
- RAP Basics Part 10: EML — Entity Manipulation Language
- RAP Basics Part 11: Draft, Locking and Authorization
- RAP Basics Part 2: Data Model Design — Tables, Keys, Administrative Fields and Interface Views
- RAP Basics Part 3: Projection Layer and Metadata Extensions
- RAP Basics Part 4: Implementation Types — Managed, Unmanaged, Additional Save and Unmanaged Save
- RAP Basics Part 5: Root Entity, Child Entity and Composition
- RAP Basics Part 6: Behavior Definition — CRUD, Field Control and Features