SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Build an SAP CAP Application to Access SAP HANA Cloud, data lake Relational Engine

Create an SAP Cloud Application Programming Model (CAP) application in SAP Business Application Studio that queries data from an existing data lake, Relational Engine table. The data lake, Relational Engine instance must be SAP HANA-managed.

Overview

🎓 beginner 15 min. SAP HANA Cloud Data LakeBeginnerSAP HANA Cloud

You will learn

  • How to connect to an existing HANA-managed data lake Relational Engine instance using CAP
Unknown U Unknown June 16, 2023
Created by June 16, 2023
Contributors

Prerequisites

Prerequisites

  • An SAP HANA Cloud data lake instance managed by an SAP HANA Cloud instance
  • Experience working in SAP Business application Studios with HDI-based tables
  • Experience building and running SAP Cloud Applications Programming (CAP) model applications in SAP Business Application Studios

Steps

To learn about SAP CAP and application development on SAP BTP, see Introduction to Application Development Using CAP and Node.js | Tutorials for SAP Developers.

Intro


Step 1 Create database objects

  1. From SAP HANA Cloud Central, open your SAP HANA database in Database Explorer by choosing Open in SAP HANA Database Explorer.

    If you have not previously opened the database in Database Explorer, you will need to login using the DBADMIN credentials specified upon the creation of your HANA database.

    open-in-database-explorer
    open-in-database-explorer

  2. Within Database Explorer as DBADMIN, run the following SQL script to create a new user HDB_BOOKSHOP_USER and a relational container BOOKSHOP_CONTAINER in the attached HANA-managed data lake Relational Engine instance owned by HDB_BOOKSHOP_USER. and a new schema BOOKSHOP. This script also grants privileges on the BOOKSHOP SCHEMA to the HDB_BOOKSHOP_USER.

    SQL
    -- Create a new user called HDB_BOOKSHOP_USER
    CREATE USER HDB_BOOKSHOP_USER PASSWORD Password1 NO FORCE_FIRST_PASSWORD_CHANGE SET USERGROUP DEFAULT;
    -- Create a Relational Container in the attached HANA-managed HDLRE instance
    CALL SYSHDL.CREATE_CONTAINER('BOOKSHOP_CONTAINER', 'HDB_BOOKSHOP_USER');

    create-user-sql
    create-user-sql

    Then, create a new schema BOOKSHOP, and grant schema privileges on BOOKSHOP schema to the HDB_BOOKSHOP_USER.

    SQL
    -- Create a new schema
    CREATE SCHEMA BOOKSHOP;
    -- Grant all BOOKSHOP schema privileges to HDB_BOOK_USER
    GRANT ALL PRIVILEGES ON SCHEMA BOOKSHOP TO HDB_BOOKSHOP_USER WITH GRANT OPTION;

    create-schema-sql
    create-schema-sql

  3. You will now create database objects in the BOOKSHOP schema in the HANA-managed data lake Relational Engine that map to objects in the HANA database. These commands will be executed as the HDB_BOOKSHOP_USER as the owner of the relational container created in the previous step.

    SQL
    -- Connect as the HDB_BOOKSHOP_USER
    CONNECT HDB_BOOKSHOP_USER PASSWORD Password1;
    
    -- Create a virtual table in HANA that maps to a table in the attached HANA-managed HDLRE instance, also created here
    CREATE VIRTUAL TABLE BOOKSHOP.BOOK_REVIEWS (
        REVIEW_ID INTEGER PRIMARY KEY,
        BOOK_ID INTEGER NOT NULL,
        RATING INTEGER NOT NULL,
        REVIEW VARCHAR(500) NOT NULL
    ) AT "SYSHDL_BOOKSHOP_CONTAINER_SOURCE"."NULL"."SYSHDL_BOOKSHOP_CONTAINER"."BOOK_REVIEWS" WITH REMOTE;
    
    -- Insert sample data into the virtual table
    INSERT INTO BOOKSHOP.BOOK_REVIEWS(REVIEW_ID, BOOK_ID, RATING, REVIEW) VALUES(1, 1, 5, 'I loved reading this novel since I love mysteries.');
    INSERT INTO BOOKSHOP.BOOK_REVIEWS(REVIEW_ID, BOOK_ID, RATING, REVIEW) VALUES(2, 12, 4, 'This was a good fantasy book, but not as realistic as I had hoped.');
    INSERT INTO BOOKSHOP.BOOK_REVIEWS(REVIEW_ID, BOOK_ID, RATING, REVIEW) VALUES(3, 7, 3, 'This book was slow but an interesting read overall.'); 
    INSERT INTO BOOKSHOP.BOOK_REVIEWS(REVIEW_ID, BOOK_ID, RATING, REVIEW) VALUES(4, 3, 5, 'I could not put this book down. I truly get why this is a classic.');
    INSERT INTO BOOKSHOP.BOOK_REVIEWS(REVIEW_ID, BOOK_ID, RATING, REVIEW) VALUES(5, 12, 3, 'I wish there was more action and less romance.');

    create-table-sql
    create-table-sql

    For additional details consult Creating Virtual Tables

  4. Query the local SAP HANA table and the equivalent SAP HANA Cloud, data lake Relational Engine table. Note that both results should be identical.

    SQL
    SELECT * FROM BOOKSHOP.BOOK_REVIEWS;
    SELECT * FROM SYSHDL_BOOKSHOP_CONTAINER.BOOK_REVIEWS;

    select-query
    select-query

Step 2 Create a dev space in SAP Business Application Studio
+
Step 3 Create a CAP application in SAP Business Application Studio
+
Step 4 Connect to data lake, Relational Engine tables through a CAP application
+
Step 5 Knowledge check
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 5
1. Create database objects 2. Create a dev space in SAP Business Application Studio 3. Create a CAP application in SAP Business Application Studio 4. Connect to data lake, Relational Engine tables through a CAP application 5. Knowledge check

Learn more →