[[{“value”:”
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 Subscriptions
- Subscribe 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 Generator
- Click Next
3.2 Provide Project Details
- Project Name → Any name of your choice
- Choose 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:
- XSUAA
- SAP BTP Connectivity Service
- SAP BTP Destination Service
- SAP BTP Application Router
Click Finish.
This creates the complete folder structure including:
- /db
- /srv
- /app
- mta.yaml
- Security 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 Project
- Or use:
mbt build
2. Login to Cloud Foundry
Ctrl + Shift + P → CF Login
3. Deploy the generated .mtar
- Right-click .mtar → Deploy MTA Archive
- Or 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 Cloud
- Plan: hana
- Environment: Cloud Foundry
- Instance 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 “+” icon
- Choose Cloud Foundry
- Log 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 hana
- Generates HANA-specific configuration
- Creates HDI deployment artifacts
- Prepares the project to run on SAP HANA instead of SQLite
- Installs 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 app
- Choose Bind to Service
- Pick your HANA DB instance hanaDB
This automatically creates a .env file containing:
- HDI container name
- Credentials
- Database URLs
- Service 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 container
- Deploys CDS schema into HANA tables
- Activates 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 Explorer
- Click +
- Select Instance Type = HDI
- Choose your CAP application HDI container
5. Expand Tables and Views
You can verify that:
- Tables are created
- Data model is deployed correctly
19. Running CAP Application Locally Using HANA Cloud
If you want to run locally via HANA:
- Ensure .env exists
- Rebind 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 running
- HANA DB is connected
- Deployment 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.
“}]]
Read More Technology Blog Posts by Members articles
#abap