Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / CAP / CAP Foundations – What, Why & Architecture

CAP Foundations – What, Why & Architecture

CAP · SAP BTP ·

Open the interactive lesson →
  1. Why CAP exists
  2. Architecture: everything is a service, everything is an event
  3. Project layout and configuration
  4. The cds CLI: inner loop and outer loop
  5. What happens when you type cds watch
  6. CAP Node.js or CAP Java
  7. CAP for ABAP developers: the RAP mapping
  8. Interview questions

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.

Why CAP: you write CDS models, services, annotations and a few handlers; the CAP runtime serves OData, CRUD, paging, draft, validation, authorization and i18n; it plugs into SQLite, HANA Cloud, XSUAA or IAS, destinations and Event Mesh

1.1 What CAP is – and what it is not

CAP is

CAP is not

A framework + runtime (@sap/cds for Node.js, CAP Java SDK on Spring Boot) and a CLI (@sap/cds-dk)

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.

Everything is a service: protocol adapters turn HTTP or messages into events for an application service; it uses database, remote, messaging and platform services through the same API (cds.connect.to, run)

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

/odata/v4/rep, /odata/v4/manager

Application services

Your services defined in CDS + generic handlers + your handlers

RepService, ManagerService

Domain model

Entities, types, associations in CDS

ApprovalRequests, Notes, Decisions

Secondary services

Database, remote, messaging, auth, audit log – consumed through the same API

SAP HANA Cloud, API_SALES_ORDER_SRV, SAP Event Mesh

2.2 Why "everything is a service" matters

  • One API for all: await cds.connect.to('db') and await cds.connect.to('API_SALES_ORDER_SRV') return objects with the same run, send, emit and on methods – 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.

order-approval/
db/
schema.cds                  # domain model (02 · CDS Modeling)
data/                       # CSV initial / test data, e.g. sap.capire.orderapproval-ApprovalRequests.csv
srv/
rep-service.cds             # RepService definition (03 · Services)
manager-service.cds         # ManagerService definition
manager-service.js          # handlers for ManagerService (04 · Custom Logic in Node.js)
external/                   # imported remote APIs, cds import (09 · Remote Services)
app/
requests/                   # Fiori elements app for reps (06 · Fiori Elements & Draft)
inbox/                      # Fiori elements app for managers
test/                         # cds.test specs (12 · Testing)
package.json                  # dependencies + "cds" configuration section
.cdsrc.json                   # optional: cds configuration outside package.json
.cdsrc-private.json           # cds bind results – never commit
xs-security.json, mta.yaml    # created by cds add xsuaa / cds add mta (07, 08)

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].

{
"name": "order-approval",
"dependencies": { "@sap/cds": "^10", "express": "^5" },
"devDependencies": { "@cap-js/sqlite": "^3", "@sap/cds-dk": "^10" },
"cds": {
"requires": {
"db": { "[development]": { "kind": "sqlite" }, "[production]": { "kind": "hana" } },
"auth": { "[development]": { "kind": "mocked" }, "[production]": { "kind": "xsuaa" } },
"API_SALES_ORDER_SRV": { "kind": "odata-v2", "model": "srv/external/API_SALES_ORDER_SRV" }
}
}
}
  • The ranges match the CDS 10 line (@sap/cds and @sap/cds-dk 10.2, @cap-js/sqlite and @cap-js/hana 3.x in November 2026; @sap/cds 10 accepts Express 4.22+ or 5). cds init writes the current ones for you.
  • Facets such as @cap-js/sqlite and @cap-js/hana are plugins that configure themselves; often you need no db entry at all.
  • cds env requires.db (or cds 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_SERVICES or Kubernetes secrets); locally from cds 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.

Project layout and the cds CLI: inner loop cds init, edit, cds watch, test; outer loop cds add, hybrid profile, cds build, mbt build and cf deploy or cds up; helpers cds env, compile, deploy, serve, repl, debug

Command

What it does

Typical use

cds init order-approval

New project; --add sample, --add hana,xsuaa, --java

Start of every project

cds add <facet>

Adds a capability: hana, postgres, sqlite, xsuaa, ias, ams, mta, helm, approuter, multitenancy, data, http, handler, typer …

Grow as you go; cds add --help lists the facets of your version

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 cds bind

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

cds deploy --to sqlite:db.sqlite / --to hana

Deploys only the database part

Persistent local DB, HDI container in hybrid mode

cds build

Writes deployable artefacts to gen/ (gen/srv, gen/db with HDI files)

Before mbt build or a container build

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 debug typed into a running cds watch

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 files from db/, srv/, app/ and plugins, compiles them into one model (CSN)

[cds] - loaded model from N file(s)

2 · Connect

Connects the db service according to the active profile

connect to db > sqlite { url: ':memory:' }

3 · Deploy

Creates tables and views from the model, loads db/data/*.csv

/> successfully deployed to in-memory database.

4 · Serve

Creates each service, attaches handlers from srv/*.js, mounts protocol adapters

[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 http://localhost:4004 with links to services, $metadata, Fiori previews

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.

CAP Node.js vs CAP Java: start, run, handlers, typed access, queries, dev database, ecosystem and when to pick each; models and generic features are the same

Question

Node.js

Java

Team skills

JavaScript / TypeScript, full-stack

Java, Spring Boot

Turnaround

cds watch restarts in about a second

Maven build + Spring start, slower

Typing

optional (cds-typer, TypeScript)

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 (define root view entity)

CDS entity in db/schema.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 (@odata, @rest), path by @path

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 / srv.send

Draft (with draft, draft tables)

@odata.draft.enabled, generated .drafts entity

No draft table to create

Authorization master + DCL access control

@requires / @restrict with where

Roles come from XSUAA / IAS, not PFCG

numbering : managed, admin fields

aspects cuid, managed

UUID keys by default

Business events (RAP business events)

event in CDS + srv.emit

10 · Messaging

ABAP Unit, test doubles

cds.test, mocks

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