Skip to Content
Previous

Create Database objects and CDS views

By Lsubatin

Create database objects and CDS views

You will learn

You will create a database module with Core Data Services artifacts.

Details


Step 1: Create a database module

Back to your project, right click on your project and then click on New->SAP HANA Database Module:

create db

Name your module db and click on next

create db

Remove the namespace, add a name to the schema, click on Build module after creation and the click on Finish

create db
Please log in to access this content.
Step 2: Create a CDS artifact

You will now use Core Data Services to create a table. The design-time artifact will be an Entity that will then be combined with the SHINE model.

Begin by creating a folder under db->src:

create folder

Call it data:

create folder

Create a CDS artifact in your new folder

create folder

Call it PO

create folder

The graphical editor will open automatically. Close it so you can create a context first.

Close editor
Please log in to access this content.
Step 3: Create a Context

Open the file using the Code Editor by right-clicking on it:

create CDS

Enter the following code into it:

context PO   {

};

Save and call the graphical editor:

create CDS
Please log in to access this content.
Step 4: Create your Entities using the CDS graphical editor

You can now explore the graphical Core Data Services editor briefly.

Click on an entity and drop it in the editor:

create CDS graphical

Call it APPROVAL_STATUS:

create CDS

Double click on the node you have just added (inside the white rectangle) and click on the + sign to add a new field for your entity:

add fields

Create two fields as follows:

create CDS fields

Save and close the Graphical editor. Open the Text Editor again.

see text editor

Copy the definition of the entity and click on Validate:

×
Step 5: Load data into your entity

You will now add data into your new entity. Build the db module first:

Build db

Create a comma-separated values file called status.csv in the data folder:

create csv

Add the following contents to it:

ID,TEXT
I, In process
A, Approved
R, Rejected

Save the file.

create csv

Now you need to add a new file to indicate how that file loads your new table. Create a file called load.hdbtabledata with the following contents on it:

{
    "format_version": 1,
    "imports": [
        {
            "target_table": "PO.APPROVAL_STATUS",
            "source_data": {
                "data_type": "CSV",
                "file_name": "status.csv",
                "has_header": true
            },
            "import_settings": {
                "import_columns": [
                    "ID",
					          "TEXT"
                ]
            }
        }
    ]
}     

Save:

load csv

Build the module.

Build module

Save and build the db module. Wait until the build finished to answer the following question.

Which sentence resembles the build results the most?
×

Updated 10/10/2017

Time to Complete

15 Min

Beginner

Tags

Next
Back to top