Technical Articles
Develop Calculation View in BAS and consume in SAC
SAP Business Application Studio could help us develop Calculation Views. SAC released connecting SAP HANA Cloud by live data mode. This article explains how to use SAC connect SAP HANA Cloud to illustrate Calculation Views.
What you will learn
✔️ How to create a CAP model on SAP Cloud Platform, Cloud Foundry environment
✔️ How to create HANA tables by CDS
✔️ How to create Calculation View in BAS
✔️ How to consume Calculation View in SAC
Prerequisites
- Setup environment BAS (SAP Business Application Studio)
- Setup SAP HANA Cloud (Setup SAP HANA Cloud)
- Access permission on SAP Analytics Cloud landscape
Step1: Create new dev space for CAP
Step2: New CAP project in SAP Application Studio
Step3: Config CDS in workspace
- Update value for @sap/hana-client
"@sap/hana-client": "^2.6.61"
- Update scripts section
"start": "cds run", "hana": "cds deploy --to hana:mycapdemo-db --auto-undeploy", "build": "cds build/all --clean"
- Add new section hana into cds chapter
"hana": { "deploy-format": "hdbtable" }
- update db kind to hana
"kind": "hana"
Entire package.json file for your reference, memorize the hana instance name mycapdemo-db, it will be invoked later.
NOTES: Keep the segment “name”: “mycapdemo” and hana instance name “mycapdemo-db” mapping. It will avoid much manual job in subsequent steps.
{ "name": "mycapdemo", "version": "1.0.0", "description": "A simple CAP project.", "repository": "<Add your repository here>", "license": "UNLICENSED", "private": true, "dependencies": { "@sap/cds": "^5", "express": "^4", "@sap/hana-client": "^2.6.61" }, "devDependencies": { "@sap/hdi-deploy": "^4.2.0", "sqlite3": "^5.0.2" }, "scripts": { "start": "cds run", "hana": "cds deploy --to hana:mycapdemo-db --auto-undeploy", "build": "cds build/all --clean" }, "cds": { "hana": { "deploy-format": "hdbtable" }, "requires": { "db": { "kind": "hana" } } } }
- Add new entity Authors
To perform data join query in subsequent calculation view development, add a new table Authors here
Navigate to mycapdemo/db/src/data-model.cds, add a new entity in the file and setup AUTHOR_ID as foreign key in books table.
namespace my.bookshop;
entity Books {
key ID : Integer;
title : String;
stock : Integer;
author : Association to Authors;
}
entity Authors {
key ID : Integer;
name : String;
Address : String;
books : Association to many Books on books.author = $self;
}
- Add initial data for the tables
if you want to your table including data after table creation, navigate to file mycapdemo/db/data/my.bookshop-Authors.csv and my.bookshop-Books.csv to filling your demo data.
Note: Create the CSV file manually if related file not existing
- Pick up node dependencies
Open terminal from menu, and then execute command line:
npm install
- Create hdi-container and initiate the tables
Login your org/space
Open menu View->Find Command->Login to Cloud Foundry, input your own credential to complete org/space targeting.
This command line will create the hana instance mycapdemo-db here, the creation process will persist several minutes. Execute command line:
npm run hana
- Check OData service availability Execute command:
npm start
Step4: Create Calculation View project in BAS
Step5: Develop calculation view
Step6: Deploy Calculation View
Note: Make sure your dev space has already connected to CF correctly. If not, you can run command
cf login
to login CF
Step7: Check Calculation View in SAP HANA Database Explorer
Step8: Consume Calculation View in SAC
- Create Connection Login BTP Cockpit, Open Instances and Subscriptions, click the instance mycapdemo-db from the list, and then open “mycapdemo-db-key”, copy these values for creating SAC connection
Required Parameters |
---|
host |
user |
password |
- Create Modeler
Open Create Modeler wizard, click Live Data Model to launch wizard Create Model From Live Data Connection.
- Create new Story
Open Create Story wizard page, select Canvas, Click Chart icon, select new created modeler from the list.
Select Chart Orientation Vertical, Add Measures
The Calculation View will display on canvas.
Referenced link:
Create an SAP Cloud Application Programming Model Project for SAP HANA Cloud
Create Calculation View in BAS