Learn SAP Free
Back to Dashboard
SAP BTP

SAP CAP Model Explained – Build Cloud Apps on BTP with Node.js

Daksh | July 25, 2026 | 10 min read

SAP CAP Model on BTP

If you are learning SAP BTP and wondering how to actually build cloud applications on it, the answer is CAP — the Cloud Application Programming Model. CAP is SAP’s official framework for building enterprise-grade cloud applications. It is the recommended way to develop new applications on SAP Business Technology Platform, and it is quickly becoming the most in-demand skill in the SAP developer market.

Before CAP existed, building cloud applications on SAP involved dealing with a lot of boilerplate code — setting up databases, writing REST APIs manually, handling authentication, managing multi-tenancy, and connecting to S/4HANA backends. Developers spent more time on infrastructure code than on actual business logic.

CAP changes that completely. It provides a high-level framework where you define your data model and business logic, and CAP automatically generates the database tables, REST/OData APIs, authentication setup, and even the deployment configuration. You focus on WHAT your application should do, and CAP handles HOW it should run.

In this tutorial, we will understand what CAP is, why it matters, how its architecture works, and walk through building a simple application step by step.


What is SAP CAP?

CAP stands for Cloud Application Programming Model. It is an open-source framework developed by SAP for building cloud-native applications that run on SAP BTP.

Think of CAP as a recipe kit for building cloud applications. Instead of buying individual ingredients and figuring out the recipe yourself, CAP gives you a structured kit with pre-measured ingredients and clear instructions. You just follow the steps and get a professional-quality application.

Key Features of CAP:

  • CDS (Core Data Services): A modeling language to define your data models and services declaratively
  • Built-in OData/REST APIs: Your services are automatically exposed as OData or REST APIs
  • Database Agnostic: Works with SAP HANA, SQLite, PostgreSQL — switch databases without changing code
  • Multi-Tenancy Support: Built-in support for SaaS applications serving multiple customers
  • Authentication & Authorization: Integrated with SAP BTP security services (XSUAA)
  • Event-Driven Architecture: Support for asynchronous messaging and event handling

There are several reasons why every SAP developer needs to learn CAP right now:

1. SAP’s Official Recommendation

SAP has officially declared CAP as the standard for building new cloud applications. Whether you are building extensions for S/4HANA Cloud, standalone BTP apps, or side-by-side extensions, SAP recommends CAP.

2. Clean Core Strategy

With SAP’s push for Clean Core (keeping the S/4HANA core system modification-free), all custom development is moving to BTP. CAP is the primary tool for building these BTP-based extensions.

3. Job Market Demand

Search any SAP job portal in 2026 and you will find that “SAP CAP” or “CAP Model” appears in most BTP developer job descriptions. Companies migrating to S/4HANA Cloud need developers who can build extensions on BTP using CAP.

4. Full-Stack Simplicity

CAP lets a single developer build the complete backend — data model, business logic, API layer, and deployment — without needing separate teams for database design, API development, and DevOps.


CAP Architecture — How It Works

A CAP application has three main layers:

1. Data Model Layer (CDS Models)

You define your database tables using CDS (Core Data Services) — a simple, human-readable modeling language. No SQL scripts, no manual table creation.

namespace learnsapfree.bookshop;

entity Books {
    key ID    : Integer;
    title     : String(200);
    author    : String(100);
    price     : Decimal(10,2);
    stock     : Integer;
    category  : String(50);
}

entity Orders {
    key ID    : Integer;
    book      : Association to Books;
    quantity  : Integer;
    orderDate : Date;
    status    : String(20) default 'NEW';
}

That is it. These few lines define two database tables with all their fields, data types, primary keys, and even a foreign key relationship between Orders and Books. CAP will create the actual database tables automatically when you deploy.

2. Service Layer (CDS Services)

You define which data should be exposed as APIs:

using learnsapfree.bookshop as db from '../db/schema';

service CatalogService {
    entity Books as projection on db.Books;
    entity Orders as projection on db.Orders;
}

This creates a fully functional OData V4 service with CRUD (Create, Read, Update, Delete) operations for both Books and Orders. No Express.js routes, no controller files, no manual API coding.

3. Custom Logic Layer (Event Handlers)

When you need business logic beyond simple CRUD, you add event handlers:

const cds = require('@sap/cds');

module.exports = class CatalogService extends cds.ApplicationService {

    init() {
        const { Books, Orders } = this.entities;

        // Validate stock before placing an order
        this.before('CREATE', Orders, async (req) => {
            const { book_ID, quantity } = req.data;
            const book = await SELECT.one.from(Books).where({ ID: book_ID });

            if (!book) {
                req.error(404, `Book with ID ${book_ID} not found`);
            }
            if (book.stock < quantity) {
                req.error(409, `Not enough stock. Available: ${book.stock}`);
            }
        });

        // Reduce stock after order is created
        this.after('CREATE', Orders, async (data, req) => {
            const { book_ID, quantity } = data;
            await UPDATE(Books).set({
                stock: { '-=': quantity }
            }).where({ ID: book_ID });
        });

        return super.init();
    }
};

This handler checks if enough stock is available before allowing an order, and automatically reduces the stock after the order is placed. Clean, readable, and maintainable.


Setting Up Your First CAP Project

Prerequisites

  • Node.js (version 18 or higher)
  • SAP Business Application Studio or VS Code with SAP CDS extension
  • npm (comes with Node.js)

Step 1: Install CAP CLI

npm install -g @sap/cds-dk

Step 2: Create a New Project

cds init my-bookshop
cd my-bookshop
npm install

This creates a project with the following structure:

my-bookshop/
├── app/           # Frontend (UI5/Fiori) — optional
├── db/            # Data models (CDS files)
├── srv/           # Service definitions and logic
├── package.json   # Project configuration
└── README.md

Step 3: Define Your Data Model

Create db/schema.cds:

namespace learnsapfree.bookshop;

entity Books {
    key ID    : Integer;
    title     : String(200);
    author    : String(100);
    price     : Decimal(10,2);
    stock     : Integer;
}

Step 4: Define Your Service

Create srv/catalog-service.cds:

using learnsapfree.bookshop as db from '../db/schema';

service CatalogService {
    @readonly entity Books as projection on db.Books;
}

Step 5: Add Sample Data

Create db/data/learnsapfree.bookshop-Books.csv:

ID;title;author;price;stock
1;Clean ABAP;Robert C. Martin;2500.00;50
2;SAP BTP in Practice;Thomas Jung;3200.00;30
3;ABAP to the Future;Paul Hardy;2800.00;45
4;SAP Fiori Implementation;Bince Mathew;3500.00;20
5;Learning SAP CAP;Daksh Dedha;1500.00;100

Step 6: Run the Application

cds watch

Open your browser and go to http://localhost:4004. You will see your OData service running with all five books available as a REST API. You can query, filter, sort, and paginate the data using standard OData URL parameters.

http://localhost:4004/catalog/Books              → All books
http://localhost:4004/catalog/Books?$top=3        → First 3 books
http://localhost:4004/catalog/Books(1)            → Book with ID 1
http://localhost:4004/catalog/Books?$filter=price gt 3000  → Books over 3000

CDS Query Language (CQL) — Writing Queries in CAP

CAP provides its own query language that works across all databases:

// Read all books
const books = await SELECT.from(Books);

// Read specific book
const book = await SELECT.one.from(Books).where({ ID: 1 });

// Read with filter
const expensive = await SELECT.from(Books).where({ price: { '>=': 3000 } });

// Count books
const count = await SELECT.one.from(Books).columns('count(*) as total');

// Update a book
await UPDATE(Books).set({ price: 2999 }).where({ ID: 1 });

// Delete a book
await DELETE.from(Books).where({ ID: 5 });

// Insert a new book
await INSERT.into(Books).entries({
    ID: 6, title: 'New Book', author: 'Author', price: 1000, stock: 10
});

The beauty of CQL is that it looks almost like natural English. And it works the same whether your database is SQLite (for local development) or SAP HANA (for production). No database-specific SQL needed.


CAP vs Other Approaches — Why CAP Wins

FeatureCAPManual Node.js + ExpressTraditional ABAP
Data ModelCDS (declarative)Manual SQL scriptsSE11 Dictionary
API CreationAutomatic OData/RESTManual route definitionsICF/Gateway setup
AuthenticationBuilt-in XSUAAManual JWT handlingSU01/Roles
Multi-tenancyBuilt-in supportCustom implementationNot applicable
Database SwitchChange config, no code changeRewrite queriesNot possible
Deploymentcds deployCustom Docker/CF setupTransport system
Learning CurveMediumHighHigh

Deploying to SAP BTP Cloud Foundry

When your application is ready for production, you deploy it to SAP BTP:

Step 1: Add HANA Database Support

cds add hana --for production

Step 2: Add XSUAA (Authentication)

cds add xsuaa --for production

Step 3: Build and Deploy

cds build --production
cf login
cf push

CAP generates all the necessary deployment descriptors (mta.yaml, xs-security.json) automatically. You do not need to write deployment configurations manually.


Common Mistakes to Avoid

1. Skipping CDS Modeling and Writing Raw SQL

CAP is designed to work with CDS models. If you bypass CDS and write raw SQL, you lose all the automatic API generation, validation, and database-agnostic benefits.

2. Putting Business Logic in the CDS File

CDS files are for data modeling and service definitions only. Business logic (validations, calculations, side effects) should go in JavaScript/TypeScript event handlers.

3. Not Using cds watch During Development

The cds watch command provides hot-reload — it automatically restarts your server when you change any file. Without it, you have to manually restart the server after every change, which slows down development significantly.

4. Ignoring the Built-in Generic Handlers

CAP provides generic CRUD handlers out of the box. Many beginners write custom CREATE, READ, UPDATE, DELETE handlers from scratch when CAP already handles these automatically. Only add custom handlers when you need additional business logic.


Interactive Checkpoints

🙋‍♂️ Checkpoint 1: What is CDS in the context of SAP CAP?
CDS stands for Core Data Services. It is a declarative modeling language used in CAP to define data models (database tables), service definitions (APIs), and even authorization rules. Instead of writing SQL scripts to create tables and Express routes to create APIs, you write simple CDS files and CAP generates everything automatically. CDS is database-agnostic, meaning the same CDS model works with SQLite, SAP HANA, and PostgreSQL.
🙋‍♂️ Checkpoint 2: How does CAP handle database switching between development and production?
During local development, CAP uses SQLite (a lightweight file-based database) by default. When you deploy to production on SAP BTP, you switch to SAP HANA by adding the HANA configuration with cds add hana. The key point is that your application code and CDS models do not change at all. CAP's database abstraction layer translates your CQL queries into the appropriate native SQL for whatever database is configured. This means you develop and test locally with SQLite, and deploy to production with HANA, without modifying a single line of business logic.
🙋‍♂️ Checkpoint 3: Why is CAP important for SAP's Clean Core strategy?
SAP's Clean Core strategy means keeping the core S/4HANA system free of custom modifications. All custom extensions and applications should be built outside the core — on SAP BTP. CAP is the primary framework for building these BTP-based extensions. It provides built-in connectivity to S/4HANA APIs, supports side-by-side extension patterns, and follows SAP's recommended architecture for cloud-native development. Without CAP knowledge, developers cannot participate in the Clean Core extension model that SAP is pushing across all customer implementations.

Summary

SAP CAP is the most important skill for any SAP developer looking to work with cloud technologies. It simplifies cloud application development by letting you define data models and services declaratively, while handling all the infrastructure complexity automatically.

The framework is built around three simple concepts: define your data with CDS, expose it as services with CDS, and add custom business logic with JavaScript event handlers. Everything else — database creation, API generation, authentication, deployment — is handled by CAP.

Start by installing the CDS toolkit, create a simple bookshop project, and run it locally with cds watch. Once you are comfortable with the basics, explore advanced topics like remote service consumption, event-driven architecture, and multi-tenant SaaS applications. The SAP developer job market in 2026 rewards CAP skills very generously.

Daksh Dedha - SAP Technical Consultant

Written by Daksh Dedha

SAP Technical Consultant

Daksh is an SAP Technical Consultant specializing in ABAP programming, SAP S/4HANA migrations, Fiori development, and BTP cloud architecture. He authors free, hands-on tutorials to make enterprise SAP education accessible to all developers.

Test Your Knowledge

SAP Challenge Question 1 of 10

Loading question...

Found this tutorial useful? Share it with your SAP development team.