Getting hands-on with the SAP Cloud Application Programming Model (CAP) is the fastest way to learn modern SAP development. This walkthrough will take you from zero to a running CAP service using SAP Business Application Studio (BAS). It’s written so beginners and company teams can follow the exact commands and workflow to scaffold, run, and deploy a small CAP application.
Before you begin, if you want structured lessons that cover SAP fundamentals, consider taking a practical SAP course. Also, because CAP often uses SAP HANA for persistence, you may want to review SAP HANA basics later.
Prerequisites
- An SAP BTP account with a subaccount and entitlements.
- SAP Business Application Studio available in your BTP subaccount.
- Basic knowledge of JavaScript/Node.js (recommended) or Java.
- Git and a terminal experience.
- Optional: an SAP HANA instance (for database persistence).
Step 1 — Create a Dev Space in SAP Business Application Studio
- Log in to your SAP BTP cockpit and open your subaccount.
- Go to “Service Marketplace” → subscribe to SAP Business Application Studio if not already.
- Open BAS and click Create Dev Space. Choose the Full-Stack Cloud Application or CAP dev space type.
- Name it (e.g.,
cap-dev) and create. Wait until the dev space is RUNNING, then open it.
Step 2 — Scaffold a New CAP Project
- In BAS open a terminal (Terminal → New Terminal).
- Create a project folder and move into it:
mkdir first-cap && cd first-cap
- Initialize a CAP project:
cds init
This creates a minimal structure. To scaffold a fuller starter project you can use:
cds add samples
or use the Yeoman/Fiori generators from BAS to add UI templates.
Step 3 — Understand the Project Structure
After scaffolding, you should see folders:
db/— CDS models and database artifactssrv/— service definitions and handlersapp/— optional UI apps (Fiori)package.json— project metadata and scripts
Step 4 — Define Your Data Model (CDS)
Create a file db/schema.cds and add a simple entity:
namespace my.bookshop;
entity Books {
key ID : UUID;
title : String;
author : String;
stock : Integer;
}
CDS (Core Data Services) is the single source of truth for your model. It compiles to DB artifacts and drives the service layer.
Step 5 — Expose a Service
Create srv/cat-service.cds:
using my.bookshop from '../db/schema';
service CatalogService {
entity Books as projection on my.bookshop.Books;
}
This exposes an OData endpoint /catalog/Books.
Step 6 — Add Simple Handler Logic (Optional)
If you want to run custom logic, create srv/cat-service.js:
const cds = require('@sap/cds');
module.exports = cds.service.impl(async function() {
this.before('CREATE', 'Books', (req) => {
if (!req.data.title) req.reject(400, 'Title is required');
});
});
Handlers let you enforce validations, trigger side effects, or call external APIs.
Step 7 — Install Dependencies and Run Locally
- Ensure
@sap/cdsis inpackage.json. If not:
npm init -y
npm install @sap/cds --save
- Start the CAP server in watch mode:
cds watch
Open the provided URL or use the BAS preview to view OData metadata at /catalog/$metadata and test endpoints with a REST client (e.g., Postman) or browser.
Step 8 — Use SQLite for Local Persistence (Quick Start)
By default, cds watch runs without a DB. For local testing add SQLite:
npm i sqlite3 --save
Create package.json cds configuration or add cds.requires.db = { kind: 'sqlite', credentials: { database: ':memory:' } } in .cdsrc.json for quick local persistence.
Step 9 — Connect to SAP HANA (Dev/Test)
When you’re ready to use SAP HANA:
- Provision an SAP HANA instance and HDI container in your BTP subaccount.
- Create a service key and bind it to your application or set credentials in BAS.
- In
package.jsonor cds config, declare the HANA binding:
"cds": {
"requires": {
"db": {
"kind": "hana",
"model": "db"
}
}
}
- Run:
cds deploy --to hana:your_hana_service_key
BAS simplifies binding and deployment via the Environment panel if you prefer a GUI.
Step 10 — Deploy to SAP BTP (Cloud Foundry)
- Prepare
mta.yaml(if needed) or usecftools. - Add a manifest or MTA module describing the CAP application and bound services (HANA, destination, etc.).
- Use BAS terminal to push:
cf push
or build and deploy via MTA:
mbt build
cf deploy mta_archives/your_app.mtar
Deployment binds your app to runtime services and exposes it under a BTP route.
Step 11 — Test and Monitor
- Use
cds watchfor iterative development (auto-reload). - Use BAS debugging and logs to troubleshoot.
- Check BTP logs (
cf logs <app-name> --recent) after deployment. - Test endpoints, Fiori apps (if any), and business flows.
Troubleshooting Tips
cdscommands not found → ensure@sap/cdsis installed and your PATH points to projectnode_modules/.bin.- HANA deployment errors → verify HDI container permissions and service bindings.
- Missing entities in service → run
cds compileto confirm CDS compiled output.
Best Practices
- Keep
db,srv, andappmodular and version controlled. - Use annotations in CDS for validation and UI hints.
- Write unit tests for handlers using standard Node testing tools.
- Use CI/CD for deployment (mbt, GitHub Actions, or Azure DevOps).
- Start with Node.js runtime if you’re new; Java is a strong alternative for enterprise teams.
Real-World Example: Simple Bookshop Flow
- Model
Booksin CDS (db/schema.cds). - Expose
CatalogService(srv/cat-service.cds). - Add handler to validate stock (srv/cat-service.js).
- Run locally with
cds watch, test POST and GET. - Deploy to BTP with HANA for persistence and access from Fiori UI.
Conclusion and Next Steps
You now have a working CAP project scaffolded, served, and ready to be extended. From here you can:
- Add Fiori Elements UI in
app/and bind it toCatalogService. - Implement authentication and authorization for production readiness.
- Explore persistence optimizations with SAP HANA.
- Strengthen core SAP knowledge through a hands-on SAP course to accelerate your learning curve.
Build one small feature at a time, commit often, and iterate. CAP gives you a clean, productive path into enterprise-grade SAP development — and BAS is the perfect companion to make that journey smooth.

WhatsApp us