CAP
BTP & Integrationintermediate

BTP CAP Part 2: Building and Exposing Services with CDS

Key takeaway

Design CAP services: projections on domain entities, service-level exposure choices (read-only, restricted fields), annotations for OData and UI, mock data, hybrid testing against real BTP services with cds bind, and database deployment with cds deploy.

Explanation

📌 KEY POINTS
✅ Services expose projections of domain entities tailored to consumers (fields, read-only, filters).

✅ Annotations (@readonly, @insertonly, UI annotations) shape OData and Fiori behavior.

✅ CSV files in db/data provide mock data; cds deploy writes to the target database.

✅ cds bind connects local runs to real BTP services (e.g. HANA Cloud, XSUAA) for hybrid testing.

⚠️ Exposing domain entities one-to-one to every consumer leaks internal fields and couples UIs to the model.

━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE

Part 1 introduced CAP. Now services.

━━━━━━━━━━━━━━━━━━━━
▶ 1. SERVICE DESIGN

  • One service per consumer/use case.

━━━━━━━━━━━━━━━━━━━━
▶ 2. PROJECTIONS

  • Select fields, exclude, rename.

━━━━━━━━━━━━━━━━━━━━
▶ 3. ANNOTATIONS

  • Access, UI, OData.\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 4. DATA\n• CSV mock data; cds deploy.

━━━━━━━━━━━━━━━━━━━━
▶ 5. HYBRID TESTING

  • cds bind; profile hybrid.

━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP

  1. Create AdminService and CatalogService.
  2. Add @readonly and excluding.
  3. Test locally, then hybrid with cds bind.

✅ CHECKPOINT: catalog users can't see cost fields.

Code example

ABAP Code
===== srv/services.cds =====using my.bookshop as my from '../db/schema';service CatalogService {  @readonly entity Books as projection on my.Books excluding { createdBy, modifiedBy, cost };}service AdminService { entity Books as projection on my.Books; } ===== HYBRID =====cds bind -2 my-hana    # binds to HANA Cloud service instancecds watch --profile hybridcds deploy --to hana   # deploy schema

Real project scenario

A Fiori app exposed the full Books entity including internal cost fields. Introducing a CatalogService projection excluding them and a separate AdminService fixed the leak.

Common mistakes

  • One service for all.
  • Exposing internal fields.
  • No mock data.
  • Testing only with SQLite.
  • UI logic in handlers.

Best practices

  • Consumer-specific services.
  • Projections with excluding.
  • CSV data.
  • Hybrid tests.
  • Use annotations.

Interview angle

Questions: "How do you design CAP services?", "What is a projection?", "What is hybrid testing?"
Strong answer: service design, projections, annotations, data, cds bind.

Practice this lesson

Quick check

1. A Fiori app exposes internal cost fields because the service exposes the full entity. What is the CAP fix?

2. Which command is used to bind a locally running CAP application to a real service instance (such as a database or destination) provisioned in Cloud Foundry, enabling hybrid testing?

3. What does the 'cds deploy' command primarily accomplish in a CAP project?

Interview questions

1. Design CAP services for a catalog app used by end users and administrators.

Answer it in your own words first, then compare.

2. How would you apply CAP in a real SAP project? Walk through the design or implementation approach.

Answer it in your own words first, then compare.

Practice more with Interview AI →

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

Interview questions on this topic

Related SAP topics