ERPClimb logoERPClimb
CAP
BTP & Integrationbeginner 6 min read

BTP CAP Part 1: What CAP Is and Why It Matters on SAP BTP

Free sample lesson · open to everyone

Key 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 structure, local development with cds watch, and how it deploys to BTP.

In this lessonShow sections

Visual overview

CAPFrom model to running serviceThe CAP development loop1Initialize projectdb, srv, app folderscds init2Model data & serviceCDS entities and projections.cds3Run locallySQLite + OData served automaticallycds watch4Add business logicHandlers only where neededsrv/*.jsDeploy to BTPHANA Cloud, XSUAA, MTAcf deployTip: let CAP handle CRUD — write code only for real business logic.

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

BTP ACADEMY · PART 1 · Architecture hierarchyERPClimb.com

CAP application building blocks

CAP · Chapter-specific technical teaching map

Architecture hierarchy

1Top level

Domain CDS / db

2Related level

Service definitions / srv

3Related level

Handlers & policies

4Related level

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…

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

Code example

ABAP Code
===== 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 Foundry

Watch 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?

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

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.