Skip to content

Prerequisite

Complete Exercise 1 before starting this exercise.

Exercise 2 - Create an SAP Cloud Application Programming Model Project for SAP HANA Cloud

In this exercise you will use the SAP CAP project wizard in SAP Business Application Studio to scaffold a new CAP Node.js application that is pre-configured to target SAP HANA Cloud as its database. By the end you will have a working project skeleton, a Git repository to track your changes, and a Cloud Foundry login ready for HDI container deployment.

Background

SAP Cloud Application Programming Model (CAP) is SAP's opinionated framework for building full-stack cloud-native applications. Rather than writing raw SQL or low-level service code, you describe your data model and services in CDS (Core Data Services) — a high-level, declarative language — and CAP generates the boilerplate for you: OData endpoints, database tables, service bindings, and more.

By default, CAP uses an in-memory SQLite database for local development. To use SAP HANA Cloud instead, you need to configure the project for HDI (HANA Deployment Infrastructure) — the mechanism that deploys and manages database artifacts inside an isolated HANA container. The CAP wizard handles this configuration for you automatically.

Exercise 2.1 Create the CAP Project

The CAP project wizard in SAP Business Application Studio generates the project skeleton, sets up the package.json with the correct SAP dependencies, and adds the mta.yaml deployment descriptor needed for Cloud Foundry deployment.

Create dev space in SAP Business Application Studio

Dev spaces are like isolated virtual machines in the cloud that can be quickly spun-up. Each dev space type contains tailored tools and pre-installed run-times for a target scenario such as SAP Fiori or mobile development. This simplifies and saves time in setting up the development environment as there's no need to install anything or upgrade; letting developers focus on their business domain, anytime, anywhere.

In this step we will create a new Dev Space configured for SAP Cloud Application Programming Model (CAP) development. If you already have a dev space configured for CAP and HANA development, you can skip this step as each dev space can hold multiple projects.

  1. Go to your SAP Business Technology Platform subaccount and click the Services -> Instances and Subscriptions option.

    Subscriptions

  2. Locate the SAP Business Application Studio entry and click Go to Application

    Go To Application

  3. Choose Create Dev Space. Please NOTE: In the SAP BTP trial and free tier you are limited to only two Dev Spaces and only one can be active at a time. If you have performed other tutorials, you might already have reached your maximum. In that case you might have to delete one of the other dev spaces in order to continue with this tutorial.

    Create Dev Space

  4. Enter any name you wish for your dev space name and choose Full Stack Cloud Application as the kind of application you are creating.

    Create Dev Space

  5. The Dev space will automatically be configured with the most common tools you need for the type of application you choose. However you can also choose additional, optional extensions. Since you want to combine CAP and HANA artifacts in the same project, we would ask that you also choose SAP HANA Calculation View Editor and SAP HANA Tools at minimum.

    Configure Dev Space

  6. Once all selections are completed, press Create Dev Space

    Press Create Dev Space

  7. The Dev Space will then begin starting and the process will take a minute or so as your cloud environment is being created

    Staring Dev Space

  8. Once the Dev Space reaches the green status of RUNNING, you can click on the name of the Dev Space and it will load into the editor within your browser

    Dev Space is Running

  9. You'll be redirected to your newly created SAP Business Application Studio Dev Space. We recommend you bookmark this URL so it's easier for you to access this dev space of your SAP Business Application Studio in the future

    Business Application Studio is running

Configure dev space

Before we create our SAP HANA project, we want to do a few more one-time configuration steps to prepare the Dev Space

  1. In the left side of the Business Application Studio click on the Cloud Foundry targets icon. Depending upon your screensize this option might be behind the expansion three dots (...).

    CF Not Set

  2. Now in the Cloud Foundry Targets window you can expand either Service or Applications and then click on the Logon icon to continue the configuration process

    Login Required

  3. The Cloud Foundry Sign In and Targets window will then open in a side panel of the SAP Business Application Studio. The first input will prompt you for the API endpoint and your credentials

    API Endpoint

  4. The default value proposed is not necessarily the correct value, please confirm. The value can be found in the SAP BTP cockpit at the Subaccount level

    Finding the API Endpoint

  5. Once you have verified the API endpoint, input the email address you used to create your SAP BTP account and password and press Sign In.

    Email

  6. If successful, the next input will ask you for your Organization. In most situations you will have a single choice. But like the API endpoint earlier, if you need to confirm the correct value it will be displayed in the top navigation of the SAP BTP cockpit

    Organization

  7. The final input will ask you for your Space. Press Apply. Space

  8. Upon completion of all the inputs, you should see that the Organization and Space have been set and you will see any service instances or application instances from the target space. It's normal to see less options in this tree display than the screenshot depending upon how much other development you might have already done in your BTP account.

    Org and Space Set Correctly

Create a new project

  1. Return to the Explorer view. From the SAP Business Application Studio Welcome tab, click New Project from Template.

    New project from template

  2. Choose CAP Project and click Start

    Choose CAP Project

  3. Use the following name for your project and click Next

    Name
    MyHANAApp

    This name will be used in different steps. It is recommended that you do not change it unless you remember to replace it in future tasks.

    New CAP Project Name

    Choose Node.js as the runtime. Select SAP HANA Cloud from the database for your application section. Choose Cloud Foundry:MTA Deployment and CI/CD Pipeline Integration under which way to deploy your project. Choose SAP BTP Authorization and Trust Management Service (XSUAA) and SAP Application Router from the productive runtime capabilities for your application section. Press Finish

    New CAP Project Details

  4. The new project should be added to your workspace automatically.

Explore the generated artifacts

  1. The wizard has generated a Multi-target Application with two modules: a database module and a service module. Expand them to familiarize yourself with the basic folder structure.

    New CAP model project structure

  2. The wizard has also populated the mta.yaml configuration file with the necessary dependencies and parameters for each module. Open it in the code editor by right mouse clicking on it and using the Open With menu option to explore it.

    New CAP model project mta.yaml explained

    This file is the deployment descriptor and it is the glue that keeps all the micro-services together as a single application throughout its lifecycle. It declares the modules (applications or micro-services) and their dependencies with other micro-services or backing services. You can also use this file to inject variables into the environment variable VCAP_SERVICES of your application.

    This file is very sensitive to indentation and does not allow for tabs.

Install dependencies

We are using several dependent Node.js modules in our project. They are referenced in the dependencies section of the package.json file we were just editing. These dependencies need to be installed into your project before we can do any testing.

  1. Open a new terminal

    New Terminal

  2. The terminal will open in the bottom right of the Business Application Studio

    Terminal in BAS

  3. From the terminal run the command npm install

    shell
    npm install

    npm install

  4. We will use an open source sample utility called hana-cli to help with development tasks. From this same terminal window run the command npm install -g hana-cli in order to install it for later usage.

    shell
    npm install -g hana-cli

Initialize local Git repository

You will use the local Git repository for basic version management.

  1. Click on the Source Control icon

    Source Control

  2. Click on the Initialize Repository icon

    Initialize Repository

  3. The Source Control panel now shows that it is being managed by Git and changes are being tracked

    Source Control: GIT

Perform your first commit

Each time you commit to the local or remote repository, you create a version. This will allow you to revert and compare any changes. It is recommended that you perform commits at the end of each tutorial.

  1. Choose Changes -> Stage All Changes to include all the new or changed files in this commits

    Stage All

  2. Add a commit message and click Commit All (Signed Off):

    Commit

For a real project it is recommended to set a remote repository, for example GitHub. This will allow you to have a copy of your code outside the SAP Business Application Studio Dev Space.

What the wizard creates: After running the wizard, your project contains a db/ folder for your data model, a srv/ folder for your service definitions, an app/ folder for any UI content, and a package.json that already includes @sap/cds, @sap/hdi-deploy, and other SAP-specific dependencies.

Exercise 2.2 Log In to Cloud Foundry

Before you can deploy or bind an HDI container, the Cloud Foundry CLI in BAS needs to know which Cloud Foundry organization and space to use.

👉 In BAS, open the command palette and run CF: Login to Cloud Foundry. Select your API endpoint, provide your credentials, and select the org and space where your HANA Cloud instance is mapped.

Why Cloud Foundry? SAP HANA Cloud instances are provisioned in a "multi-environment" context — the database itself is not running inside Cloud Foundry — but HDI containers are still created and managed as Cloud Foundry service instances (using the hana service with the hdi-shared plan). Logging in lets the CAP tooling find and bind those containers later.

Exercise 2.3 Initialize a Git Repository

Version control is important from day one. The tutorial has you initialize a local Git repository so you can track every change you make as you progress through the exercises.

👉 Follow the Git initialization steps in the tutorial. Stage and commit your initial project files once the wizard finishes.

Local vs. remote: A local Git repository gives you commit history and the ability to revert changes, but the code only lives on your BAS dev space. In a real project you would push to a central repository (GitHub, GitLab, Azure DevOps, etc.) for backup, collaboration, and CI/CD integration.

Summary

At the end of this exercise you have:

  • A CAP Node.js project scaffolded and configured for SAP HANA Cloud
  • A package.json with the correct SAP dependencies (@sap/cds, @sap/hdi-deploy, etc.)
  • An mta.yaml deployment descriptor ready for Cloud Foundry MTA builds
  • A Cloud Foundry CLI session pointed at the correct org and space
  • A local Git repository with an initial commit

Questions for Discussion

  1. What is the value of the dev space in SAP Business Application Studio? To help with this discussion point consider the prerequisites section for not using SAP Business Application Studio.

    Answer A dev space is a pre-configured, containerized development environment in BAS tailored to a specific scenario — such as Full Stack Cloud Application, SAP Fiori, or SAP HANA Native. It ships with the correct extensions, CLI tools (`@sap/cds-dk`, Cloud Foundry CLI, MTA Build Tool), and runtimes already installed, so you can start coding immediately without any local setup.

    The trade-off versus a local environment like VS Code is that BAS requires an internet connection and runs inside SAP BTP, which can simplify connectivity to SAP services. SAP also provides a CDS language extension for VS Code for developers who prefer to work locally — see the prerequisites for details.

  2. Why was it necessary to log in to Cloud Foundry, even though SAP HANA Cloud itself is not running inside Cloud Foundry?

    Answer SAP HANA Cloud is provisioned in a multi-environment context — the database is not tied to Cloud Foundry — but **HDI containers** (the isolated schemas where your database artifacts live) are still created and managed as Cloud Foundry service instances using the `hana` service with the `hdi-shared` plan.

    When you run cds deploy or build the MTA, the CAP tooling uses your Cloud Foundry session to discover, create, or bind to the correct HDI container in the target space. Without a CF login, the tooling cannot locate or provision the container. See HDI containers for more detail.

  3. What is the purpose of the mta.yaml file?

    Answer `mta.yaml` is the deployment descriptor for a **Multi-Target Application (MTA)** — a bundle that groups multiple deployable components (a database module, a CAP service module, a UI app, an AppRouter, etc.) into a single archive that can be deployed atomically to Cloud Foundry.

    In this project the mta.yaml defines:

    • A db module (MyHANAApp-db) that runs @sap/hdi-deploy to push database artifacts into the HDI container
    • A srv module (MyHANAApp-srv) that runs the CAP Node.js service and exposes the srv-api destination
    • Resources for the HANA HDI container and (later) XSUAA, which Cloud Foundry provisions as service instances

    See the MTA specification for the full descriptor reference.

  4. Who can explain what NPM is and how it is used in this project?

    Answer NPM (Node Package Manager) is the standard package manager for Node.js. It reads `package.json` to install the libraries your project depends on and makes them available in `node_modules/`.

    Key packages in this CAP project:

    • @sap/cds — the CAP runtime: processes CDS models, serves OData endpoints, handles database queries.
    • @sap/cds-dk — the CAP development toolkit: provides the cds CLI for building, running, and deploying projects.
    • @sap/hdi-deploy — the HDI deployer: reads compiled HANA artifacts from db/src/gen/ and deploys them into the HDI container during the MTA build.

    Run npm ci (not npm install) in CI/CD or when you first clone a project — it installs exactly the versions listed in package-lock.json rather than resolving fresh versions, which ensures reproducible builds.

  5. Version control with Git — what is the impact of using a local Git repository as we did in this tutorial?

    Answer A local Git repository gives you a full commit history, the ability to branch and experiment, and the safety net of reverting to any previous state. Every `git commit` is a snapshot of your project at a point in time.

    The limitation is that a local repo only exists on your BAS dev space. If the dev space is deleted or your BTP trial expires, that history is gone. In a real project you would push to a central repository (GitHub, GitLab, Azure DevOps, etc.) for:

    • Backup — the code survives beyond any single environment
    • Collaboration — multiple developers can push and pull changes
    • CI/CD — pipelines can trigger automatically on commits and run builds, tests, and deployments

    For ABAP developers in the room: Git-based version control in CAP works similarly to the abapGit / ABAP Development Tools (ADT) workflow you may already know, but operates at the file level rather than the transport level.

  6. What is the difference between npm install and npm ci, and which should you use in a build pipeline?

    Answer

    npm install resolves the dependency tree fresh from package.json, potentially installing newer minor or patch versions than the last run. npm ci installs exactly the versions locked in package-lock.json, deletes node_modules first if it already exists, and fails if package-lock.json is missing or out of sync with package.json.

    In a build pipeline — including the before-all hook in mta.yamlnpm ci is always preferred because it guarantees reproducible builds: every run installs exactly the same versions regardless of when the build runs or what has been published to the npm registry since package-lock.json was last updated.

    Use npm install when you are intentionally updating dependencies and want npm to resolve fresh versions. Use npm ci everywhere else.

  7. Look at the generated package.json. What does the cds.requires.db section tell CAP about which database to use?

    Answer

    The cds.requires.db block is CAP's database configuration. By default the wizard generates something like:

    json
    "cds": {
      "requires": {
        "db": {
          "kind": "sql"
        },
        "[production]": {
          "db": {
            "kind": "hana"
          }
        }
      }
    }

    "kind": "sql" tells CAP to use SQLite for local development — no HANA connection needed to run cds watch on your laptop. The "[production]" profile overrides this to "kind": "hana" when CAP is started with --profile production (which cds build --production activates).

    At runtime on BTP, CAP reads the HDI container credentials from VCAP_SERVICES using the db key as the lookup name, so the service binding in mta.yaml must be named to match. This single block controls both the local development database and the production HANA connection.

Further Study

Next

Continue to 👉 Exercise 3 - Create Database Artifacts Using Core Data Services (CDS) for SAP HANA Cloud