Skip to Content

Create a Database Module

Create database objects and CDS views
You will learn

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

LsubatinLsubatinJanuary 5, 2021
Created by
Lsubatin
September 21, 2017
Contributors
Lsubatin

Prerequisites

  • This tutorial is designed for SAP HANA on premise and SAP HANA, express edition. It is not designed for SAP HANA Cloud.
  • Proficiency: Beginner
  • Step 1

    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
  • Step 2

    You will now use Core Data Services to create a table. You will then use other entities to combine the data.

    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
  • Step 3

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

    Right-click on the entity and choose Graphical Editor.

    Double-click on the context to create an entity:

    create CDS

    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:

    Hint: If you haven’t already, close the Git pane.

    create CDS fields

    Save and close the Graphical editor.

    Open the Text Editor again by right-clicking on PO.hdbcds

    see text editor

    Copy the definition of the entity (blurred out below) and click on Validate:

    validate CDS definition

  • Step 4

    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:

    text
    Copy
    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

    create csv

    Add the following contents to it:

    json
    Copy
    {
        "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?

Back to top