Create a CAP Application with SAP HANA Cloud from Scratch and Deploy to Cloud Foundry
This guide walks you through the complete lifecycle of building a CAP (Cloud Application Programming) application, connecting it to SAP HANA Cloud, and deploying it to SAP BTP Cloud Foundry.
1.Create SAP BTP Trial Account
You need a trial account to access Cloud Foundry, SAP HANA Cloud, and all BAS development tools.
2. Subscribe to SAP Business Application Studio (BAS)
If not subscribed:
Go to SAP BTP Cockpit → Instances and SubscriptionsSubscribe to Business Application Studio
3. Create CAP Project Skeleton (Using Template Wizard)
Open BAS and press:
Ctrl + Shift + P → Template Wizard
Then follow these steps:
3.1 Select Template
Select: CAP Project GeneratorClick Next
3.2 Provide Project Details
Project Name → Any name of your choiceChoose Database → SQLite (default)Choose Deployment Target → Cloud Foundry
Note:
Do not select SAP HANA Cloud here.
We first deploy the application with SQLite, then add HANA later from terminal.
3.3 Choose Runtime Capabilities
Select these productive services:
XSUAASAP BTP Connectivity ServiceSAP BTP Destination ServiceSAP BTP Application Router
Click Finish.
This creates the complete folder structure including:
/db/srv/appmta.yamlSecurity and deployment artifacts
4. Modify MTA Configuration
Cloud Foundry sometimes fails when resource names contain dynamic interpolation (org/space).
Removing them ensures deployment simplicity.
Open mta.yaml and remove:
-${org}-${space}
from all resource names.
5. Create a Sample CAP Model
5.1 Define Database Schema
Open /db/schema.cds:
5.2 Create Service Definition
Open /srv/service.cds:
Now, you have a simple end-to-end data + service model to validate local and cloud deployment.
6. Test the CAP Application Locally
cds w
Now, CAP runs using SQLite, allowing quick testing without any external services.
7. Deploy the CAP Application (SQLite Mode)
Right-click mta.yaml → Build MTA ProjectOr use: mbt build
2. Login to Cloud Foundry
Ctrl + Shift + P → CF Login
3. Deploy the generated .mtar
Right-click .mtar → Deploy MTA ArchiveOr use:cf deploy yourfile.mtar
Your CAP app runs in Cloud Foundry with SQLite.
Next, we will connect it to real SAP HANA Cloud
8. Create SAP HANA Cloud Instance
Go to:
SAP BTP Cockpit → Instances & Subscriptions → Create
Choose:
Service: SAP HANA CloudPlan: hanaEnvironment: Cloud FoundryInstance Name: hanaDB
Set the DB administrator password → required for Data Explorer.
And press on Create instance.
It will take estimated 10-15min
It creates the actual HANA database where CAP HDI containers will be deployed.
9. Subscribe to SAP HANA Cloud Tools
Without this subscription, you cannot access the DB instance UI.
Go to:
Instances & Subscriptions → Subscribe → SAP HANA Cloud Tools
Assign Roles
Under Users, assign all required HANA Cloud roles.
Sign out → Sign in again.
10. Open SAP HANA Data Explorer
Click the HANA instance → Open SAP HANA Database Explorer
First login:
Username: DBADMIN (or the username shown under “Administrator”)Password: the one you entered during instance creation
If you forgot your DB username
Open:
SAP HANA Cloud Administration → Overview
Your administrator username will be displayed there.
Now, You have direct access to schemas, HDI containers, and database objects.
11. Open HDI Container Section in SAP HANA Database Explorer
Inside SAP HANA Database Explorer:
Click the “+” iconChoose Cloud FoundryLog in to your CF environment
From the list → choose Instance Type: HDI Container
At this stage, your CAP HDI container will NOT appear yet, because we have not created it.
12. Add HANA Support to CAP Application
Run the following commands in BAS terminal:
cds add hana
npm i
What these commands do
cds add hanaGenerates HANA-specific configurationCreates HDI deployment artifactsPrepares the project to run on SAP HANA instead of SQLitenpm iInstalls additional dependencies required for HANA runtime
Now, your project is ready to connect and deploy models to an HDI container.
13. Update package.json for HANA Deployment
Open package.json → under “cds.requires” add:
“db”: {
“kind”: “hana”
}
This tells CAP to use SAP HANA as the primary database in production.
14. Bind the CAP Project to Your HANA Instance
In BAS → Cloud Foundry view:
Select your CAP appChoose Bind to ServicePick your HANA DB instance hanaDB
This automatically creates a .env file containing:
HDI container nameCredentialsDatabase URLsService keys
Why we are doing this
CAP needs this information to connect to SAP HANA for:
Local “cds watch”Production deployment
Your project is now fully connected to SAP HANA Cloud.
15. Build Your CAP Project for Production
Run:
cds build –production
HANA Cloud can now deploy your database schema properly.
16. Deploy to SAP HANA Cloud
Run:
cds deploy –production
This:
Creates HDI containerDeploys CDS schema into HANA tablesActivates views, indexes, constraints
Your CAP application now uses SAP HANA Cloud as its primary DB.
17. Rebuild and Deploy the Entire CAP Application
Again perform:
mbt build
Then deploy:
cf deploy <yourfile>.mtar
Our complete application (service + database) is deployed on Cloud Foundry using HANA.
18. Verify Schema Deployment in SAP HANA Cloud
Open SAP HANA Data ExplorerClick +Select Instance Type = HDIChoose your CAP application HDI container
5. Expand Tables and Views
You can verify that:
Tables are createdData model is deployed correctly
19. Running CAP Application Locally Using HANA Cloud
If you want to run locally via HANA:
Ensure .env existsRebind HDI container if needed
Run: cds w
Successful connection check
If logs show:
Connected to SAP HANA Cloud (hanaDB) . Then your HDI container is successfully connected.
20. Validate Deployment Using Postman
This confirms:
Service is runningHANA DB is connectedDeployment is successful end-to-end
Conclusion
In this blog, we have completed the following activities:
Created a new CAP application using the BAS template wizard.
Performed an initial deployment using SQLite to verify application behavior.
Provisioned a SAP HANA Cloud instance and assigned all required role collections.
Enabled HANA support in the CAP project and generated HDI-related artifacts.
Bound the project to the HANA instance to establish secure database connectivity.
Built CDS artifacts for production and deployed them into the HDI container.
Rebuilt and deployed the full MTA application to SAP BTP Cloud Foundry using HANA as the primary database.
Verified successful deployment through SAP HANA Database Explorer and API testing.
Create a CAP Application with SAP HANA Cloud from Scratch and Deploy to Cloud FoundryThis guide walks you through the complete lifecycle of building a CAP (Cloud Application Programming) application, connecting it to SAP HANA Cloud, and deploying it to SAP BTP Cloud Foundry. 1.Create SAP BTP Trial Account You need a trial account to access Cloud Foundry, SAP HANA Cloud, and all BAS development tools. 2. Subscribe to SAP Business Application Studio (BAS)If not subscribed:Go to SAP BTP Cockpit → Instances and SubscriptionsSubscribe to Business Application Studio 3. Create CAP Project Skeleton (Using Template Wizard)Open BAS and press:Ctrl + Shift + P → Template Wizard Then follow these steps:3.1 Select TemplateSelect: CAP Project GeneratorClick Next 3.2 Provide Project DetailsProject Name → Any name of your choiceChoose Database → SQLite (default)Choose Deployment Target → Cloud FoundryNote:Do not select SAP HANA Cloud here.We first deploy the application with SQLite, then add HANA later from terminal. 3.3 Choose Runtime CapabilitiesSelect these productive services:XSUAASAP BTP Connectivity ServiceSAP BTP Destination ServiceSAP BTP Application RouterClick Finish.This creates the complete folder structure including:/db/srv/appmta.yamlSecurity and deployment artifacts 4. Modify MTA ConfigurationCloud Foundry sometimes fails when resource names contain dynamic interpolation (org/space).Removing them ensures deployment simplicity.Open mta.yaml and remove:-${org}-${space}from all resource names. 5. Create a Sample CAP Model5.1 Define Database SchemaOpen /db/schema.cds: 5.2 Create Service DefinitionOpen /srv/service.cds:Now, you have a simple end-to-end data + service model to validate local and cloud deployment. 6. Test the CAP Application Locally cds wNow, CAP runs using SQLite, allowing quick testing without any external services. 7. Deploy the CAP Application (SQLite Mode)Right-click mta.yaml → Build MTA ProjectOr use: mbt build 2. Login to Cloud Foundry Ctrl + Shift + P → CF Login 3. Deploy the generated .mtarRight-click .mtar → Deploy MTA ArchiveOr use:cf deploy yourfile.mtarYour CAP app runs in Cloud Foundry with SQLite. Next, we will connect it to real SAP HANA Cloud 8. Create SAP HANA Cloud InstanceGo to:SAP BTP Cockpit → Instances & Subscriptions → CreateChoose:Service: SAP HANA CloudPlan: hanaEnvironment: Cloud FoundryInstance Name: hanaDBSet the DB administrator password → required for Data Explorer. And press on Create instance.It will take estimated 10-15minIt creates the actual HANA database where CAP HDI containers will be deployed. 9. Subscribe to SAP HANA Cloud ToolsWithout this subscription, you cannot access the DB instance UI.Go to:Instances & Subscriptions → Subscribe → SAP HANA Cloud ToolsAssign RolesUnder Users, assign all required HANA Cloud roles.Sign out → Sign in again. 10. Open SAP HANA Data ExplorerClick the HANA instance → Open SAP HANA Database Explorer First login:Username: DBADMIN (or the username shown under “Administrator”)Password: the one you entered during instance creationIf you forgot your DB usernameOpen:SAP HANA Cloud Administration → OverviewYour administrator username will be displayed there. Now, You have direct access to schemas, HDI containers, and database objects. 11. Open HDI Container Section in SAP HANA Database ExplorerInside SAP HANA Database Explorer:Click the “+” iconChoose Cloud FoundryLog in to your CF environment From the list → choose Instance Type: HDI ContainerAt this stage, your CAP HDI container will NOT appear yet, because we have not created it. 12. Add HANA Support to CAP ApplicationRun the following commands in BAS terminal:cds add hana
npm iWhat these commands docds add hanaGenerates HANA-specific configurationCreates HDI deployment artifactsPrepares the project to run on SAP HANA instead of SQLitenpm iInstalls additional dependencies required for HANA runtimeNow, your project is ready to connect and deploy models to an HDI container. 13. Update package.json for HANA Deployment Open package.json → under “cds.requires” add:”db”: {
“kind”: “hana”
}This tells CAP to use SAP HANA as the primary database in production. 14. Bind the CAP Project to Your HANA InstanceIn BAS → Cloud Foundry view:Select your CAP appChoose Bind to ServicePick your HANA DB instance hanaDBThis automatically creates a .env file containing:HDI container nameCredentialsDatabase URLsService keysWhy we are doing thisCAP needs this information to connect to SAP HANA for:Local “cds watch”Production deploymentYour project is now fully connected to SAP HANA Cloud. 15. Build Your CAP Project for ProductionRun:cds build –productionHANA Cloud can now deploy your database schema properly. 16. Deploy to SAP HANA CloudRun:cds deploy –productionThis:Creates HDI containerDeploys CDS schema into HANA tablesActivates views, indexes, constraintsYour CAP application now uses SAP HANA Cloud as its primary DB. 17. Rebuild and Deploy the Entire CAP ApplicationAgain perform:mbt buildThen deploy:cf deploy <yourfile>.mtar Our complete application (service + database) is deployed on Cloud Foundry using HANA. 18. Verify Schema Deployment in SAP HANA CloudOpen SAP HANA Data ExplorerClick +Select Instance Type = HDIChoose your CAP application HDI container 5. Expand Tables and ViewsYou can verify that:Tables are createdData model is deployed correctly 19. Running CAP Application Locally Using HANA CloudIf you want to run locally via HANA:Ensure .env existsRebind HDI container if needed Run: cds wSuccessful connection checkIf logs show:Connected to SAP HANA Cloud (hanaDB) . Then your HDI container is successfully connected. 20. Validate Deployment Using Postman This confirms:Service is runningHANA DB is connectedDeployment is successful end-to-endConclusionIn this blog, we have completed the following activities:Created a new CAP application using the BAS template wizard.Performed an initial deployment using SQLite to verify application behavior.Provisioned a SAP HANA Cloud instance and assigned all required role collections.Enabled HANA support in the CAP project and generated HDI-related artifacts.Bound the project to the HANA instance to establish secure database connectivity.Built CDS artifacts for production and deployed them into the HDI container.Rebuilt and deployed the full MTA application to SAP BTP Cloud Foundry using HANA as the primary database.Verified successful deployment through SAP HANA Database Explorer and API testing. Read More Technology Blog Posts by Members articles
#SAP
#SAPTechnologyblog