You are on page 1of 8

| HOW-TO PAPER

[ SAP HANA Tutorial ]


mayato How-To Papers in the Area of Business Intelligence
Title:

Build your first SAP HANA model

Author(s):

Thorsten Fg

Topic:

SAP HANA

Published:

December 2012

Overview: How to build your first SAP HANA model


This tutorial describes how to build a simple model using data stored on SAP HANA. By the end of this tutorial, you will
have created tables, attribute views, and analytical views in SAP HANA.
Prerequisites
You have access to an SAP HANA system.
You have SAP HANA Studio installed on your machine.
You have SAP HANA Clients installed on your machine.
Topics
In this tutorial, you will learn how to:
1. Insert new tables in SAP HANA and fill them with data using the SQL editor
2. Create an attribute view
3. Create one analytic view
4. Browse and analyze the data of the analytical view
5. Create a second attribute view and modify your analytic view

The estimated completion time for this tutorial is 20 minutes.


Using a simple data model, you will learn the basic steps about how to model data in the SAP in-memory computing
studio.

Insert new tables in SAP HANA and fill them with data
1. Go to your schema. This is named like your SAP HANA system name.

Right-click on your schema and select SQL editor. Now you can insert the following code:
Note: Take your schema name instead of <YOUR SCHEMA> in the SQL syntax!
Table: ITIM_DIM
create column table "<YOUR SCHEMA>"."ITEM_DIM"(
"ITEM_ID" INTEGER null,
"ITEM_NAME" VARCHAR (100) null default '');
insert into "<YOUR SCHEMA>"."ITEM_DIM" values(1,'Shirts');
insert into "<YOUR SCHEMA>"."ITEM_DIM" values(2,'Jackets');
insert into "<YOUR SCHEMA>"."ITEM_DIM" values(3,'Trousers');
insert into "<YOUR SCHEMA>"."ITEM_DIM" values(4,'Skirts');
insert into "<YOUR SCHEMA>"."ITEM_DIM" values(5,'Purse');

Table: REGION_DIM
create column table "<YOUR SCHEMA>"."REGION_DIM"(
"REGION_ID" INTEGER null,
"REGION_NAME" VARCHAR (100) null default '',
"SUB_REGION_NAME" VARCHAR (100) null default '');
insert into "<YOUR SCHEMA>"."REGION_DIM" values(1,'Americas','NA');
insert into "<YOUR SCHEMA>"."REGION_DIM" values(2,'Americas','SA');
insert into "<YOUR SCHEMA>"."REGION_DIM" values(3,'APJ','Asia');
insert into "<YOUR SCHEMA>"."REGION_DIM" values(4,'APJ','Japan');
insert into "<YOUR SCHEMA>"."REGION_DIM" values(5,'EMEA','EMEA');

Table: SALES_FACT
create column table "<YOUR SCHEMA>"."SALES_FACT"(
"REGION_ID" INTEGER null,
"ITEM_ID" INTEGER null,
"SALES_AMOUNT" DOUBLE null);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(1,1,100);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(1,2,90);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(1,5,85);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(2,2,80);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(2,1,75);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(3,3,85);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(4,4,75);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(5,1,65);
insert into "<YOUR SCHEMA>"."SALES_FACT" values(5,2,65);
At the end of this section, you should have three tables:
If there are no tables, try right-clicking on your schema and refreshing.

Create an attribute view


Before we create the attribute view, we have one important step to do:
Open the SQL editor of your schema and insert the following command line:
Command: Give your schema SELECT rights for system table _SYS_REPO
GRANT SELECT ON SCHEMA <YOUR SCHEMA> TO _SYS_REPO WITH GRANT OPTION;
Note: Take your schema name instead of <YOUR SCHEMA> in the SQL syntax!
If you miss this step, an error will occur when you activate your views later. If you replicate data automatically, using
SAP LTR Server, this command is executed automatically in the background while creating a new schema.
After that, you can go ahead and create some attribute views.
To do this, please create a new package under the content folder. Right-click on the content folder and choose New > Package. Fill the fields Name and Description and click OK.

If there is no package, try right-clicking on the content folder


and refreshing.
We want to create an attribute view for the table
REGION_DIM. Right-click on your package and choose New
Attribute View. Enter a name and a description and click
Next.

After that, select your schema and the table REGION_DIM.


Click Finish.

Now you can define the attributes and key attributes you want to see later in the analyses. Right-click on the attributes
and choose Add as key attribute or Add as attribute.
In our case, the REGION_ID is added as the key attribute and the fields REGION_NAME and SUB_REGION_NAME are
added as attributes.

At the end, save and activate the attribute view. You can do this using the context menu by right-clicking on your
attribute view or using the status bar at the top of the output frame.

Please take note of the status massage in the job log frame at the bottom if there are any problems during activation.

Now we want to create an analytic view before the second attribute view.

Create an analytic view


We want to create an analytic view for the table SALES_FACT. Right-click on your package and choose New Analytic
View. Enter a name and description and click Next.

After that, select your schema and the table SALES_FACT. Click Finish.
In the data foundation tab, select REGION_ID as Add as attribute and the field SALES_AMOUNT as Add as measure.

After you saved the view, you can switch to the logic view tab. Now put the attribute view ATTR_REGION into the
window using the drag-and-drop feature. Afterwards, connect the key fields REGION_ID with a n..1 referential join.

Finally, save and activate the view, as you did before with the attribute view.

Browse and analyze the data


Right-click on your analytic view and choose Data Preview.
After that, you can browse through the tabs named raw data, distinct values, and analysis.

Create a second attribute view and modify your analytic view


Now we want to add a second attribute view to our analytic view.
To do this, in the first step, we create a second attribute view with the name ATR_ITEM and the table ITEM_DIM.
Now you can define the attributes and key attributes you want to see later in the analyses. Right-click on the attributes
and choose Add as key attribute or Add as attribute.
In our case, the ITEM_ID is added as the key attribute and the field ITEM_NAME as an attribute.

At the end, save and activate the attribute view. You can do this using the context menu by right-clicking your attribute
view or using the status bar at the top of the output frame, if everything was correctly activated.
Go back to your analytic view. At this point, you must switch to the data foundation tab first. Here, select the field
ITEM_ID as Add as attribute and save your view. Then switch back to the logical view and drag your attribute view
ATR_ITEM into the window. Afterwards, join the fields ITEM_ID of both views, also with an n..1 referential join, as you
did before.

Save and activate the analytic view and take a look at the preview data again.

References
Part of this tutorial is based on the following source: http://www.youtube.com/watch?v=9hM83qw9tYs

You might also like