User-Defined Structured Type in CDS

In the article SAP HANA Core Data Service, we explained
  • What is HANA Core Data Service?
  • How to create a HANA table using Core Data Service?
In this article, we will show how to create User-Defined Structured Type in CDS.
In CDS, we can create structured type as reusable component. For example:
type MyStructuredType
                {
                  aNumber   : Integer;
                  someText  : String(80);
                  otherText : String(80);
                };

For each structured type defined in a CDS document, an SAP HANA table type is generated.

Example of User-Defined Structured Type in CDS:

In previous article , we created a CDS file to create a HANA table. Let us extend that to use a structured type.

1. Create a structured type “NameType” by using below code.
type NameType
        {
                FirstName : String(20);
                LastName : String(20);
        };
2. Create a simple type Amount by using below code.
type Amount : Decimal(15,2);
3. In the Entity definition, use the type NameType and Amount.
Entity Employee {
                key Id : Integer;
                Name : NameType;
                Salary: Amount;
      };



4. Activate the CDS file. This will generate the structured type and table.
5. Open Catalog, go to schema “MY_SCHEMA” and check the type and table.



Click here to download the complete project.

Continue reading:

No comments:

Post a Comment