The SAP Cloud Application Programming model utilizes core data services to define artifacts in the database module. Because this model is meant to be database-agnostic – i.e., work with any database – it does not allow you to leverage features that are specific to SAP HANA Cloud. For this reason, you will also create two tables that do not require any advanced data types.
In the db folder, right mouse click and choose New File
New File
Use the following name:
Name
interactions.cds
Interactions.cds
Use the following content in this new file:
CAP
namespace app.interactions;
using {
Country,
Currency,
cuid,
managed
} from '@sap/cds/common';
type BusinessKey : String(10);
type Price : Decimal(10, 2);
type Text : String(1024);
entity Headers : cuid, managed {
items : Composition of many Items
on items.interaction = $self;
partner : BusinessKey;
country : Country;
};
entity Items : cuid {
interaction : Association to Headers;
text : localized Text;
date : DateTime;
@Semantics.amount.currencyCode: 'currency'
price : Price;
currency : Currency;
};
What is going on?
You are declaring two entities with relationships between each other. The design-time artifacts declared in this file will be converted to run-time, physical artifacts in the database. In this example, the entities will become tables.
We are using a reusable set of content (lists of countries, currencies, etc) provided by SAP in the above model. We also have to add this dependency to our project. From the command line issue the following command to do so:
Shell
npm add @sap/cds-common-content --save
Step 2Create service interface
+
In the srv (not src!) folder create another file and name it interaction_srv.cds
Name
interaction_srv.cds
interaction_srv.cds
Use the following content in this new file:
CAP
using app.interactions from '../db/interactions';
using {sap} from '@sap/cds-common-content';
service CatalogService {
@odata.draft.enabled: true
entity Interactions_Header as projection on interactions.Headers;
entity Interactions_Items as projection on interactions.Items;
@readonly
entity Languages as projection on sap.common.Languages;
}
Save all.
What is going on?
You are declaring services to expose the database entities you declared in the previous step.
From the terminal issue the command: cds build --production
Shell
cds build --production
cds build
Look into the console to see the progress. You can scroll up and see what has been built
cds build log
Step 3Explore generated design-time artifacts
+
If you pay attention to the build log in the console, you will see the CDS artifacts were converted to hdbtable and hdbview artifacts. You will find those artifacts in a new folder under /gen/db/src called gen.
Results of cds build
You will now deploy those objects into the HANA Database creating tables and views. We will use the SAP HANA Projects view to do this. Please expand this view and you will see the following:
SAP HANA Projects view
We need to bind our project to a Database Connection and HDI container instance. Press the bind icon to being the process.
Bind Project
If you receive either of these two following warning dialogs, please just choose Continue (nothing will be deleted because we are create a new HDI Container Instance) and Enable (automatic undeploy is quite helpful during the development process for the reasons described in this dialog)
Binding Warning #1
Binding Warning #2
The bind process will start a wizard where you will be prompted for values via the command pallet at the top of the SAP Business Application Studio screen. You might be asked to confirm your Cloud Foundry endpoint and credentials depending upon how long it has been since you last login.
Confirm Credentials
Your first choice will be for the binding option. Choose Bind to an HDI container.
Bind to an HDI container
You might be presented with options for existing service instances (if you’ve completed other tutorials or have performed other HANA development). But for this exercise we want to choose Create a new service instance
Create a new service instance
To make subsequent steps easier, shorten the generated name to MyHANAApp-dev + a group number or your initials if you are doing this tutorial as part of a group workshop/shared environment. This makes sure that everything remains unique per participant. Remember the value you used here and adjust the name in the subsequent steps. The remaining screenshots will always just show the base name.
Generated Service Name
It will take a minute or two for the service to be created in HANA. A progress bar will be shown in the message dialog
Service Creation Progress
Sometimes the binding step fails due to a timing issue. If so simply repeat the binding but this time do not create a new container name but select the existing HDI container that has been created from the previous attempt MyHANAApp-dev
Upon completion, the Database Connections will now show the service bound to the instance the wizard just created.
Bound Connection
We are now ready to deploy the development content into the database. Before you go ahead, we recommend that you increase the default number of scrollback lines in the integrated terminal, if you’re using a Dev Space in SAP Business Application Studio. This is because there are many lines of log output about to be generated and you will want to see them all. So use menu path File -> Preferences -> Settings and search for the “Terminal โบ Integrated: Scrollback” setting. Set the value to 10000. Now, once you’ve done that, you’re ready to deploy. Press the Deploy button (which looks like a rocket) at the db folder level in the SAP HANA Projects view.
Deploy
Scroll up to in the console to see what the build process has done.
What is going on?
CDS stands for Core Data Services. This is an infrastructure that allows you to create persistency and services using a declarative language. Notice how you are using the same syntax to define both the persistency and the services.
ย
You can find more information on CDS in the help
You defined a CDS artifact, this is an abstraction, a design-time declaration of the entities to be represented in a database and the services to expose them.
ย Build database module
The original .cds file was translated into hdbtable, which is the SQLDDL syntax specific to SAP HANA when you saved all of the files.
ย Build database module
These hdbtable files were then translated into runtime objects such as tables in the HANA database.
Build database module
If you checked the services in your space, you would see the service for your HDI container.
Build database module
You can find a similar example and further context on Core Data and Services in this explanatory video
Step 4Check the Database Explorer
+
You can now check the generated tables and views in the Database Explorer.
In the SAP HANA Projects view, press the Open HDI Container button
Press Open HDI Container
The Database Explorer will open in a new browser tab and automatically select the database entry for your project’s HDI container.
Once open, navigate to the Tables section and click on the Header table.
Open Table Definition
Note the name of the table matches the generated hdbtable artifacts. You will also see the physical schema managed by the HDI container.
Unless a name is specified during deployment, HDI containers are automatically created with names relative to the project and user generating them. This allows developers to work on different versions of the same HDI container at the same time.Build database module
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 6
1. Create database entities2. Create service interface3. Explore generated design-time artifacts4. Check the Database Explorer5. Load data into your tables6. Check data loaded into the tables
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.