SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Create Database Artifacts Using Core Data Services (CDS) for SAP HANA Cloud

Use SAP Cloud Application Programming Model (CAP) and Core Data Services (CDS) to generate SAP HANA Cloud basic database artifacts.

Overview

🎓 beginner 15 min. SAP HANA CloudBeginnerSAP Cloud Application Programming ModelSAP Business Application StudioSAP HANA

You will learn

  • โœ”How to use SAP Cloud Application Programming Model (CAP) Core Data Services (CDS) to create simple database entities
  • โœ”How to define database-agnostic artifacts in the persistence module

Prerequisites

Prerequisites

Steps

Video Version

Video version of tutorial:

Step 1 Create database entities
โ€”

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.

  1. In the db folder, right mouse click and choose New File

    New File
    New File

  2. Use the following name:

    Name
    interactions.cds

    Interactions.cds
    Interactions.cds

  3. 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.

  4. 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 2 Create service interface
+
Step 3 Explore generated design-time artifacts
+
Step 4 Check the Database Explorer
+
Step 5 Load data into your tables
+
Step 6 Check data loaded into the tables
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 6
1. Create database entities 2. Create service interface 3. Explore generated design-time artifacts 4. Check the Database Explorer 5. Load data into your tables 6. Check data loaded into the tables

Learn more →