Creating Your First CAP Project: A Step-by-Step Walkthrough

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

  1. Log in to your SAP BTP cockpit and open your subaccount.
  2. Go to “Service Marketplace” → subscribe to SAP Business Application Studio if not already.
  3. Open BAS and click Create Dev Space. Choose the Full-Stack Cloud Application or CAP dev space type.
  4. 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

  1. In BAS open a terminal (Terminal → New Terminal).
  2. Create a project folder and move into it:
mkdir first-cap && cd first-cap
  1. 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 artifacts
  • srv/ — service definitions and handlers
  • app/ — 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

  1. Ensure @sap/cds is in package.json. If not:
npm init -y
npm install @sap/cds --save
  1. 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:

  1. Provision an SAP HANA instance and HDI container in your BTP subaccount.
  2. Create a service key and bind it to your application or set credentials in BAS.
  3. In package.json or cds config, declare the HANA binding:
"cds": {
  "requires": {
    "db": {
      "kind": "hana",
      "model": "db"
    }
  }
}
  1. 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)

  1. Prepare mta.yaml (if needed) or use cf tools.
  2. Add a manifest or MTA module describing the CAP application and bound services (HANA, destination, etc.).
  3. 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 watch for 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

  • cds commands not found → ensure @sap/cds is installed and your PATH points to project node_modules/.bin.
  • HANA deployment errors → verify HDI container permissions and service bindings.
  • Missing entities in service → run cds compile to confirm CDS compiled output.

Best Practices

  • Keep db, srv, and app modular 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

  1. Model Books in CDS (db/schema.cds).
  2. Expose CatalogService (srv/cat-service.cds).
  3. Add handler to validate stock (srv/cat-service.js).
  4. Run locally with cds watch, test POST and GET.
  5. 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 to CatalogService.
  • 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.

you may be interested in this blog here:-

Don’t Fear the Update: Navigating the Challenges of how to implement sap note

Five Top Technology Investment Drivers for 2024

How many dollars worth of RSU does Salesforce typically offer an MTS (experienced hire) on joining?

Integration cloud system to HANA Cloud Platform using Cloud Connector

₹25,000.00

SAP SD S4 HANA

SAP SD (Sales and Distribution) is a module in the SAP ERP (Enterprise Resource Planning) system that handles all aspects of sales and distribution processes. S4 HANA is the latest version of SAP’s ERP suite, built on the SAP HANA in-memory database platform. It provides real-time data processing capabilities, improved…
₹25,000.00

SAP HR HCM

SAP Human Capital Management (SAP HCM)  is an important module in SAP. It is also known as SAP Human Resource Management System (SAP HRMS) or SAP Human Resource (HR). SAP HR software allows you to automate record-keeping processes. It is an ideal framework for the HR department to take advantage…
₹25,000.00

Salesforce Administrator Training

I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
₹25,000.00

Salesforce Developer Training

Salesforce Developer Training Overview Salesforce Developer training advances your skills and knowledge in building custom applications on the Salesforce platform using the programming capabilities of Apex code and the Visualforce UI framework. It covers all the fundamentals of application development through real-time projects and utilizes cases to help you clear…
₹25,000.00

SAP EWM

SAP EWM stands for Extended Warehouse Management. It is a best-of-breed WMS Warehouse Management System product offered by SAP. It was first released in 2007 as a part of SAP SCM meaning Supply Chain Management suite, but in subsequent releases, it was offered as a stand-alone product. The latest version…
₹25,000.00

Oracle PL-SQL Training Program

Oracle PL-SQL is actually the number one database. The demand in market is growing equally with the value of the database. It has become necessary for the Oracle PL-SQL certification to get the right job. eLearning Solutions is one of the renowned institutes for Oracle PL-SQL in Pune. We believe…
₹25,000.00

Pega Training Courses in Pune- Get Certified Now

Course details for Pega Training in Pune Elearning solution is the best PEGA training institute in Pune. PEGA is one of the Business Process Management tool (BPM), its development is based on Java and OOP concepts. The PAGA technology is mainly used to improve business purposes and cost reduction. PEGA…
₹27,000.00

SAP PP (Production Planning) Training Institute

SAP PP Training Institute in Pune SAP PP training (Production Planning) is one of the largest functional modules in SAP. This module mainly deals with the production process like capacity planning, Master production scheduling, Material requirement planning shop floor, etc. The PP module of SAP takes care of the Master…

X
WhatsApp WhatsApp us
Call Now Button