Creating HDBDD Table using CDS method in SAP HANA

Hi All. Welcome to a new tutorial on creating a CDS based HDBDD Table in SAP HANA. In this one, we learn to create a table using the SAP HANA CDS (Core Data Service) method. The two recommended methods today to create a custom table in SAP HANA are using the HDBDD file or to use the HDBCDS file (when you have an XS Advanced or XSA installation).

The method to create a table elaborated on this website are:

  1. Using the graphical method  discussed in a separate tutorial.
  2. Using the SQL Script method discussed in a separate tutorial.
  3. Using the HDB tables method discussed in a separate tutorial.
  4. Using the HDBDD method discussed here(Recommended method in non XSA projects).
  5. Using the HDBCDS method which would be discussed in a future tutorial(Recommended method in XSA projects).

For anyone in a hurry, here’s the video version of this tutorial on YouTube. If you prefer a written one, please read on. Also, please subscribe to our YouTube channel to get video tutorials weeks before the written ones.

CDS HDBDD table : Using Web Development Workbench

We are using the web development workbench to create this HDBDD file. You can also do this in the SAP HANA studio under the repository tab.

Once you open the SAP HANA web development workbench, click on the Catalog to open the Catalog section.

hdbdd table cds sap hana

The catalog link opens up showing the packages you are authorized to view.

hdbdd table cds sap hana

Right click on the package where you wish to develop this code.

From the context menu, choose New-> File

hdbdd table cds sap hana

A window opens up asking for the file name

hdbdd table cds sap hana

We provide a file name TABLES with the extension hdbdd.

hdbdd table cds sap hana

The editor opens up.

hdbdd table cds sap hana

Now, we paste the below code into this editor to create our table.

namespace TEACHMEHANA;

@Schema: 'SHYAM'

context TABLES {

Entity CUST_REV_CDS {

CUST_ID : String (10);

FIRST_NAME : String (20);

LAST_NAME : String(20);

REVENUE_USD : Integer;

};

};

The namespace needs to define the package under which this file is created.

@Schema defines the schema under which the created table(s) would reside under.

The main context defines the file name that was given at the time of HDBDD creation.

A table is a persistent entity in SAP HANA CDS and hence the below statement declares a table (entity) CUST_REV_CDS.

Entity CUST_REV_CDS : The next part declares the columns in this table. Notice that the data types are different than in regular SQL. There is no NVARCHAR. Instead the declaration uses a String datatype. This is because CDS has slightly different datatypes.

{

CUST_ID : String (10);

FIRST_NAME : String (20);

LAST_NAME : String(20);

REVENUE_USD : Integer;

};

SAP has an online page dedicated to the datatype mappings which you can refer to in this regard. Click here to reach that page. A screenshot of that page currently is as below.

hdbdd table cds sap hana

hdbdd table cds sap hana

Once done, right click on the file and click “Activate”.

hdbdd table cds sap hana

The cross symbol disappears from the file confirming that it is now active. The table CUST_REV_CDS should also now be created in the SHYAM schema as defined.

hdbdd table cds sap hana

Now come back to the Web based development workbench. Click on the Editor.

hdbdd table cds sap hana

Now, expand the Catalog, the schema, and the tables folder.

We see that the table has been created successfully.

hdbdd table cds sap hana

This table can also be loaded using the hdbti method in the same way as the hdb tables.

I hope that the SAP HANA CDS HDBDD table concept is now clear to you. Please share this tutorial on social media to help support the site. Also, comments with your thoughts and questions.

Until next time…

<<Previous Tutorial                                                                                                                 Next Tutorial>>

Tagged , .

99 Comments

  1. Shyam, I tried creating table by this approach getting below error message don’t know what is missing here?

    Error while activating /HARRYHANA/CDSTABLE.hdbdd:
    [HARRYHANA:CDSTABLE.hdbdd] Cannot find artifact “SCHEMA”
    [HARRYHANA:CDSTABLE.hdbdd] Annotation “sap.cds::Schema” must be specified
    [HARRYHANA:CDSTABLE.hdbdd] Artifact name “TABLES” does not match base name “CDSTABLE” from resource

    • Seems like you didn’t provide the schema name correctly.
      Tell me:
      1. Your package name
      2. The schema where you are trying to create this.
      3. The HDBDD filename.
      4. Paste the code here.

      Shyam

  2. hi,

    What is the Pros & Cons of creating the table in SQL, Graphical, CDS methods…

    Appreciate you explanation.

    Thank you,

    • CDS is the only recommended method currently as you can declare and define multiple table at one place increasing maintainability.
      Also, you can define reusable datatypes which all tables defined inside this cds file can then use.
      Also, it’s easier to transport and version control.

      • Hi Shyam,

        How HDBDD is different than HDBTABLE method? What do you mean by reusing datatypes and increasing maintainability? Cant we do the same thing with HDBTABLE?

        Thanks,
        Nilima

        • in 1 HDBDD file, I can declare and define multiple tables. But in an HDBTABLE file, I can only declare 1 table.
          In HDBDD, I can define a datatype let’s say apple which is of varchar (20) length.
          Now if varchar (20) is a frequently used datatype, I can declare fields as the datatype apple which will be same as varchar(20). Ofcourse, this is a simple example and there are further complex usecases.

    • SQL and graphical are quick methods but no longer recommended.
      The only recommended way is the CDS method(s). It is more ideal to maintain and transport.

  3. Hi Shyam,

    The tables created in SAP HANA studio using HDBDD method, how can I display them in structural format as you have given above in SAP HANA Studio or do I need to use Web based development workbench or Eclipse for that?

    Thanks,
    Nilima

    • They will be available in the schema you declared in the HDBDD file. It’s visible both in hana studio or the web editor.

  4. Thanks for wonderful explanation, Small correction in above can be done as follow:

    In the text above -“Once you open the SAP HANA web development workbench, click on the Catalog to open the Catalog section.” Instead of ‘catalog’ its has to be ‘Editor’ as we can add the file hdbdd inside content.
    Similarly later while opening the editor it has to be updated from Editor–>Catalog

    Being a newbie to this hana cloud Account it took a lot time(My bad)to find content>”Mypackagename” in catalog,when actually it was inside Editor

  5. what is the difference between Hana Modeler and Hana Developer?So far I have created tables,views in hana modeler.But HDB table I could not create in Hana modeler.so I did it in hana developer.Which one should I use to create all the objects?

  6. Hi Shyam,

    Is it possible to create Hdbdd file dynamically,
    now we are creating hdbdd file manually and creating tables in it.
    can we not do it using any other method like SQL query or something.

    Thanks in Advance,
    Miyan

    • Not sure. There’s always a way to do things in a database.
      I am not aware of the way though. But why would you want to do that.
      What is your use case?

  7. Can we have same context defined in multiple .hdbcds files?
    I am using full text indexes and each time i modify the file, indexes are getting rebuild and taking lot of time.
    Putting different tables in different .hdbcds file might help in that case.

Leave a Reply

Your email address will not be published. Required fields are marked *