What CAP is and why it exists, its architecture ("everything is a service, everything is an event"), the project layout, configuration and profiles, the cds CLI, what cds watch does, Node.js vs Java, and how RAP concepts map to CAP – all on the Order Approval Portal scenario.
Part 1 – Why CAP exists
Requirements on this page
CR-ID | Requirement | What this page gives you |
|---|---|---|
CR1, CR2 | Store approval requests; different APIs for reps and managers | The idea of model-first development; details on 02 · CDS Modeling and 03 · Services |
CR5 | The same service in Java | Node.js vs Java in one table (Part 6); details on 05 · CAP Java |
CR8 | SQLite on the laptop, SAP HANA Cloud in production | Profiles, the inner and outer loop (Parts 3–5); details on 08 · Databases & Deployment |
all | Order Approval Portal end to end | Architecture of the whole app (Part 2) |
Picture the Order Approval Portal: sales reps of a medical-supplies distributor request approval for sales orders above their limit, managers approve or reject them, and everything sits next to S/4HANA on SAP BTP. Written with plain Node.js and Express, this needs a REST or OData server, SQL for every table, paging and filtering, input checks, login and role checks, translated texts, a Fiori-ready $metadata document, and a way to run all of it on a laptop without a cloud database. That is weeks of plumbing before the first business rule.
The SAP Cloud Application Programming Model (CAP) turns this around: you describe the data and the services in CDS, and the CAP runtime serves them – generic CRUD, OData V4, paging, search, draft, validation, authorization and localisation – out of the box. You write code only where the business is special (for example "approve only orders in status N"). CAP is SAP's recommended pro-code framework for side-by-side apps on SAP BTP, next to ABAP Cloud / RAP for ABAP teams.

1.1 What CAP is – and what it is not
CAP is | CAP is not |
|---|---|
A framework + runtime ( | A product you buy or a BTP service you subscribe to – it is a set of libraries |
Model-first: CDS models are the single source for DB tables, APIs and UI metadata | A code generator that leaves you with thousands of generated lines – CAP interprets the model at runtime |
Opinionated about best practices (UUID keys, managed fields, draft, OData V4) | A lock-in: handlers are plain JavaScript / Java; any npm or Maven library can be used |
Database- and platform-agnostic (SQLite, SAP HANA Cloud, PostgreSQL; Cloud Foundry or Kyma) | Tied to SAP HANA – HANA is the default for production, not a requirement |
1.2 The key qualities CAP promises
- Focus on the domain – capture what the business is about in CDS; the framework handles the rest.
- Served out of the box – generic providers answer most requests without code (03 · Services).
- Grow as you go – start with mocks for the database, users and remote APIs, add real services later through configuration (
cds add …), without changing models or code. - Best practices built in – multitenancy, extensibility, security and observability are framework features, not project code.
Interview tip: "CAP = CDS + generic providers + event handlers + grow-as-you-go configuration." Say that in one sentence, then give one concrete example from your project.
Part 2 – Architecture: everything is a service, everything is an event
CAP has one central abstraction: the service. Your ManagerService is a service; the database is a service (db); the S/4HANA Sales Order API is a (remote) service; the message broker is a service. Every request that reaches a service is an event – READ, CREATE, UPDATE, DELETE, a custom action like approve, or an asynchronous message like SalesOrder.Created. Handlers subscribe to these events in three phases: before, on and after.

2.1 The layers of a CAP app
Layer | What lives there | Order Approval Portal |
|---|---|---|
Protocol adapters | Turn OData V4, REST, GraphQL (plugin) or messages into CAP events |
|
Application services | Your services defined in CDS + generic handlers + your handlers |
|
Domain model | Entities, types, associations in CDS |
|
Secondary services | Database, remote, messaging, auth, audit log – consumed through the same API | SAP HANA Cloud, |
2.2 Why "everything is a service" matters
- One API for all:
await cds.connect.to('db')andawait cds.connect.to('API_SALES_ORDER_SRV')return objects with the samerun,send,emitandonmethods – the CAP-level service integration idea that capire calls "Calesi". - Mocks for free: in development CAP replaces HANA with SQLite, XSUAA with mock users and the S/4HANA API with a local mock filled from CSV – the code does not notice (09 · Remote Services).
- Hexagonal architecture without the boilerplate: business logic talks to ports (services), adapters are configuration.
2.3 The scenario on SAP BTP
Piece | BTP service / runtime | Explained on |
|---|---|---|
Fiori elements apps for reps and managers | HTML5 Application Repository, SAP Build Work Zone | 06 · Fiori Elements & Draft, 08 · Deployment |
CAP service (Node.js or Java) | Cloud Foundry or Kyma runtime | 08 · Deployment |
Own tables (requests, notes, decisions) | SAP HANA Cloud, HDI container | 08 · Databases |
Login, roles Rep / Manager | XSUAA or SAP Cloud Identity Services (IAS + AMS), app router | 07 · Authorization & Security |
Live sales orders and customers | Destination service, Cloud Connector, S/4HANA OData API | 09 · Remote Services |
SalesOrder.Created / OrderApproved | SAP Event Mesh or Advanced Event Mesh | 10 · Messaging |
Order summary with generative AI | Generative AI hub in SAP AI Core | 13 · CAP and Generative AI |
Part 3 – Project layout and configuration
A CAP project is a normal npm (or Maven) project with three folders by convention. Nothing has to be registered: CAP finds models in db/, srv/ and app/ automatically, and a handler file with the same base name as a .cds file in srv/ is picked up as its implementation.
|
3.1 The cds configuration and profiles
All configuration sits in the cds section of package.json (or in .cdsrc.json). Profiles in square brackets switch settings per environment: [development] is active for cds watch, [production] on SAP BTP, and you can define your own such as [hybrid].
|
- The ranges match the CDS 10 line (
@sap/cdsand@sap/cds-dk10.2,@cap-js/sqliteand@cap-js/hana3.x in November 2026;@sap/cds10 accepts Express 4.22+ or 5).cds initwrites the current ones for you. - Facets such as
@cap-js/sqliteand@cap-js/hanaare plugins that configure themselves; often you need nodbentry at all. cds env requires.db(orcds env requires --profile production) prints the effective result – the first command to run when something connects to the wrong place.- Never put credentials into
package.json. On BTP they come from service bindings (VCAP_SERVICESor Kubernetes secrets); locally fromcds bind(.cdsrc-private.json) or a git-ignored.env.
Part 4 – The cds CLI: inner loop and outer loop
@sap/cds-dk (install once with npm i -g @sap/cds-dk) brings the cds command. Think of two loops: the inner loop on your laptop or in SAP Business Application Studio, where every save restarts the app in a second, and the outer loop towards SAP BTP.

Command | What it does | Typical use |
|---|---|---|
cds init order-approval | New project; | Start of every project |
cds add <facet> | Adds a capability: | Grow as you go; |
cds watch | Starts the server on port 4004, deploys the model to SQLite in memory, mock users, restarts on every change | The inner loop |
cds watch --profile hybrid | Same, but with real cloud services bound by | Test against HANA Cloud or a real destination |
cds serve | Starts the server without watching | Production-like local start |
cds compile <model> --to sql | edmx | xsuaa | openapi | mermaid | Shows what CAP generates | Understand and debug the model |
| Deploys only the database part | Persistent local DB, HDI container in hybrid mode |
cds build | Writes deployable artefacts to | Before |
cds up | Build and deploy in one step (Cloud Foundry or Kyma) | Quick deployment from BAS |
cds env | Effective configuration per profile | Debugging configuration |
cds repl | Interactive CAP shell: load a project, try CQL | Learning, quick checks |
cds import <file> | Imports an EDMX / OpenAPI / AsyncAPI definition as CDS | 09 · Remote Services |
cds debug | Starts local or remote debugging (Node.js; Java since cds-dk 8.7) | See also |
Java projects use the same cds CLI for models and facets; to run them use mvn spring-boot:run or mvn cds:watch (05 · CAP Java).
Part 5 – What happens when you type cds watch
Knowing the start-up sequence answers half of all "why does it not work" questions.
Step | What CAP does | What you see in the log |
|---|---|---|
1 · Load | Collects all | [cds] - loaded model from N file(s) |
2 · Connect | Connects the | connect to db > sqlite { url: ':memory:' } |
3 · Deploy | Creates tables and views from the model, loads | /> successfully deployed to in-memory database. |
4 · Serve | Creates each service, attaches handlers from | [cds] - serving ManagerService { impl: 'srv/manager-service.js', path: '/odata/v4/manager' } |
5 · Mock | Mocks required remote services it cannot reach, uses mocked authentication | mocking API_SALES_ORDER_SRV … |
6 · Listen | Index page at | server listening on { url: ' http://localhost:4004' } |
- Exact log texts differ between versions – the order is what matters.
- The step-by-step hands-on walkthrough in SAP Business Application Studio (dev space, template wizard, run configurations) is on BTP Development › 06 · BTP Developer Hands-On, Part 2.
Common mistakes: a handler file whose name does not match the .cds file (logic silently not active – check the impl: in the serving log); a CSV file named without the namespace prefix (table stays empty); expecting data to survive a restart with the in-memory database.
Part 6 – CAP Node.js or CAP Java
CR5 asks for the same service in Java. CAP has two runtimes with the same CDS layer: the models, annotations and generic features are identical, only the handler code differs. Details of Java (Spring Boot, typed accessors, CQN) are on CAP › 05 · CAP Java.

Question | Node.js | Java |
|---|---|---|
Team skills | JavaScript / TypeScript, full-stack | Java, Spring Boot |
Turnaround |
| Maven build + Spring start, slower |
Typing | optional ( | strong, generated accessor interfaces |
Samples and tutorials | most capire samples start in Node.js | Java samples exist for each topic |
Resilience for remote calls | via libraries | built in (feature matrix: retry, circuit breaking) |
Interview tip: "The CDS model is portable, so the choice is about the team and the operations stack, not about features." Name one or two differences from the feature matrix rather than claiming one runtime is better.
Part 7 – CAP for ABAP developers: the RAP mapping
If you know RAP, you already know most CAP ideas – the names differ. Use this table to translate, then learn the differences in the last column.
RAP (ABAP Cloud) | CAP | Difference to remember |
|---|---|---|
CDS view entity ( | CDS | CAP CDS defines tables and views; no separate DDIC table |
Projection view + service definition | service … { entity X as projection on … } | One CDS file can hold the whole service |
Service binding (OData V2 / V4, UI / Web API) | Protocol adapter chosen by annotation ( | No binding artefact |
Behavior definition (managed) | Generic providers – managed by default | No BDEF; capabilities come from annotations |
Behavior pool: validations, determinations, actions | Event handlers before / on / after | JavaScript / Java instead of ABAP; EML ≈ CQL / |
Draft ( |
| No draft table to create |
Authorization master + DCL access control |
| Roles come from XSUAA / IAS, not PFCG |
| aspects | UUID keys by default |
Business events ( |
| 10 · Messaging |
ABAP Unit, test doubles |
| 12 · Testing |
7.1 CAP or RAP for the Order Approval Portal?
- CAP when the extension runs side by side on BTP, the team knows JavaScript or Java, and it needs SaaS / multitenancy, events and open-source libraries – our scenario.
- RAP when the logic sits close to S/4HANA data (on-stack developer extensibility) or the team is ABAP only. The RAP version of the same business is in the RAP section.
- Both produce OData V4 services with Fiori elements annotations; both are SAP's recommended models.
Part 8 – Interview questions
Q1. What is CAP in one sentence, and why would you use it?
A framework and runtime (Node.js or Java) in which you model data and services in CDS and get generic OData / REST providers, persistence, draft, validation, authorization and i18n out of the box, so you write code only for real business logic. It cuts plumbing, enforces best practices and runs the same code with mocks locally and with HANA Cloud, XSUAA and remote APIs on BTP.
Q2. What does "everything is a service" mean?
Application services, the database, remote APIs and the message broker are all CAP services with the same API (run, send, emit, on). Requests are events (READ, CREATE, actions, messages) handled in before / on / after phases. That uniformity lets CAP swap real services for mocks and keeps business logic independent of protocols.
Q3. What happens when you run cds watch?
It loads and compiles all CDS models, connects the db service (SQLite in memory by default), deploys tables and loads CSV data, serves each service with its handlers and protocol adapters, mocks remote services and authentication, and restarts on every file change. The index page on port 4004 links to services, metadata and Fiori previews.
Q4. What is a profile and how do you check the effective configuration?
A named configuration variant in the cds section, e.g. [development], [hybrid], [production]. cds watch uses development, BTP uses production, --profile hybrid mixes local app and cloud services. cds env requires --profile <p> shows the resolved result.
Q5. What is "grow as you go"?
Start minimal – model, service, SQLite, mock users, mocked remote APIs – and add production qualities with cds add hana, cds add xsuaa, cds add mta, cds add multitenancy and so on. Configuration changes; models and handlers stay the same.
Q6. Where do credentials come from in a CAP app?
Never from package.json. On BTP from service bindings (VCAP_SERVICES on Cloud Foundry, secrets on Kyma); locally from cds bind (stored in the git-ignored .cdsrc-private.json) or a git-ignored .env.
Q7. CAP Node.js or Java – how do you decide?
By team skills and operations: the CDS layer and generic features are the same. Node.js gives the fastest inner loop and most samples; Java gives Spring Boot integration, strong typing and built-in resilience for remote calls.
Q8. Map RAP terms to CAP.
CDS view entity → CDS entity; projection + service definition → service with projections; service binding → protocol adapter; managed BDEF → generic providers; behavior pool → event handlers; draft → @odata.draft.enabled; DCL → @restrict where; EML → CQL and srv.send.
Q9. Scenario: your custom logic is not executed at all. What do you check first?
The serving log: does it show impl: 'srv/manager-service.js' for the service? If not, the file name does not match the .cds file or @impl points elsewhere. Then check the event and entity names in the handler registration, and that the class returns super.init().
Q10. Scenario: the team wants to start the Order Approval Portal tomorrow but HANA Cloud and XSUAA are not provisioned yet. What do you tell them?
Start anyway: cds init, model, services and CSV data run on SQLite in memory with mock users and a mocked S/4HANA API. When the BTP services arrive, cds add hana,xsuaa,mta and cds bind switch the same code to the cloud – that is the grow-as-you-go principle.
🏠 Start Here · 02 · CDS Modeling ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC
Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | EHS ABAP | HR ABAP | BW | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP