SAP HANA Cloud offers a fully managed, high-performance database service ideal for SAP CAP applications. Integrating CAP with HANA Cloud ensures enterprise-grade persistence, analytics, and scalability for SaaS applications.
This guide explains best practices, deployment strategies, and tips for building CAP applications with SAP HANA Cloud.
Why Use SAP HANA Cloud with CAP
HANA Cloud benefits CAP applications by providing:
- High-performance in-memory database
- Advanced analytical capabilities
- Multi-tenancy support
- Scalable storage and compute
- Seamless integration with SAP BTP services
CAP Persistence on HANA Cloud
CAP automatically supports HANA Cloud as a persistence layer.
Configure HANA in package.json
"cds": {
"requires": {
"db": {
"kind": "hana",
"model": ["db/schema"],
"credentials": {
"host": "hana.example.com",
"port": 443,
"user": "username",
"password": "password"
}
}
}
}
CAP supports:
- Multiple HDI containers for multitenancy
- Deploying CDS models to HANA artifacts
- Using
cds deploy --to hanafor migrations
Best Practices for Modeling & Persistence
- Keep CDS models database-agnostic for flexibility
- Use proper data types to leverage HANA performance (e.g.,
Decimal,UUID) - Optimize entity relationships to reduce joins
- Apply indexes on high-traffic columns
- Use
@readonlyfor analytical views
Using CAP Services with HANA Cloud
Expose CAP services via OData or REST:
- Use projections and views for read-only access
- Apply role-based access control for sensitive data
- Leverage CDS associations for navigation properties
Example: Expose Products entity
service CatalogService {
entity Products as projection on db.Products;
}
CAP automatically exposes OData endpoints for the HANA Cloud database.
Handling Multi-Tenancy
HANA Cloud supports tenant isolation via HDI containers:
- Assign each tenant a separate container
- Use CAP multitenancy features for provisioning
- Isolate schemas for better security and upgrades
Deployment Strategies
Deploy CAP applications to SAP BTP using:
- Cloud Foundry
- Push Node.js CAP apps using
cf push - Bind HANA Cloud service instance
- Configure environment variables for DB credentials
- Push Node.js CAP apps using
- Kyma / Kubernetes
- Containerize CAP app
- Deploy alongside HANA Cloud clients
- Use ConfigMaps for DB credentials
- CI/CD Integration
- Automate
cds deploy --to hana - Manage HDI containers and schema updates
- Include unit and integration tests for services
- Automate
Performance Optimization
- Use CDS views for complex queries
- Leverage HANA calculation views for analytics
- Enable caching for frequent queries
- Minimize unnecessary joins in high-traffic services
- Monitor performance with HANA Cloud monitoring tools
Monitoring & Logging
- Enable CAP logging using
CDS_LOG_LEVEL=debug - Use SAP BTP monitoring for HDI container performance
- Track service calls and database usage to detect bottlenecks
Real-World Example
- CAP service stores Orders, Products, and Customers in HANA Cloud
- Developers use CDS projections to expose OData endpoints
- Multi-tenant setup provides isolated HDI containers per customer
- Application deployed to Cloud Foundry with CI/CD pipeline
- Analytics team queries aggregated sales data using calculation views
Security Best Practices
- Use XSUAA for authentication
- Restrict entity access with role-based authorization
- Use HTTPS connections for DB access
- Avoid exposing raw HANA credentials in code
- Regularly rotate keys and service bindings
Conclusion
Combining SAP CAP with HANA Cloud enables enterprise-grade, scalable, and secure applications. Following best practices in modeling, persistence, deployment, and security ensures your CAP applications are production-ready and optimized for real-time processing.

WhatsApp us