- You have SAP HANA Studio installed on your machine.
- You have added an SAP HANA system in HANA Studio.
- You have created the Analytic view mentioned in session 4.8
There is an analytic view that provides Product ID, Region and Sales Amount. We will make a join with PRODUCT table to get Product Name.
Further we will calculate Discount and Net Amount using following formula:
If Product Name = “Purse” then Discount = 20%; Else Discount = 10%
Net Amount = Sales Amount – Discount
Right click on the package and choose New -> Calculation View.
Enter a name and a description. Select Subtype as “SQL Script”.
You will see 2 blocks in the editor: Semantics and Script_View.
Semantics provides the summary of output structure, editor view of output objects and general view properties.
Select the Default Schema as the schema which contains tables to be used. In our example it is “SAP_HANA_TUTORIAL”.
Script_View is the place where we specify SQL script.
var1 = SELECT “REGION_NAME”, “SUB_REGION_NAME”, “PRODUCT_ID”, sum(“SALES_AMOUNT”) AS “SALES_AMOUNT”
GROUP BY “REGION_NAME”, “SUB_REGION_NAME”, “PRODUCT_ID”;
var2 =SELECT T1.”REGION_NAME”, T1.”SUB_REGION_NAME”, T1.”PRODUCT_ID”, T2.”PRODUCT_NAME”, T1.”SALES_AMOUNT”
from :var1 AS T1
PRODUCT AS T2
ON T1.PRODUCT_ID = T2.PRODUCT_ID;
var3 = SELECT “REGION_NAME”, “SUB_REGION_NAME”, “PRODUCT_ID”, “PRODUCT_NAME”, “SALES_AMOUNT”,
WHEN “PRODUCT_NAME” = ‘Purse’ THEN 20
END AS “DISCOUNT”
var_out = select “REGION_NAME”, “SUB_REGION_NAME”, “PRODUCT_ID”, “PRODUCT_NAME”, “SALES_AMOUNT”,
“SALES_AMOUNT” – “DISCOUNT” AS “NET_AMOUNT” From :var3;
Right click on Columns in Output pane and click on “Create Target”.
This is the place where we specify the output columns. The output columns are the columns mentioned in last statement of the SQL script. Specify the name and data types as shown in figure below.
Select Semantics block. Now we need to specify which columns are attributes and which columns are measures. Click on the “Auto Assign” icon or click on the Type icon to specify Attribute/Measure.
Specify REGION_NAME, SUB_REGION_NAME, PRODUCT_ID, PRODUCT_NAME as attributes and SALES_AMOUNT and NET_AMOUNT as measure.
Right-click on your calculation view and choose “Data Preview”. After that, you can browse through the tabs named Raw Data, Distinct Values, and Analysis.
Raw Data tab:
Congratulation!! You have successfully created your first scripted calculation view.