// |
| name | sap-cap-capire |
| description | SAP Cloud Application Programming Model (CAP) development skill using Capire documentation. Use when: building CAP applications, defining CDS models, implementing services, working with SAP HANA/SQLite/PostgreSQL databases, deploying to SAP BTP Cloud Foundry or Kyma, implementing Fiori UIs, handling authorization, multitenancy, or messaging. Covers CDL/CQL/CSN syntax, Node.js and Java runtimes, event handlers, OData services, and CAP plugins. |
| license | GPL-3.0 |
| metadata | {"version":"2.0.0","last_verified":"2025-11-27","cap_version":"@sap/cds 9.4.x"} |
# Install CAP development kit
npm i -g @sap/cds-dk
# Create new project
cds init <project-name>
cds init <project-name> --add sample,hana
# Start development server with live reload
cds watch
# Add capabilities
cds add hana # SAP HANA database
cds add sqlite # SQLite for development
cds add xsuaa # Authentication
cds add mta # Cloud Foundry deployment
cds add multitenancy # SaaS multitenancy
cds add typescript # TypeScript support
using { cuid, managed } from '@sap/cds/common';
namespace my.bookshop;
entity Books : cuid, managed {
title : String(111) not null;
author : Association to Authors;
stock : Integer;
price : Decimal(9,2);
}
entity Authors : cuid, managed {
name : String(111);
books : Association to many Books on books.author = $self;
}
using { my.bookshop as my } from '../db/schema';
service CatalogService @(path: '/browse') {
@readonly entity Books as projection on my.Books;
@readonly entity Authors as projection on my.Authors;
@requires: 'authenticated-user'
action submitOrder(book: Books:ID, quantity: Integer) returns String;
}
project/
├── app/ # UI content (Fiori, UI5)
├── srv/ # Service definitions (.cds, .js/.ts)
├── db/ # Data models and schema
│ ├── schema.cds # Entity definitions
│ └── data/ # CSV seed data
├── package.json # Dependencies and CDS config
└── .cdsrc.json # CDS configuration (optional)
| CDS Type | SQL Mapping | Common Use |
|---|---|---|
UUID | NVARCHAR(36) | Primary keys |
String(n) | NVARCHAR(n) | Text fields |
Integer | INTEGER | Whole numbers |
Decimal(p,s) | DECIMAL(p,s) | Monetary values |
Boolean | BOOLEAN | True/false |
Date | DATE | Calendar dates |
Timestamp | TIMESTAMP | Date/time |
using { cuid, managed, temporal } from '@sap/cds/common';
// cuid = UUID key
// managed = createdAt, createdBy, modifiedAt, modifiedBy
// temporal = validFrom, validTo
// srv/cat-service.js
module.exports = class CatalogService extends cds.ApplicationService {
init() {
const { Books } = this.entities;
// Before handlers - validation
this.before('CREATE', Books, req => {
if (!req.data.title) req.error(400, 'Title required');
});
// On handlers - custom logic
this.on('submitOrder', async req => {
const { book, quantity } = req.data;
// Custom business logic
return { success: true };
});
return super.init();
}
}
const { Books } = cds.entities;
// SELECT with conditions
const books = await SELECT.from(Books)
.where({ stock: { '>': 0 } })
.orderBy('title');
// INSERT
await INSERT.into(Books)
.entries({ title: 'New Book', stock: 10 });
// UPDATE
await UPDATE(Books, bookId)
.set({ stock: { '-=': 1 } });
// package.json
{
"cds": {
"requires": {
"db": {
"[development]": {
"kind": "sqlite",
"credentials": { "url": ":memory:" }
},
"[production]": { "kind": "hana" }
}
}
}
}
cds add hana
cds deploy --to hana
db/data/my.bookshop-Books.csv<namespace>-<EntityName>.csv# Add CF deployment support
cds add hana,xsuaa,mta,approuter
# Build and deploy
npm install --package-lock-only
mbt build
cf deploy mta_archives/<project>_<version>.mtar
cds add multitenancy
Configuration:
{
"cds": {
"requires": {
"multitenancy": true
}
}
}
// Service-level
@requires: 'authenticated-user'
service CatalogService { ... }
// Entity-level
@restrict: [
{ grant: 'READ' },
{ grant: 'WRITE', to: 'admin' }
]
entity Books { ... }
cds init [name] # Create project
cds add <feature> # Add capability
cds watch # Dev server with live reload
cds serve # Start server
cds compile <model> # Compile CDS to CSN/SQL/EDMX
cds deploy --to hana # Deploy to HANA
cds build # Build for deployment
cds env # Show configuration
cds repl # Interactive REPL
cds version # Show version info
cuid and managed aspects from @sap/cds/commondb/, services in srv/, UI in app/