ERPClimb logoERPClimb
HANA Cloud and deployments
SAP Cloud Application Programming Modeladvanced 5 min read

HANA Cloud and deployments — SAP Guided Tutorial

Free sample lesson · open to everyone

Key takeaway

Deploying a CAP app with SAP HANA Cloud: HDI containers, the db deployer module, MTA builds with mbt and cf deploy, secrets via bindings, and how to change the schema safely without losing data.

In this lessonShow sections

Visual overview

HANA Cloud and deployments — learning sheetFlow: cds add hana + mta → mbt build: .mtar → cf deploy: HDI + srv → Schema change: migration table. Key ideas: PIECES OF A DEPLOYMENT; BUILD AND DEPLOY; SAFE SCHEMA EVOLUTION; SECRETS AND ENVIRONMENTS. Watch out: Never fix production by editing the HDI schema by hand — the next deployment will overwrite or fail on it.ERPClimb.com / CAP / LESSON 10/12 / LEARNING SHEETHANA Cloud and deployments1 · HOW IT FLOWS1cds add hana +mta2mbt build.mtar3cf deployHDI + srv4Schema changemigration table2 · KEY IDEAS EXPLAINEDPieces Of A Deploymentsrv module: the Node.js or Java app (gen/srv).db-deployer module: a short-lived task thatdeploys gen/db into the HDI container, then stops.Build And Deploy`cds add hana,xsuaa,mta` then `npm install`.`mbt build -t ./mta_archives` builds all modulesaccording to mta.yaml.Safe Schema EvolutionAdding nullable columns and new entities is safe.Changing a column type or renaming can recreatethe table; annotate the entity with`@cds.persistence.journal` so CAP generates an…Secrets And EnvironmentsCredentials come only from bindings; `cds bind`lets developers use real services locally withoutcopying secrets.Use separate subaccounts or spaces fordev/test/prod with a CI/CD pipeline deploying thesame .mtar.3 · REMEMBER · WATCH OUTRemember`cds add hana` switches production to HANA; `cds add mta` createsmta.yaml with srv, db-deployer and service resources.Each app gets an HDI container (service plan hdi-shared); the dbdeployer module writes tables and views into it.`mbt build` produces an .mtar archive; `cf deploymta_archives/<app>.mtar` deploys modules and creates/binds…!Watch outNever fix production by editing theHDI schema by hand — the nextdeployment will overwrite or fail onit.4 · IN A REAL PROJECTA team renamed `amount` to `netAmount` in a CDS entity and redeployed to production. HDI recreated the tableand the column's data was lost. They restored from backup, then re-did the change with@cds.persistence.journal on the entity and a migration rehearsal on a copy, which preserved the data.Original ERPClimb learning sheet • Verify against your SAP release and edition

The situation: a real project scenario

A team renamed amount to netAmount in a CDS entity and redeployed to production. HDI recreated the table and the column's data was lost. They restored from backup, then re-did the change with @cds.persistence.journal on the entity and a migration rehearsal on a copy, which preserved the data.

Explanation

Getting a CAP app onto SAP BTP with a real database starts with adding the right facets: cds add hana switches the production profile to HANA, and cds add mta generates an mta.yaml describing the modules that make up the deployment — the service itself, a database deployer, and the various backing resources.

Each app gets its own HDI container, typically provisioned with the hdi-shared service plan, and a short-lived db-deployer module runs once per deployment to write the compiled tables and views from gen/db into that container before stopping.

mbt build -t ./mta_archives packages all of this into a single .mtar archive, and cf deploy mta_archives/<app>.mtar deploys it, creating and binding the resources it declares; cf apps, cf services, and the db-deployer's own logs are where you confirm it actually worked.

Schema evolution is the part that bites teams who treat HANA like a local SQLite file. Adding a new nullable column or a brand-new entity is safe and HDI handles it transparently. Changing a column's type or renaming it is not safe by default — HDI can recreate the underlying table, which silently drops the data in it.

The fix is to annotate the entity with @cds.persistence.journal, which causes CAP to generate an .hdbmigrationtable artifact so HDI performs an actual data migration instead of a drop-and-recreate.

Even with that annotation in place, it's worth rehearsing the change against a copy of production data before running it for real, since migrations can still behave unexpectedly on data shapes you didn't anticipate.

Secrets and environment-specific values follow the same discipline as everywhere else in CAP: credentials should come only from service bindings, never be hardcoded, and cds bind lets a developer connect to real cloud services locally without ever copying a secret into a config file.

Separate subaccounts or Cloud Foundry spaces for dev, test, and production, with one CI/CD pipeline promoting the same .mtar archive through all of them, keeps "it worked in test" meaningfully connected to "it will work in production" — building a different archive per environment undermines that guarantee. Differences between environments belong in .mtaext extension descriptors, not in separate builds.

To work through this directly: run cds add hana,xsuaa,mta, build with mbt, and deploy to a test space; read the db-deployer logs and locate the HDI container in the HANA database explorer; add a nullable field and redeploy, confirming the existing data survives; then change a field's type on a journaled entity and confirm the data is migrated rather than lost. The goal is to be able to redeploy with a schema change and prove, by row counts and spot checks, that nothing was lost in the process.

Code example

ABAP Code
# add facets and deploycds add hana,xsuaa,mtanpm installmbt build -t ./mta_archivescf deploy mta_archives/bookshop_1.0.0.mtar // db/schema.cds — evolve with data in place@cds.persistence.journalentity Invoices : cuid { netAmount : Decimal(15,2); }

Watch out

Common mistakes

  • Deploying only the srv module and forgetting the db deployer.
  • Renaming or retyping columns without a migration, silently losing data.
  • Editing tables manually in the HDI container.
  • Building a different archive per environment instead of promoting one artefact.

Do this

Best practices

  • Promote one .mtar through environments with extension descriptors for differences.
  • Use @cds.persistence.journal for entities whose schema will evolve with data in place.
  • Check deployer logs and row counts after each production deployment.

In the interview

Interview angle

A deployment question should cover the MTA pieces (srv, db deployer, HDI, XSUAA), the build and deploy commands, and above all how you change schemas safely on live data and promote one artefact through environments.

Practice this lesson

Original educational case studies for SAP consultants, not official SAP certification exam questions. Verify product edition and implementation details against the current SAP documentation.

Quick check

0 of 4 questions attempted

Question 1 of 4

What does the db-deployer module in a CAP MTA do?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1Walk me through deploying a CAP application with HANA Cloud to BTP Cloud Foundry.

2How do you change a CDS entity in production without losing data?

Was this lesson helpful?

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.