Vous êtes sur la page 1sur 19

SAP HANA Calculation View (Creation Using

GUI)
HANA 7,230 Views

Hello Everyone,
In this article, lets look at Calculation View, which is one more modeling object in SAP HANA
and the step by step process to create the same.

What is Calculation View?


A calculation view is a powerful and flexible information view, which can be used to define
more advanced logic or complex calculations on the tables or information views available in
the SAP HANA. Calculation Views provides the functionality that is available both in Attribute
and Analytic View.
Mostly calculation views are used when we were not able to design the business logic with
the help of attribute and analytic views. For example, we need measures from more than
one fact table or need to define filters on calculated columns.
The data foundation/source of the calculation view can include any combination of tables,
column views, attribute views and analytic views.
Calculation Views can be created in two ways, they are
Graphical
SQL Script
Graphical: The graphical calculation view is built with the help of nodes available in it. We
have 5 different nodes available in graphical calculation view, they are
1. Aggregation
2. Projection
3. Join
4. Union All
5. Rank
SQL Script: When it comes to SQL script based calculation view, we can write the business
logic using native SQL in the way we want. This can be created with the help of CE functions
or SQL script.
This type of calculation view can be based on two ways,
1. CE Functions
2. SQL Script
Features of Calculation View:
1. We can create both multi dimension and relational type calculation views.
2. Supports complex expressions (i.e. IF, Case, Counter, filters, union, RANK).
3. Supports reusing Analytic views, Attribute views and other Calculation views
(Graphical and Scripted).
4. Supports SAP ERP specific features (i.e. client handling, language, currency
conversion).
5. Provides ability to combine facts from multiple tables.
6. Provides support for additional data processing operations, (i.e. Union, explicit
aggregation).
7. Provides ability to leverage specialized languages (i.e. R-Lang).
8. Provides ability to leverage both Column and Row tables.
9. Performance of certain operations (i.e. star-join, aggregation) are inferior to
Analytical Views.
Scenario:
Before we go ahead and see the step by steps process of creating a Calculation View
in HANA, lets look at what we want to build.
As we discussed in Introduction to modeling in SAP HANA article, the below diagram
needs building of two Analytic Views for Sales and Payments and then a calculation view
to combine both sales and payments data.
We have already created both the analytic views required to create a calculation
view. Please go through SAP HANA Analytic View Creation for details on how to create
analytic view in SAP HANA.
Now business want analyze their sales revenue with their finance data to know more
insight on which customer has paid how much amount, what is the remaining debt and so
on.
To be able to analyze both sales and finance data at the same time, we have to
create a calculation views because this involves measures from more than one place.
Pre-requisite: AN_ORDERS_SALES and AN_PAYMENTS
How to create a Calculation View in SAP HANA?
Lets go through the step by step process of creating a calculation view in SAP HANA.
Step1:
All the modeling objects are grouped into packages in HANA. This first step in
modeling objects creation in HANA is to make sure we have package created (in our case
sap-student).
To create new calculation view, right click on the package(sap-student) New
Calculation View as shown below.

Step2:
This gives us the initial screen of the creation process where we need to enter
technical name of the calculation view and description/label.
We can also choose few options here like Copy From and Subtype. For details
about Copy From and Subtype options, please go through article SAP HANA How to
create Attribute View.
Our object name here is CA_SALES_PAYMENTS where CA represents CAlculation
View.
The other options we have here along with Copy From and Subtype are,
Type: We can create two types of calculation views as we discussed above. In this
article we are going to create a graphical calculation view.
Data Category: We have two options here, they are
1. CUBE: We select this option when we have measures coming out from this view
(This is same as OLAP model like analytic view)
2. DIMENSION: We select this option when we dont need any measures from the view
(this is similar to OLAP structure or relational table).
We have selected CUBE for our scenario as we have measures.
With Star Join: If we would like to build a calculation like how we see in analytic
view with star join, then we need to select this option.
Note: In start join, we cannot use either attribute view or analytic view as source. We can
only use either table or calculation views as source.
Click Finish to proceed further.
Step3:
This step will show us the design area for Calculation View where we build the
complete object and activate it once the designing is completed.
We have two main areas here, they are
Palette: This area contains all the nodes that can be used as source to build our
calculation views.
We have 5 different types of nodes, they are
1. Join: This node is used to join two source objects and project the result to the next
node. The join types can be inner, left outer, right outer and text join.
Note: We can only have two source objects mapped to a join node.
2. Union: This is used to perform union all operation between multiple sources. The
source can be n number of objects.
3. Projection: This is used to fine tune our source objects before we use in next nodes
like union, aggregation and rank.
We can choose the selective columns, filter the data and create additional columns.
4. Aggregation: This is used to perform aggregation on specific columns based the
selected attributes.
5. Rank: This is the exact replacement for RANK function in SQL. We can define the
partition and order by clause based on the requirement.
Semantics: We can define and maintain the object settings here and can also make
use of advanced features like variables, hierarchies and input parameters.
As we have selected data category as CUBE, we can see the default node as
Aggregation. If the data category was DIMENSION then we will have default node
asProjection. We cannot remove the default node, however we can change from one to
another.

Proceed to the next page to continue reading

Step4:
In our scenario, we are going to use union node to combine both the analytic views
that we have built. Before we use the union node, we need to select the required columns
from analytic views. This can be easily done with the help of projection node.
Lets add two projections into our design area and add the object by selecting Add
Objects option as shown below. We can also do this by drag and drop.

Step5:
After selecting Add Objects, we can search for our objects, select the appropriate
one and click ok to add that object to the projection.
Once it is added, we need to select the required columns to the output. In our case
we need the customer, time and measures information for the output. All the required
objects has been selected to the output.
Step6:
In the same way, lets add the AN_PAYMENTS analytic view to the other projection
and select the required columns to the output as shown below.
Note: One of the biggest advantage we have in calculation views is Filter Expression. Using
this filter expression we apply the filters on calculated columns (which are not part of actual
tables) and we can also use different operators like and, or, not and so on. Please look at
the below image for details.
Step7:
Once we have the required columns selected from both the projections (source is
analytic view), the next step is to go ahead and combine them with the help of a union
node.
Lets add the union node into the design and join both the sources to union by
dragging the arrow onto the union node as shown below.
Proceed to the next page to continue reading

Step8:
After we add both the sources (projections) to Union node, we need to select the
columns from both the sources that we need for output/target by using one of the two
options available.
1. Add to Target: This option will directly add a new column to the output with the
same name.
2. Map to Target: This option is required when we have same column coming from
both the sources (mostly attributes). In this case when we add the columns for the first
time, we will select Add to target and for the columns coming from second source we
need to select Map to Target which gives us the below screen to select the target for
which we want to map as shown below.

Step9:
The next step is to perform manage mappings. When we use union operation in
SQL, the first thing comes to our mind is: number of columns from the sources should be
same otherwise it is going to throw an error.
Here in HANA, when we add any column from just one source, SAP HANA considers
null as default value from other source.
We can change this default value with the help of manage mappings. One reason to
change this is, for attributes null value works but for measures where we need
aggregation having null might give us wrong result. It is a good practice to maintain 0
(zero) as default value for measures.
To perform this, right click on any target column and select manage mappings. In the
next screen we can see the null is selected by default. If we would like to have some
other value than Null, then uncheck the box and enter the value in Constant Value
column as shown the below images.

Step10:
After completing the designing of union node, we need to map the output of union to
default aggregation node in the calculation view and then select the columns we need for
the final output.
If we need the columns as attribute (dimension), then we have to select the option
Add to Output. If we need any aggregation on columns (measures), then we have to
select the option Add As Aggregated Column as shown below.
Step11:
The final thing we need to do before we go ahead and activate this object is,
maintain the proper settings and additional options in semantics section.
Semantics section contains four areas, they are
1. Columns: This sections contains the columns (attributes and measures) that have been
picked for the final output and we can maintain the below properties for these columns
Choose the columns type as either Attribute or measure.
Maintain the Label/Description for the columns
Hide/Unhide the columns
Assigning variables to the columns.
2. View Properties: This tab contains properties of the calculation view like data category,
type, default client, default schema and so on. The below image shows all the properties
available.

Proceed to the next page to continue reading

3. Hierarchies: In this section, we can create the hierarchies based on the business
requirement. We can create two types of hierarchies in SAP HANA, they are
Level Hierarchy
Parent-Child Hierarchy
Please go through the article Hierarchy creation in SAP HANA for more details.

4. Parameters/Variable: This sections shows use the list of variables and input
parameters created in this Calculation View. We can also create a new variable/input
parameter from this screen.

Step12:
Once the object is designed and settings are maintained in semantics, the next step
is to activate it and make sure it is activated successfully. We can save and activate the
object using green arrow mark shown below.
Job Log:

Step13:
Upon successful activation we can confirm that the object is working by looking at
the data preview and performing initial data validation.

Data Preview of any Modeling object in SAP HANA has three tabs like Analysis,
Distinct Values and Raw Data using which we can quickly do basic data validations.
Below screen shots shows us the few data representations with the help of data
preview.
Raw Data:
Analysis:
Thus we have successfully created Graphical Calculation View in SAP HANA. In the coming
articles, we will see how to create a calculation view using SQL Script and calculation view
using CE Functions.
Thank you for reading and hope this information is helpful. Please do share with your friends
if you feel the information is useful.
Happy Learning.

Vous aimerez peut-être aussi