BTP CAP Part 1: What CAP Is and Why It Matters on SAP BTP
Free sample lesson · open to everyone
The SAP Cloud Application Programming Model (CAP) is SAP's framework for building enterprise services and apps on BTP with Node. js or Java. Learn its idea — model with CDS, get services and persistence generated, add custom logic only where needed — the project structure, local development with cds watch, and how it deploys to BTP.
In this lessonShow sectionsHide sections
Visual overview
The situation: a real project scenario
A retail customer wanted a custom app for store audits. With CAP, a working OData service with persistence ran locally on day one; the team focused on validation logic and a Fiori elements UI instead of plumbing.
Explanation
This series on CAP covers seven parts — what CAP is, building and exposing services, securing services, multitenancy and deployment, domain modeling, service handlers and transactions, and OData services with actions, functions and draft — and this lesson is the first.
CAP is best understood as CDS models, covering both data and services, combined with generic runtime providers and whatever custom handlers you write on top. A typical project is laid out with db/ holding the domain model, srv/ holding services and handlers, and app/ holding the user interfaces.
Running cds watch locally serves the project with an in-memory SQLite database and automatically exposes OData, with no extra setup needed for local development. When it's time to move toward BTP deployment, cds add brings in production features such as HANA, XSUAA, MTA and multitenancy support.
The core risk CAP is designed to avoid is writing custom code for things it already provides generically — CRUD operations, paging, filtering — since reimplementing those by hand just adds bugs and ongoing maintenance. The underlying philosophy is model-first: generic providers handle the standard behavior, and custom code is reserved for genuine business logic.
A good way to get a feel for this quickly is running cds init followed by cds watch, which produces a working OData service within minutes, with logic layered on afterward. One thing to avoid is scattering hand-written SQL throughout the project, since that bypasses CAP's database-agnostic runtime and ties the project to a specific database unnecessarily.
In practice, this means running cds init bookshop and moving into that folder, adding an entity in db/schema.cds and a service in srv/, and then running cds watch — the result being that a request like GET /odata/v4/catalog/Books returns real data.
Expert visual walkthrough
CAP application building blocks
CAP · Chapter-specific technical teaching map
Architecture hierarchy
Domain CDS / db
Service definitions / srv
Handlers & policies
Database / consumer
Tutor's chapter takeaway
The SAP Cloud Application Programming Model (CAP) is SAP's framework for building enterprise services and apps on BTP with Node.js or Java. Learn its idea — model with CDS, get services and persistence generated, add custom logic only where needed — the project…
In a real project
A retail customer wanted a custom app for store audits. With CAP, a working OData service with persistence ran locally on day one; the team focused on validation logic and a Fiori elements UI instead of plumbing.
Watch out for
• Writing custom code for what CAP already provides generically (CRUD, paging, filtering) adds bugs and maintenance burden — rely on the generic providers and add code only for real business logic. • Mixing hand-written SQL…
Code example
===== START =====npm i -g @sap/cds-dk # installs the CDS development kit globally, giving you the cds CLIcds init bookshop && cd bookshop # scaffolds a new CAP project with the standard db/srv folder layoutcds watch # http://localhost:4004 - starts the dev server with live reload and an in-memory SQLite DB ===== db/schema.cds =====namespace my.bookshop;using { cuid, managed } from '@sap/cds/common';entity Books : cuid, managed { title : String(111); stock : Integer; } // cuid adds a generated UUID key; managed adds createdAt/createdBy/modifiedAt/modifiedBy automatically ===== srv/cat-service.cds =====using my.bookshop as my from '../db/schema'; // imports the data model defined in schema.cds under the alias 'my'service CatalogService { entity Books as projection on my.Books; } // exposes Books as an OData service entity with default CRUD ===== PRODUCTION =====cds add hana,xsuaa,mta && mbt build && cf deploy mta_archives/*.mtar # adds HANA DB, XSUAA auth and MTA config, builds the deployable archive, then deploys it to Cloud FoundryWatch out
Common mistakes
- Writing custom code for what CAP already provides generically (CRUD, paging, filtering) adds bugs and maintenance burden — rely on the generic providers and add code only for real business logic.
- Mixing hand-written SQL throughout the app bypasses CAP's database-agnostic runtime and locks the app to one database — use CDS queries instead.
- Skipping local testing with cds watch and deploying straight to BTP slows down the feedback loop considerably — develop and test locally first.
- Building without mock/test data (CSV) makes early development and demos harder than necessary — seed local SQLite with CSV test data.
- Deploying manually instead of through an MTA-based pipeline makes deployments inconsistent across environments — use MTA-based deployment to BTP.
Do this
Best practices
- Model first with CDS and let CAP's generic providers handle CRUD, paging and filtering; write custom code only for business logic.
- Use CDS queries through the generic runtime rather than hand-written SQL.
- Develop and test locally with cds watch before deploying to BTP.
- Seed local development with CSV mock data for fast, repeatable testing.
- Deploy to BTP via MTA-based pipelines for consistency across environments.
In the interview
Interview angle
Questions: "What is CAP?", "What does cds watch do?", "How do you deploy CAP to BTP?"
Strong answer: CDS models, generic providers, structure, local dev, deployment.
Practice this lesson
Quick check
0 of 3 questions attempted
Question 1 of 3
What is the primary purpose of running the 'cds watch' command during local CAP development?
Question 2 of 3
What is the core idea of SAP CAP?
Question 3 of 3
In the SAP Cloud Application Programming Model (CAP), which domain-specific language is primarily used to define data models and service definitions?
Practise this in an interview
Answer in your own words and get instant feedback, the way an interviewer would judge it.
1A retail customer wants a custom store-audit app on BTP. Explain why you'd use CAP and how you'd start.
2What are the core concepts of CAP, and how would you explain them clearly in an SAP interview?
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
Interview questions on this topic
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.