SapHanaTutorial.Com HOME     Learning-Materials Interview-Q&A Certifications Quiz Online-Courses Forum Jobs Trendz FAQs  
     Explore The World of Hana With Us     
About Us
Contact Us
 Apps
X
HANA App
>>>
Hadoop App
>>>
Tutorial App on SAP HANA
This app is an All-In-One package to provide everything to HANA Lovers.

It contains
1. Courses on SAP HANA - Basics, Modeling and Administration
2. Multiple Quizzes on Overview, Modelling, Architeture, and Administration
3. Most popular articles on SAP HANA
4. Series of Interview questions to brushup your HANA skills
Tutorial App on Hadoop
This app is an All-In-One package to provide everything to Hadoop Lovers.

It contains
1. Courses on Hadoop - Basics and Advanced
2. Multiple Quizzes on Basics, MapReduce and HDFS
3. Most popular articles on Hadoop
4. Series of Interview questions to brushup your skills
Apps
HANA App
Hadoop App
';
Search
Stay Connected
Search Topics
Topic Index
+
-
XSA Overview
+
-
XS Overview
+
-
Hello World Example
+
-
XS OData Service
+
-
HANA XSJS Service
+
-
Core Data Service
+
-
Others

Introduction to Core Data Service

Introduction:

SAP HANA XS enables you to create database schema, tables, views, and sequences as design-time files in the repository. This is achieved with the help of Core Data Services (CDS).
Core Data Services (CDS) artifacts are design-time definitions. When CDS file is activated, it generate runtime objects.
CDS file must have the file extension .hdbdd, for example, MyCDSTable.hdbdd

SAP HANA Core Data Service(CDS)

CDS can be used to create following database artifacts:
  • Create a table (entity)
  • Create an SQL views
  • Create an association between entities or views
  • Create a user-defined structured type

Note: Currently CDS cannot be used to create Schema and Sequence. To create a database schema you need to create .hdbschema file and to create a Sequence you need to create .hdbsequence file.
Read more about it:

Create a HANA table using CDS:

Now we will see an example of creating a table using HANA Core Data Service.

Prerequisite:

Note: In this example we will use the schema MY_SCHEMA create via hdbschema approach.


Steps to create HANA table using CDS:

  1. Create a XS project as mentioned in the article Create Your First HANA XS Application using HANA Studio
  2. Right click and select New à Others à SAP HANA à Database Development à DDL Source File.
SAP HANA Core Data Service(CDS)
  1. Enter the name of the CDS document in the File Name box, for example, MyModel.
  2. A basic CDS will be created similar to below.
namespace mypackage.data;
@Schema: 'MY_SCHEMA'
context MyModel {
};
 
  • Namespace: The name of the repository package in which you created the new CDS document, for example, mypackage.data
  • Context Name: The name of the context in a CDS document must match the name of the CDS document itself; this is the name you enter when using the file-creation wizard to create the new CDS document, for example:
  • Schema Name:  The @Schema annotation defines the name of the schema to use to store the artifacts that are generated when the CDS document is activated. Change the schema name to your schema. For example, MY_SCHEMA.
  1. Copy the below code and paste it inside context.

                @Catalog.tableType : #COLUMN
                Entity Employee {
                                key Id : Integer;
                                FirstName : String(20);
                                LastName : String(20);
                                Salary: Decimal(15,2);
                };

SAP HANA Core Data Service(CDS)
  1. Right click and select Team à Activate. This will activate the file.
  2. Go to Catalog. Expand schema MY_SCHEMA and check the new Table. You may have to refresh the schema if new table does not appear.
SAP HANA Core Data Service(CDS)

Click here to download the complete project.

Important points on HANA Core Data Service:


  • CDS can be used to create table, view and user-defined structured type.
  • File extension of CDS file is hdbdd.
For example: MyModel.hdbdd
  • Schema name in CDS file is specified with the annotation @Schema.
For example:  @Schema: 'MY_SCHEMA'
  • Entity is used to define a new table.
In the above example, Entity Employee eventually creates a table.
  • The name of the generated table is <package.path>::contextName.EntityName
  • The type of table is specified with annotation @Catalog.
For example: @Catalog.tableType : #COLUMN

Continue reading:



Support us by sharing this article.



Explore More
Close X
Close X

Leave a Reply

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

Current day month ye@r *

 © 2017 : saphanatutorial.com, All rights reserved.  Privacy Policy