0% found this document useful (0 votes)
94 views85 pages

Sap Hana Modeling Workshop

RDP361ex

Uploaded by

prasadn66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views85 pages

Sap Hana Modeling Workshop

RDP361ex

Uploaded by

prasadn66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 85

SAP HANA MODELING WORKSHOP

RDP361
2

EXERCISE 1 – BASKET ANALYSIS [10 MINUTES]....................................................................................... 4


Exercise 1.1 Create a Calculation View ......................................................................................................... 5
Exercise 1.2 Execute & Test ......................................................................................................................... 13
EXERCISE 2 – DYNAMIC JOIN [15 MINUTES] ............................................................................................ 14
Exercise 2.1 Create a Calculation View ....................................................................................................... 15
Exercise 2.2 Execute & Test ......................................................................................................................... 21
EXERCISE 3 – DYNAMIC TIME PERIODS [20 MINUTES] ........................................................................... 22
Exercise 3.1 Create a Analytical View ......................................................................................................... 23
Exercise 3.2 Execute & Test ......................................................................................................................... 29
EXERCISE 4 – DYNAMIC YEAR COMPARISON [20 MINUTES] ................................................................. 31
Exercise 4.1 Create a Calculation View ....................................................................................................... 32
Exercise 4.2 Execute & Test ......................................................................................................................... 40
EXERCISE 5 – RANKING [30 MINUTES] ...................................................................................................... 41
Exercise 5.1 Create an Analytical View ....................................................................................................... 42
Exercise 5.2 Execute & Test ......................................................................................................................... 44
Exercise 5.3 Create a Script-based Calculation view ................................................................................ 45
Exercise 5.4 Execute & Test ......................................................................................................................... 48
Exercise 5.5 Create a Graphical Calculation View ..................................................................................... 49
Exercise 5.6 Execute & Test ......................................................................................................................... 55
EXERCISE 6 – DECISION TABLE [30 MINUTES] ........................................................................................ 56
Exercise 6.1 Create a Decision Table .......................................................................................................... 57
Exercise 6.2 Execute & Test ......................................................................................................................... 63
Exercise 6.3 Create a SQL script calculation view ..................................................................................... 64
Exercise 6.4 Execute & Test ......................................................................................................................... 67
Exercise 6.5 Create a Graphical Calculation View ..................................................................................... 68
Exercise 6.6 Execute & Test ......................................................................................................................... 77
EXERCISE 7 – SAP LUMIRA [10 MINUTES] ................................................................................................ 81
3

BEFORE YOU START

In this session RDP361 you have the opportunity work on several exercises that focuses primarily on
Graphical Calculation views. However, several of the exercise also contains Script-based Calculation Views
and Analytical Views and how to integrate them all together.

Due to time constraints during the Hands-on session, it is recommended that you first take a look at the
different exercises and how long they should take you and then decide which ones you want to work
through first.

Exercise 1 (Basket Analysis)


10 Minutes
Create a Graphical Calculation view that reads data from an Analytical view and displays the average
amount per order by category. This can be accomplished by the use of multi-level aggregation and counters.

Exercise 2 (Dynamic Join)


10 Minutes
Create a Graphical Calculation view that reads data from an Analytical view and ranks the profitability of
products across region and country. This can be accomplished by using a self-join or (dynamic join).

Exercise 3 (Dynamic Time Period)


15 Minutes
Create a multi-purpose Analytical View that is able to dynamically calculate sales based on user prompts.
The user will select from a selection of time period types (i.e. Current Year Sales, Previous Year Sales, or
Custom date ranges) and then the system will dynamically calculated the sales through the use or input
parameters, calculated attributes/measures & dynamic syntax expressions.

Exercise 4 (Year Comparison)


20 Minutes
Create a Graphical Calculation view that compares sales between 2 years. The model will prompt the end
user to supply the 2 years that needs to be calculated – without supplying prompts the model will
automatically calculate this year versus last year sales. This can be accomplished using Input Parameter’s
(constant expressions), dynamic constraint filters and Unions.

Exercise 5 (Ranking)
30 Minutes
This exercise will combine several different models (Analytical, Script-based & Graphical) to calculate and
rank customers by total revenue and amount of orders within a specific time range. Analytical views will be
used to calculated total number of orders, including aggregation of total sales. A Script-based calculation
view will be used to perform the actual ranking functions. Finally a Graphical calculation view wrapper will be
used to derive the time range from a table instead of having to prompt the user.

Exercise 6 (Decision Table)


30 Minutes
Create a report that displays customer discounts based on their ranking. This can be accomplished by
creating a decision table and applying rules to the customer ranking list created in Exercise 5. A Script-based
Calculation view is used to call the Decision table procedure. Finally a Graphical Calculation view is used to
compare discounts per region using an optimized source pruning method that can be seen by reviewing the
Visualize plan.

Exercise 7 (SAP Lumira)


10 Minutes
Use SAP Lumira to display customer sales versus orders using the Calculation view created in exercise 5.1
4

EXERCISE 1 – BASKET ANALYSIS [10 MINUTES]


In this exercise calculate the average order size by category. That means for each category determine how
many orders included that category. Then for each category sum up those order amounts and divide that by
the number of orders from the previous step.
5

Exercise 1.1 Create a Calculation View

Explanation Screenshot

Start SAP HANA Studio

Start > All Programs > SAP >


SAP HANA >
SAP HANA Studio – RDP361

Using the Modeler Perspective >


Expand the folder RDP361 > Right
click on the HANA System M41
(DEMO) > Add Additional User …

Enter RDP361_X, replace X with


your assigned student number.

Password = Welcome13

Click Finish.

Info: The tables for this session are


located in the RDP361 schema.

Expand the Catalog folder >


RDP361 > Tables
6

Explanation Screenshot

Optional: The solution content for


this session are located under the
Content folder > rdp361 > solution

Your assigned folder is located


under the Content folder > rdp361 >
your assigned session folder > your
assigned student number

Exercise 1: Create a Calculation


View.

Right click on your assigned student


folder > select New …

Select Calculation View from the list


of options.
7

Explanation Screenshot

Enter
SALESORDER_BASKET_ANALYSI
S_CV for the name of the view.

Instead of creating a new view use


Browse … and copy of an existing
view.

Check Copy From: Then click


Browse > and select the
SAMPLE_CV calculation view
located in the solution exercise1
folder.

Click Finish.
8

Explanation Screenshot

The calculation view currently


displays orders line items and order
header information.

Start by inserting an Aggregation


Node between the Projection Node
and the Second Join Node.

Hint: Left click (only once) on the


Aggregation Icon and then click on
the connection line.

Click Yes to insert the Aggregation


node.

Proceed to select the Aggregation


Node.
9

Explanation Screenshot

In the Details area of the


Aggregation Node add
NET_AMOUNT to the Output.

Right Click on NET_AMOUNT > Add


As Aggregated Column

Assign Max Aggregation to


NET_AMOUNT

In the Output area select


NET_AMOUNT > then in the
Properties view select Max
Aggregation.

Hint: The total order (Net Amount) is


located on the Order header and will
therefore get duplicated due to the
join to Order items. That means that
summing up Net Amount will be
incorrect, therefore MAX (or MIN)
need to be used to get the correct
(single) Net Amount per order.

Proceed. Right click on the


Projection node and select ‘Switch to
Aggregation’
10

Explanation Screenshot

Add the NET_AMOUNT column to


the Output.

Create a new Counter called


COUNTER.

Within the Output area select


Calculated Columns > Right click >
New Counter

Name the Counter > COUNTER

Hint: The aim is to determine, for a


given category the amount of orders
that included that category.

Add both columns SO_KEY &


CATEGORY columns.

Hint: Count distinct of Order Item


and Category will render the correct
count.
11

Explanation Screenshot

Create a Calculated Column


(Measure) called SALES.

Select Calculated Columns > Right


click > New Calculated Column

Assign DECIMAL as the data-type,


and select Measure as the Column
Type.

Assign the DECIMAL length 15 with


Scale 2.

Add calculations. Within the


Expression Editor area divide
NET_AMOUNT by the COUNTER.
12

Explanation Screenshot

Proceed. Select the Semantics node.

Hide the following columns:

SO_I_KEY
NET_AMOUNT
COUNTER

Save and Activate your work.

Within the Job Log view > ensure


that the Activation completed
successfully.
13

Exercise 1.2 Execute & Test


Explanation Screenshot

Open the SQL Editor to test the


model.

Hint. Select your connection first


RDP361_X (where X is your
assigned student number). Then
click on the SQL Editor Icon.

SELECT "CATEGORY", SUM("SALES") AS SALES


FROM "_SYS_BIC"."rdp361.session0.0/
Enter the following SQL – remember SALESORDER_BASKET_ANALYSIS_CV"
change the session number and WHERE CREATED_ON = '20130112'
student number according to your AND CATEGORY IN
assigned numbers. ('Notebooks', 'Handhelds', 'Flat screens')
GROUP BY "CATEGORY"
ORDER BY SALES DESC

Press F8 or click the green execute


arrow button.

Results are as follow.


14

EXERCISE 2 – DYNAMIC JOIN [15 MINUTES]


In this exercise display the top 10 most profitable products by country and by region. Create a Graphical
Calculation View and Join (Dynamic Join by Region & Country) the Sales Orders to itself. Depending on the
fields selected the aggregations will either occur on country or region first followed by the join and last the
division between sales and total sales to produce the total sales versus shared sales.

Take product HT-1502 as an example. Total sales for the APJ region (includes 2 countries) for this product
equal 12 Million, total sales across all products in the APJ region equal 30 Million. The share sales number is
calculated by dividing the 2 numbers. Alternatively you can change the query to rank profitability by country
and product and then sales and total sales will be calculated by country instead of by region.
15

Exercise 2.1 Create a Calculation View

Explanation Screenshot

Create a new Calculation View in


your assigned student folder:

Enter
SALESORDER_DYNAMIC_JOIN_CV
for the name of the view.

Rather than creating an entirely new


view instead use Browse .. and make
a copy of an existing view.

Click > Copy From: and select the


SAMPLE_CV calculation view located
in the solution exersice2 folder

Add an additional Aggregation node


to the work area.

Add SALESORDER_AV to the


Aggregation node.

Within the solution folder > exercise2


> select SALESORDER_AV and drag
and drop that into the Aggregation
node.

Proceed. Select the Aggregation


node.
16

Explanation Screenshot

Within the details work area. Add the


column NET_AMOUNT to the Output.

In addition add the following columns


to the Output.

COUNTRY
REGION
PRODUCT_ID

Rename the column NET_AMOUNT


to SALES.

Hint: In the Output area select


NET_AMOUNT > In the Properties
area rename both the Name and the
Label.
17

Explanation Screenshot

Join the 2 Aggregation nodes by


inserting a Join node.

Hint: Click the Join icon > then click


on the connection line between the
bottom Aggregation_1 and the top-
most Aggregation node. This will
insert the Join node and connect the
lines automatically.

Connect the newly added


Aggregation node to the Join node.

Hint: Drag a connection line from the


Aggregation node to the Join node.

Proceed. Select the Join node.

Within the details area add the join


key columns.

Hint: Select the COUNTRY column


on the left and drag a line to the
COUNTRY column on the right.

Proceed to join the REGION column.


18

Explanation Screenshot

As a result of adding the join


connection lines 2 additional columns
were added to the Output. Proceed
to remove the following columns as
they are duplicate and not needed.

COUNTRY_1
REGION_1

Single click to add the following


COLUMS from the Aggregation node
(2) on the RIGHT.

SALES
PRODUCT_ID

Assign the Dynamic Join.

Select any of the 2 Join connection


lines.

In the Properties area > Dynamic Join


> True
19

Explanation Screenshot

Proceed. Select the Aggregation


Node.

Add the following 2 columns to the


Output area.

Product ID
SALES ( as an Aggregated Column)

Within the Output area. Create a new


Calculated Measure.

Select Calculated Columns > Right


click > New Calculated Column

Enter SHARE_SALES for the name


of the Calculated Column.

Assign DECIMAL as the data-type,


and select Measure as the Column
Type.

Assign the DECIMAL length 12 with


Scale 5.
20

Explanation Screenshot

Divide SALES by TOTAL_SALES

Hint. Manually type in the following


code. Use the double function to cast
the decimal to a double in order for
the division to work.

Proceed. Select the Semantics area.

Assign Attributes/Measures to the


Output Columns.

Hint: Click the ‘Auto Assign’ button.

Save and Activate your work!


21

Exercise 2.2 Execute & Test


Explanation Screenshot
SELECT TOP 10 "REGION", "PRODUCT_ID",
Within the SQL Editor execute the sum("SALES") AS "SALES",
following SQL to determine the sum("TOTAL_SALES") AS "TOTAL_SALES",
profitability by Region and Product. sum("SHARE_SALES") AS "SHARE_SALES"
FROM
Remember to add your assigned "_SYS_BIC"."rdp361.session0.0/SALESORDER_DYNAMIC_JOIN_CV"
session/student number GROUP BY "REGION", "PRODUCT_ID"
ORDER BY "SHARE_SALES" DESC;

Results show the shared sales by


product and region.

Hint: Sales equal the total sales for


product HT-1502 in APJ region.
Total Sales equals the total sales
across APJ for all products.

SELECT TOP 10 "COUNTRY", "PRODUCT_ID",


Optional:
SUM("SALES") AS "SALES",
SUM("TOTAL_SALES") AS "TOTAL_SALES",
Within the SQL Editor execute the
sum("SHARE_SALES") AS "SHARE_SALES"
following SQL…
FROM
"_SYS_BIC"."rdp361.session1.0/SALESORDER_DYNAMIC_JOIN_CV"
This will show you the most
GROUP BY "COUNTRY", "PRODUCT_ID"
profitable product by country.
ORDER BY "SHARE_SALES" DESC

Results show the shared sales by


product and country. However, now
the sales are per product id and
country. And total sales are per
country.
22

EXERCISE 3 – DYNAMIC TIME PERIODS [20 MINUTES]


This exercise will show how to create a single dynamic model that calculates sales based on various time
period types. (i.e. Current Year Sales, Previous Year Sales, or Custom date ranges). You can use as many
time period parameters as required, in the interest of time the exercise will only focus on 3 periods. The
model will prompt the user to select a period type, for example by selecting ‘Current Year Sales’ the
calculations will occur dynamically based only on the current year sales. Alternatively if the user selects
‘Previous Year Sales’ then the system will dynamically calculated the sales for the previous year. Finally, the
user can supply a custom date range by selecting ‘Start Date-End Date’ as the period type. Note: 2
additional parameters (Start-Date & End-Date) are required when selecting a customer date range.

Once the final model is completed the


user will then be able to query the model
for Current Year sales by using a single
parameter/prompt.

Period Type = Current Year

Alternatively the user can also query the


model for Previous Year sales using the
following parameter/prompt.

Period Type = Pervious Year

The user can also query the model for


sales but based on a custom date range.

Period Type = Start Date-End Date


Start Date = 20110101
End Date = 20120314

Hint. Notice that in the case of a custom


date range the Period Type is set to
‘Start Date-End Date’
23

Exercise 3.1 Create a Analytical View


Explanation Screenshot
Create a new Analytical View:

Click on your folder Content >


assigned session > assigned student
number > Right-click > NEW >
Analytical View

Name :
SALESORDER_DYNAMIC_TIME_PE
RIOD_AV

Rather than creating an entirely new


view instead use Browse and select of
an existing view.

Click > Copy From: and select the


SAMPLE_AV analytical view located in
the solution exercise3 folder

Start by selecting the Logical Join


node.
24

Explanation Screenshot

In the Output area create 3 input


parameters.

Right click on Input Parameters > New

Name the first input parameter:

IP_StartDate

Make sure to select the appropriate


Data type (Date) and Parameter Type
(Direct).

Hint. This input parameter is only


required when a custom date range
period type is selected.

Continue to add another input


parameter called IP_EndDate. As
before assign the Data type (Date) and
Parameter Type (Direct).

Hint. This input parameter is only


required when a custom date range
period type is selected.
25

Explanation Screenshot

Create a third input parameter called


IP_PeriodType

However this time, select Static List for


the Parameter Type.

Define the Data Type:


VARCHAR 20

Click on the Add icon three times and


add the following Names:

Start Date-End Date


Current Year
End Year

Create a New Calculated (Attribute)


Column.
26

Explanation Screenshot

Name: CA_StartDate

Data Type: Date

Column Type: Attribute

Enter the following case statement


expression.

You can find a copy of the code within


session folder.

(STUDENT_EXAMPLE_CODE.TXT)

Hint. If the period type equals ‘Start


Date-End Date’ then the input
parameter (IP_StartDate) is used,
however if the period type equals
either Current Year or Previous Year
then the system dynamically
calculates CA_StartDate.

Proceed to create another Calculated


Attribute.

Name: CA_EndDate

Data Type: Date

Column Type: Attribute


27

Explanation Screenshot
Enter the following case statement
code. (You can find a copy of the code
within session folder.)

(STUDENT_EXAMPLE_CODE.TXT)

Hint. If the period type equals ‘Start


Date-End Date’ then the input
parameter (IP_EndDate) is used,
however if the period type equals
either Current Year or Previous Year
then the system dynamically
calculates CA_EndDate.

Create a Calculated Measure called


CM_NetAmount

Data Type: DECIMAL

Column Type: Measure

Enter the length and the scale


accordingly for the Decimal data type.

Enter the following syntax into the


Expression Editor. Net Amount will be
calculated for sales that only occur
within the specific time range. if("DATE_SQL" >= "CA_StartDate" AND "DATE_SQL"<= "CA_EndDate" ,
"NET_AMOUNT", 0 )
Hint: The DATE_SQL column is
defined on the time-based dimension.
28

Explanation Screenshot

The final Output should look as


follows.

Save and Activate your work.


29

Exercise 3.2 Execute & Test


Explanation Screenshot
Execute the following SQL statement
with the SQL Editor. Remember to SELECT
adjust your session and student "CATEGORY","CA_StartDate","CA_EndDate",SUM("CM_NetAmount")
number. FROM "_SYS_BIC"."rdp361.session0.0/
SALESORDER_DYNAMIC_TIME_PERIOD_AV"
Notice the Period Type is assigned GROUP BY "CATEGORY", "CA_StartDate", "CA_EndDate"
Start Date-End Date. That means WITH PARAMETERS (
that you also have to assign values 'PLACEHOLDER' = ('$$IP_PeriodType$$','Start Date-End Date'),
for the start and end date 'PLACEHOLDER' = ('$$IP_StartDate$$', '20110101'),
parameters. 'PLACEHOLDER' = ('$$IP_EndDate$$','20120314')
);

As a result the Calculated Measure


Amount is displayed.

Proceed to execute the following SELECT


SQL statement.
"CATEGORY","CA_StartDate","CA_EndDate",SUM("CM_NetAmount")
FROM "_SYS_BIC"."rdp361.session0.0/
Notice that the Period Type is
SALESORDER_DYNAMIC_TIME_PERIOD_AV"
assigned Current Year. Therefore
GROUP BY "CATEGORY", "CA_StartDate", "CA_EndDate"
the current year sales will
WITH PARAMETERS (
automatically be calculated and
'PLACEHOLDER' = ('$$IP_PeriodType$$', 'Current Year')
therefore the start and end date
);
parameter’s are not required.

As a result notice the system


automatically calculated the start
date of the current year plus the end
date. Keep in mind the end date
reflects the current date when the
query was executed.

SELECT
"CATEGORY","CA_StartDate","CA_EndDate",SUM("CM_NetAmount")
FROM "_SYS_BIC"."rdp361.session0.0/
Change the SQL to report on the SALESORDER_DYNAMIC_TIME_PERIOD_AV"
Previous Year’s sales. GROUP BY "CATEGORY", "CA_StartDate", "CA_EndDate"
WITH PARAMETERS (
'PLACEHOLDER' = ('$$IP_PeriodType$$', 'Previous Year')
);
30

Explanation Screenshot

The results are shown accordingly.


31

EXERCISE 4 – DYNAMIC YEAR COMPARISON [20 MINUTES]


This exercise will show how to create a model that will dynamically calculate and compare sales between 2
years. The model contains optional (year 1 and year 2) parameters and therefore can either be executed
with or without parameters. If the model is executed without parameters then the current and previous year
sales will automatically be calculated. In order to over-ride the default behavior the user can supply year 1 &
year 2 parameters to calculated sales comparisons between those two custom years.

Select Category, year2, year1 from


Model …

Select Category, year2, year1


From Model where …
Year 1 = 2011
Year 2 = 2012
32

Exercise 4.1 Create a Calculation View


Explanation Screenshot

Create a new Graphical Calculation View:

SALESORDER_YEAR_COMPARISON_CV

Start by adding 2 projection nodes into the


work area.

Add SALESORDER_AV (located in the


solution > exercise4 folder) into each
Projection node.

Hint. You can drag and drop the model unto


each projection node.

Start by first selecting the Projection node on


the left.
33

Explanation Screenshot

In the details-area add the following columns


to the Output

NET_AMOUNT
CATEGORY
YEAR

The results look as follows.

Select the second Projection node (on the


right) and add the same columns to the
Output.

Add NET_AMOUNT, CATEGORY & YEAR.

In the Output create 2 input parameters.


34

Explanation Screenshot

Define the first input parameter as follows:

Name: IP_YEAR_1
Parameter Type: Direct

Select Expression for the Default Value and


enter the following expression.
midstr(string(now()),1,4)

Data Type: VARCHAR (4)

Hint: This will produce the current year (i.e.


2013) as a default value if no parameters are
supplied.

Define the second input parameter as follows:

Name: IP_YEAR_2
Parameter Type: Direct

Select Expression for the Default Value and


enter the following expression.

string(double(midstr(string(now()),1,4))-1)

Data Type: VARCHAR (4)

Hint: This will produce the previous year (i.e.


2012) as a default value if no parameters are
supplied.

Assuming the second projection node is still


selected continue to apply a filter.
35

Explanation Screenshot

In the Output area right click on the column


YEAR > Apply Filter

Select the Equal Operator and enter


$$IP_YEAR_2$$ in the value field.

Click OK.

Hint. $$IP_YEAR_2$$ represents the year 2


input parameter value.

Repeat the steps for the first Projection node,


as before start by selecting the Projection node
(1).

Within the Output node apply a filter for the


YEAR.
36

Explanation Screenshot

This time enter $$IP_YEAR_1$$ for the Value.


Click OK.

Add a Union node to the work area above the


Projection nodes.

Connect the 2 projection nodes to the Union by


using a connection line.

Proceed to select the Union node.


37

Explanation Screenshot

In the Details area define the mappings for the


Union.

Click on the ‘Auto Map’ icon.

Hint. You can also manually perform the


mapping by dragging and connecting the
columns individually.

Remove the NET_AMOUNT mapping from the


second projection.

Instead define a vertical union by dragging-


dropping the NET_AMOUNT column unto the
white-space area in the Target area.
38

Explanation Screenshot

Connect the Union node to the Aggregation


node by dragging a connection line.

Select the Aggregation node.

Add Category and Year to the output area.

Add NET_AMOUNT & NET_AMOUNT_1 as


Aggregated Columns to the Output.
39

Explanation Screenshot

Within the Properties area rename the 2


measures as follows

NET_AMOUNT > YEAR1_NET_AMOUNT

NET_AMOUNT_1 > YEAR2_NET_AMOUNT

Select the Semantics node.

Hide the YEAR column.

Save and Activate your work.


40

Exercise 4.2 Execute & Test


Explanation Screenshot
SELECT "CATEGORY",
Within the SQL Editor execute the sum("YEAR2_NET_AMOUNT") AS "YEAR2_NET_AMOUNT",
following SQL statement. Remember sum("YEAR1_NET_AMOUNT") AS "YEAR1_NET_AMOUNT"
to supply your assigned session and FROM "_SYS_BIC"."rdp361.session0.0/
student number. SALESORDER_YEAR_COMPARISON_CV"
GROUP BY "CATEGORY";

The results are shown.

Hint. Since no parameters were


supplied the model automatically
calculated current year vs last year
sales. Year 2 represents last year
and Year 1 represents the current
year sales.

SELECT "CATEGORY",
sum("YEAR2_NET_AMOUNT") AS "YEAR2_NET_AMOUNT",
Alter the SQL statement by adding sum("YEAR1_NET_AMOUNT") AS "YEAR1_NET_AMOUNT"
input parameters and thereby FROM "_SYS_BIC"."rdp361.session0.0/
overriding the default values. SALESORDER_YEAR_COMPARISON_CV"
GROUP BY "CATEGORY"
YEAR 1 = 2011 WITH PARAMETERS (
YEAR 2 = 2012 'PLACEHOLDER' = ('$$IP_YEAR_1$$', '2011'),
'PLACEHOLDER' = ('$$IP_YEAR_2$$', '2012')
)

The results are shown based on the


years supplied.
41

EXERCISE 5 – RANKING [30 MINUTES]


This exercise contains 3 steps and at the end will combine all of the models. The different models (Analytical,
Script-based & Graphical) will all be used to calculate and rank customers by total revenue and amount of
orders placed within a specific time range. Analytical views will be used to aggregate total sales plus to
calculate the order count. A Script-based calculation view will be used to rank those numbers. Finally a
Graphical calculation view wrapper will be used to derive the date range from a table (instead of having to
prompt the user).

Select
company,
total sales,
number of orders,
sales total rank,
order total rank
from Model …
42

Exercise 5.1 Create an Analytical View


Explanation Screenshot
Create a new Analytical View:

Click on your folder Content >


assigned session, assigned student
number package > Right-click >
NEW > Analytical View

Name:
SALESORDER_RANKING_AV

Rather than creating an entirely new


view instead use Browse .. and
make a copy of an existing view.

Click > Copy From: and select the


SAMPLE_AV calculation view
located in the solution exercise5
folder

Start by selecting the Data


Foundation.

Add column SO_ID to the Output.


Notice. Since there is already a
column named SO_ID the new
column will be named SO_ID_1.

Hint: The SO_ID_1(Order ID) will be


used to get the COUNT of all orders.

Proceed by selecting the Logical


Join area.
43

Explanation Screenshot

Rename column SO_ID_1 to


ORDERS within the Properties area.

Hint. Orders will represent the total


amount of orders.

Select the Semantics node.

Select the ORDERS column and


change the Type to a Measure.

Note: Count aggregation is


automatically assigned.

Save and Activate your work.


44

Exercise 5.2 Execute & Test


Explanation Screenshot
SELECT
Execute the following SQL statement
COMPANY_NAME, SUM(NET_AMOUNT) AS SALES, COUNT(ORDERS)
within the SQL Editor. Supply your
FROM "_SYS_BIC"."rdp361.session0.0/
session and student number.
SALESORDER_RANKING_AV"
WHERE DATE_SQL BETWEEN '20130101' AND '20130112'
GROUP BY COMPANY_NAME;

As a result notice the number of


orders per customer.
45

Exercise 5.3 Create a Script-based Calculation view

Based on the order count and order total determine the ranking.

Explanation Screenshot

Create a new Script-based


Calculation View:

Name:
SALESORDER_RANKING_SQL_CV

Rather than creating an entirely new


view instead use Browse .. and
make a copy of an existing view.

Click > Copy From: and select the


SAMPLE_CV calculation view
located in the solution exercise5
folder

Start by selecing the Script_View


node and review the SQL statement
within the Details section.
46

Explanation Screenshot
BEGIN
var_out =
select
company_name, sales, orders, sales_rank, order_rank
from(
select
Change the SQL ranking code; enter company_name, sum(net_amount) as sales,
your assigned session and student count(orders) as orders, dense_rank() over
number and reference your ( order by sum(net_amount) desc )
Analytical view created in the as sales_rank, dense_rank() over
previous step.
(
order by count(orders) desc
Also, uncomment the WHERE
) as order_rank
clause line.
from
>>>> “_SYS_BIC”.”rdp361.session0.0/
Hint. Notice the where clause input
SALESORDER_RANKING_AV”
parameters that will first filter the
where
Analytical view before the ranking
functions occur on a smaller more >>>> date_sql between :IP_FR_DTE and :IP_TO_DTE
precise data-set. group by
company_name
order by
sales_rank, company_name
)
where sales_rank < 11;
END

Create 2 input parameters.


47

Explanation Screenshot

Name: IP_FR_DTE
Type: Direct
Semantic Type: Date

Hint. This represents the From Date.

Name: IP_TO_DTE
Type: Direct
Semantic Type: Date

Hint. This represents the TO date.

Save and Activate


48

Exercise 5.4 Execute & Test


Explanation Screenshot
SELECT
"COMPANY_NAME", "SALES", "ORDERS", "SALES_RANK","ORDER_RANK"
Execute the following SQL statement
FROM "_SYS_BIC". "rdp361.session0.0/
using the SQL Editor.
SALESORDER_RANKING_SQL_CV"
WITH PARAMETERS (
Enter your assigned session and
'PLACEHOLDER' = ('$$IP_FR_DTE$$', '20130101'),
student number.
'PLACEHOLDER' = ('$$IP_TO_DTE$$', '20130112')
);
The results are shown. Notice the
Sales and Order Ranking produced
by the SQL ranking functions. Notice
the ORDERS column, calculated
using the Analytical View.
49

Exercise 5.5 Create a Graphical Calculation View

The previous model requires 2 mandatory input parameters. In this exercise instead of the user specifying
the TO and FROM parameters, create a Calculation view wrapper that will automatically read the parameter
values from a table and therefore hiding the input parameters from the user.

Explanation Screenshot

Create a new Graphical Calculation


View.

Name:
SALESORDER_RANKING_CV

Uncheck ‘Enable Multi-Dimensional


Reporting’

Drag the Calculation view (created in


the previous step) unto the
Projection node.

Select the Projection node.


50

Explanation Screenshot

Add all the Columns to the Output.

Right click on Input Parameters >


select Manage Mappings.

Drag the 2 input parameters into the


Target area.

Hint. The 2 input parameters were


inherited from the Script-based
calculation view.
51

Explanation Screenshot

Proceed to Edit both Input


Parameters and change the behavior
to Derive the parameter values from
a table instead.

First select IP_FR_DTE > right click


> Edit ..

Change the Parameter Type to


‘Derive from Table’

Click the Dialog Icon to select a


Table ..

When the Table Dialog Window


appears, scroll down and select table
ZSalesOrderFilter located within the
RDP361 schema.

Click Ok.
52

Explanation Screenshot

Click on the Return Column dialog


icon ..

Select COLVALUE as the Return


Column..

Add filters by clicking the Add button


..

Click the Filter Column dialog icon …


53

Explanation Screenshot

Select MODEL as the filter ..

Click on the Filer Value dialog icon


Select
SALESORDER_RANKING_AV

Proceed to add another Filter


Column called COLNAME with
FROM as the Filter Value.
54

Explanation Screenshot

Edit the second input parameter


IP_TO_DTE and repeat the previous
steps except when defining the
COLNAME select TO.

Proceed. Select the Semantics node.

Click on the Auto Assign icon and


ensure that all the columns are
defined as Attributes.

Save and Activate your work!


55

Exercise 5.6 Execute & Test


Explanation Screenshot
Execute the following SQL statement
to see what the static input SELECT * FROM "RDP361"."ZSalesOrderFilter"
parameters values are.

The following input parameters will


automatically be assigned when the
view is executed.

SELECT
Execute the following SQL
"COMPANY_NAME","SALES","ORDERS","SALES_RANK","ORDER_RANK"
statement. Enter your assigned
FROM
session and student number.
"_SYS_BIC"."rdp361.session0.0/SALESORDER_RANKING_CV"

The results are as follows. Orders


count is executed by the Analytical
View, the sales and order ranking
are executed by the SQL script
calculation view. The filters are
automatically being red by the
Graphical Calculation view.
56

EXERCISE 6 – DECISION TABLE [30 MINUTES]


This exercise contains 3 steps. Create a report that displays customer discounts based on their ranking.
This can be accomplished by creating a decision table and applying rules to the customer ranking list created
in Exercise 5. A Script-based Calculation view is used to call the Decision table procedure. Finally a
Graphical Calculation view is used to compare discounts per region using an optimized source pruning
approach that can be seen by reviewing the Visualize plan.

Decision Table

Customer discount rates in the APJ region


57

Exercise 6.1 Create a Decision Table

Create a decision table based on a table type, this will allow you to have a generic rule that can get re-used
assuming the data-set passed into the rule conforms to the table-type columns. The rule will take in a
customer list based on the rankings calculated in Exercise 5 and will return discounts for each customer.

Explanation Screenshot
Create a Decision Table in your assigned
package.

Name:
CUSTOMER_DISCOUNT_CALCULATION_
DT

Click Finish

The decision table will be based on a table


type. Click on the Add Table icon …

In the Find Objects window search and


select the following table type

CUSTOMER_DISCOUNT_CALCULATION_
TT

Click OK.

Note: The table type was created


beforehand for you.
58

Explanation Screenshot
Info. You can view the table types in the
SYSTEM_BIC schema.

Proceed. Click on the Data Foundation tab.

Add all the columns as Attributes to the


Output.

Note: The attributes must be added in the


same order they appear in the table – in
order for the data import step to work later.

In the Output area add the following columns


as Conditions.

REGION
SALES
ORDERS
SALES_RANK
ORDER_RANK

Hint. Conditions are essentially the data


input parameters and based on the values of
these columns a discount it determined.
Notice, customer name is not selected.
59

Explanation Screenshot
Create a new Parameter

Hint. The Parameter mentioned here is NOT


the same as input parameter used in regular
modeled views. Parameters within the
context of a Decision Table are values
returned, basically the calculated Discount.

Name: DISCOUNT
Default Value: 1.5

Data Type: Decimal


Length: 12
Scale: 2
60

Explanation Screenshot
Add the Discount as an Action.

Hint. The action is what will essentially get


calculated and returned from the rule.

Proceed. Click on the Decision Table tab.

Right click in the area underneath Region >


Add Condition Values

Enter the following regions..

AMEA
AMER

Click OK.
61

Explanation Screenshot
Delete the Default Value

Right click > Delete

Click in the Sales (cell) for AMEA and enter


> 1000000

Add the following values for the rest of the


columns

ORDERS > 2000


SALES_RANK <3
ORDER_RANK <3
DISCOUNT 3.5

Instead of filling out the entire table


manually, proceed to Import the Data from
Excel spread-sheet prepared beforehand.

Note: In reality you as a modeler will most


likely not know the discount values. If that is
the case, export the current decision table as
an Excel spread-sheet and forward the
template to a business user. Once they have
added the discount values you can import
the file as follow.

Right Click (underneath the decision table) >


select Import Data from Excel)
62

Explanation Screenshot
Within the session folder (click on the
Student Share folder on the desktop) and
select the file called
CUSTOMER_DISCOUNT_CALCULATION_
DT.xlsx

The imported table results looks as follows.

Save and Activate your work.

Info: If you get any errors during the


activation, un-check all the Decision table
validation rules within the SAP HANA Studio
preferences.

Hint: Window > Preferences > Modeler >


Validation Rules > Decision Table
63

Exercise 6.2 Execute & Test


Explanation Screenshot
Optional. Since the decision table is
based on a table type testing is not
that straight forward compared to if
the decision table was based on a
static model or table. CREATE COLUMN TABLE TEMP_DECISION_TABLE_DATA AS (
select
Execute the following SQL statement 'SAP' as company_name,
within the SQL Editor. This will 'EMEA' as region,
create a test table that you can use 100 as sales,
to test your decision table procedure. 300 as orders,
1 as sales_rank,
In the next exercise you will see how 3 as order_rank from DUMMY
to re-use the decision table );
procedure in a real-scenario.

Hint. The table is located in your CALL


assigned student numbers schema. "_SYS_BIC"."rdp361.session0.0/CUSTOMER_DISCOUNT_CALCULATION_
DT" (TEMP_DECISION_TABLE_DATA, ?);
Hint. If the table already exists,
proceed to drop the table. (i.e.
DROP TABLE
TEMP_DECISION_TABLE_DATA)
64

Exercise 6.3 Create a SQL script calculation view


Explanation Screenshot
Create a new Script-based Calculation view:

Click on your content folder > your assigned


session number, your assigned student number
package > Right-click > NEW > Calculation View

Name:
SALESORDER_RANKING_AND_DISCOUNT_SQ
L_CV

Rather than creating an entirely new view instead


use Browse .. and make a copy of an existing view.

Click > Copy From: and select the SAMPLE_CV


calculation view located in the solution exersice6
folder

Start by selecting the Script View node.

First change the name of the variable var_out to


var_rank
65

Explanation Screenshot

Second, un-comment the line that calls the


decision table procedure. Make sure to adjust the
package name to point to your decision table
created in the first step.

CALL "_SYS_BIC"."rdp361.session0.0/
Remember to supply your session and student
CUSTOMER_DISCOUNT_CALCULATION_DT" (:var_rank,
number.
var_out);

Add an additional column to the Output.


66

Explanation Screenshot

Name: DISCOUNT
Data Type: DECIMAL
Length: 12
Scale: 2

Hint. The DISCOUNT is the customer discount


result column returned by the decision table.

Proceed. Click on the Semantics node.

Define the DISCOUNT column as an Attribute.

Save and Activate your work.


67

Exercise 6.4 Execute & Test


Explanation Screenshot
SELECT
Execute the following SQL code "COMPANY_NAME","REGION","SALES","ORDERS",
within the SQL Editor. "SALES_RANK","ORDER_RANK","DISCOUNT"
FROM "_SYS_BIC"."rdp361.session0.0/
Add your assigned session and SALESORDER_RANKING_AND_DISCOUNT_SQL_CV"
student number. WITH PARAMETERS (
'PLACEHOLDER' = ('$$IP_FR_DTE$$', '20130101'),
Supply the input parameters 'PLACEHOLDER' = ('$$IP_TO_DTE$$', '20130112'),
accordingly. 'PLACEHOLDER' = ('$$IP_REGION$$', 'AMEA')
);

Results are shown based on the


region and date.
68

Exercise 6.5 Create a Graphical Calculation View


In this step you will compare discounts based on region and review the execution path using the Visualize
plan.

Explanation Screenshot

Create a new Calculation View

Name:
CUSTOMER_DISCOUNT_BY_RAN
KING_AND_REGION_CV

Check – Enable Multi-Dimensional


Reporting.

Add 4 Projection nodes (one for


each region) to the work area.

Rename the first 2 projections to


AMEA and
AMER

Rename the third and fourth


projections to
APJ and
AFR
69

Explanation Screenshot

Associate each projection node with


the previously created SQL script
based Calculation view.

Start with the AMEA projection node


first.

Select
SALESORDER_RANKING_AND_DI
SCOUNT_SQL_CV within your own
work package folder and drag and
drop that unto the AMEA projection
node.

Repeat the same steps for the


remaining 3 regional projection
nodes.

Proceed. Click on the projection


node AMEA.

Add the following columns to the


Output area.

COMPANY_NAME
REGION
SALES
DISCOUNT
70

Explanation Screenshot

Rename the SALES column.

In the Output area select the SALES


column, within the Properties area
rename the column name & label to
SALES_AMEA

Repeat the steps for the additional 3


regional projection nodes.

Add the same columns of each


projection node to the Output Node.
COMPANY_NAME
REGION
SALES
DISCOUNT

Then proceed to RE-NAME each


SALES column within each Regional
Projection accordingly.
(SALES_AMER, SALES_APJ &
SALES_AFR)

Add a Union node above the


projection nodes and add connection
lines.

Select the Union Node


71

Explanation Screenshot

Map the columns in the Union.

Click the ‘Auto map by name’ icon to


automatically map all the columns.

In the Target Parameters area create


a new Target by clicking on the
Green plus sign.

Enter the name:


REGION_CONSTANT

Data Type: VARCHAR


Length: 4
72

Explanation Screenshot

Select the column > right click >


Manage Mappings

Define the following Constant Values


according to the Source Model.

AFR
AMEA
AMER
APJ

Proceed. Drag a connection line


between the Union node and the
Aggregation node.

Add all the columns to the Output


area. Remember to add all the
Measures as Aggregated Column’s.
73

Explanation Screenshot

Proceed. Click on the Semantics


area.

Define Attributes for


COMPANY_NAME
REGION
REGION_CONSTANT
DISCOUNT

and measure for


SALES_AMEA
SALES_AMER
SALES_APJ
SALES_AFR

In the Variables/Input Parameters


area click on the ‘Input Parameter
Mappings’ Icon ..

Click on Auto-Map by Name to


automatically perform the mappings.
74

Explanation Screenshot

Remove the mapping from


IP_REGION

Instead define a target for each


region.

Drag the IP_REGION from the


AMEA Input Source into the Target
Area.

Repeat the same steps for the


additional 3 regions.
75

Explanation Screenshot

The Input parameters should look as


follows.

Proceed to edit and rename each


Input parameter by clicking on the
Edit Icon.

Start by selecting the IP_REGION


input parameter.

Rename it to IP_AMEA

Define a Constant Value: AMEA


76

Explanation Screenshot

Repeat the steps for the


IP_REGION_1 Input parameter.

Rename it to IP_AMER

Define a Constant (AMER)

Repeat the same steps for the last 2


Input Parameters

IP_APJ
IP_AFR

Note: Remember to set the constant


for each Input parameter accordingly
(APJ or AFR)

Save and Activate your work.


77

Exercise 6.6 Execute & Test


Explanation Screenshot
SELECT "DISCOUNT",
SUM("SALES_AMEA") AS "SALES_AMEA",
SUM("SALES_AMER") AS "SALES_AMER",
Execute the following SQL statement SUM("SALES_APJ") AS "SALES_APJ",
in the SQL Editor. SUM("SALES_AFR") AS "SALES_AFR"
FROM "_SYS_BIC"."rdp361.session0.0/
Add your assigned session and CUSTOMER_DISCOUNT_BY_RANKING_AND_REGION_CV"
student number. GROUP BY "DISCOUNT"
WITH PARAMETERS (
'PLACEHOLDER' = ('$$IP_FR_DTE$$', '20100101'),
'PLACEHOLDER' = ('$$IP_TO_DTE$$', '20130112')
);

Results are shown comparing


discount values per region.

Execute the SQL statement again –


however – turn on the Visualize
Plan.

Select the entire SQL statement >


right click > Visualize Plan

Right-Click and select Execute on


the first screen..
78

Explanation Screenshot

Drill down into the Column Search ..

Further drill down into the


Calculation Search…

Review the record count of each


input source – confirming that the
filters are pushed down.

SELECT "COMPANY_NAME", "DISCOUNT",


SUM("SALES_APJ") AS "SALES_APJ"
FROM "_SYS_BIC"."rdp361.session0.0/
CUSTOMER_DISCOUNT_BY_RANKING_AND_REGION_CV"
Change the SQL syntax a bit – this
WHERE REGION='APJ'
time we are only interested in sales
GROUP BY "COMPANY_NAME", "DISCOUNT"
for one region (APJ)
WITH PARAMETERS (
'PLACEHOLDER' = ('$$IP_FR_DTE$$', '20100101'),
'PLACEHOLDER' = ('$$IP_TO_DTE$$', '20130112')
);
79

Explanation Screenshot

The results are as follows for the


APJ region.

However, looking at the Visualize


plan you can see that the other
regions calculations were also
calculated even though they were
not requested.

SELECT "COMPANY_NAME", "DISCOUNT",


SUM("SALES_APJ") AS "SALES_APJ"
FROM "_SYS_BIC"."rdp361.session0.0/
Change the query by filtering on the CUSTOMER_DISCOUNT_BY_RANKING_AND_REGION_CV"
REGION_CONSTANT instead of the WHERE REGION_CONSTANT = 'APJ'
REGION dimension. GROUP BY "COMPANY_NAME", "DISCOUNT" WITH PARAMETERS (
'PLACEHOLDER' = ('$$IP_FR_DTE$$', '20100101'),
'PLACEHOLDER' = ('$$IP_TO_DTE$$', '20130112')
);

The results are as the same as


before for the APJ region.
80

Explanation Screenshot

However, looking at the Visualize


plan you can see a more optimal
execution plan since the other input
sources (AMEA, AMER, and AFR)
were pruned and not calculated.

Notice 6 rows are returned for APJ.

SELECT
"COMPANY_NAME","REGION","SALES","ORDERS",
"SALES_RANK","ORDER_RANK","DISCOUNT"
To confirm that the 6 row count is FROM "_SYS_BIC"."rdp361.session0.0/
correct execute the following SQL SALESORDER_RANKING_AND_DISCOUNT_SQL_CV"
statement against the scripted WITH PARAMETERS (
calculation view. 'PLACEHOLDER' = ('$$IP_FR_DTE$$', '20100101'),
'PLACEHOLDER' = ('$$IP_TO_DTE$$', '20130112'),
'PLACEHOLDER' = ('$$IP_REGION$$', 'APJ')
);

The results are shown confirming


that the filters are push down and
only the selected input sources are
executed.
81

EXERCISE 7 – SAP LUMIRA [10 MINUTES]


In this exercise use SAP Lumira to display customer sales versus orders using the Calculation view created
in exercise 5.1

Explanation Screenshot
To expose models to Multi-
Dimensional reporting tools ensure
that the model is flagged as ‘Multi-
Dimensional’

Open and modify


SALESORDER_RANKING_CV

Click on the Semantics area > click


on the Multi-Dimensional checkbox.

In addition to expose models as


Multi-Dimensional reports ensure
that the model contains at least 1
measure and 1 dimension.

Change both sales and orders types


to measures.

Save and Activate your work.

Open SAP Lumira

Create a New Document..


82

Explanation Screenshot

Select SAP HANA Online ..

System: coe-he-084.wdf.sap.corp

Instance: 20

User Name: Your assigned User ID

Search and select


SALESORDER_RANKING_CV
located in your work package folder

Click Preview and Select Data

Click Select
83

Explanation Screenshot

Select both ORDERS and SALES as


measures.

Select only COMPANY_NAME as an


Attribute

Define ORDERS as the Y Axis 2


And SALES as Y Axis 1

Define COMPANY_NAME as the X


Axis.

Select the Line Chart With 2 Y-Axes


visualization.
84

Explanation Screenshot

Finish!
85

© 2013 by SAP AG. All rights reserved.


SAP and the SAP logo are registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo are
trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company. Sybase and the Sybase logo are registered
trademarks of Sybase Inc. Sybase is an SAP company. Crossgate is a registered trademark of Crossgate AG in Germany and other countries. Crossgate is
an SAP company.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy