0207 - Modeling - Exercise - How To Create A Level and Parent Child Hierarchy.pdf

61
SAP How-to Guide Business Analytics SAP HANA™ Appliance Applicable Releases: SAP HANA 1.0 SP04 Version 3.0 May 2012 How to Define a Level Hierarchy and a Parent-Child Hierarchy in HANA

description

sss

Transcript of 0207 - Modeling - Exercise - How To Create A Level and Parent Child Hierarchy.pdf

SAP How-to Guide

Business Analytics

SAP HANA™ Appliance

Applicable Releases:

SAP HANA 1.0 SP04

Version 3.0

May 2012

How to Define a Level Hierarchy and a Parent-Child Hierarchy in HANA

© Copyright 2012 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form

or for any purpose without the express permission of SAP AG. The

information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors

contain proprietary software components of other software vendors.

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered

trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, System i, System i5, System p,

System p5, System x, System z, System z10, System z9, z10, z9, iSeries,

pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390,

OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power

Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER,

OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS,

HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex,

MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and

Informix are trademarks or registered trademarks of IBM Corporation.

Linux is the registered trademark of Linus Torvalds in the U.S. and other

countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either

trademarks or registered trademarks of Adobe Systems Incorporated in

the United States and/or other countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open

Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame,

and MultiWin are trademarks or registered trademarks of Citrix Systems,

Inc.

HTML, XML, XHTML and W3C are trademarks or registered trademarks

of W3C®, World Wide Web Consortium, Massachusetts Institute of

Technology.

Java is a registered trademark of Sun Microsystems, Inc.

JavaScript is a registered trademark of Sun Microsystems, Inc., used

under license for technology invented and implemented by Netscape.

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP

BusinessObjects Explorer, StreamWork, and other SAP products and

services mentioned herein as well as their respective logos are

trademarks or registered trademarks of SAP AG in Germany and other

countries.

Business Objects and the Business Objects logo, BusinessObjects,

Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other

Business Objects products and services mentioned herein as well as their

respective logos are trademarks or registered trademarks of Business

Objects Software Ltd. Business Objects is an SAP company.

Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere,

and other Sybase products and services mentioned herein as well as their

respective logos are trademarks or registered trademarks of Sybase, Inc.

Sybase is an SAP company.

All other product and service names mentioned are the trademarks of

their respective companies. Data contained in this document serves

informational purposes only. National product specifications may vary.

The information in this document is proprietary to SAP. No part of this

document may be reproduced, copied, or transmitted in any form or for

any purpose without the express prior written permission of SAP AG.

This document is a preliminary version and not subject to your license

agreement or any other agreement with SAP. This document contains

only intended strategies, developments, and functionalities of the SAP®

product and is not intended to be binding upon SAP to any particular

course of business, product strategy, and/or development. Please note

that this document is subject to change and may be changed by SAP at

any time without notice.

SAP assumes no responsibility for errors or omissions in this document.

SAP does not warrant the accuracy or completeness of the information,

text, graphics, links, or other items contained within this material. This

document is provided without a warranty of any kind, either express or

implied, including but not limited to the implied warranties of

merchantability, fitness for a particular purpose, or non-infringement.

SAP shall have no liability for damages of any kind including without

limitation direct, special, indirect, or consequential damages that may

result from the use of these materials. This limitation shall not apply in

cases of intent or gross negligence.

The statutory liability for personal injury and defective products is not

affected. SAP has no control over the information that you may access

through the use of hot links contained in these materials and does not

endorse your use of third-party Web pages nor provide any warranty

whatsoever relating to third-party Web pages.

SAP “How-to” Guides are intended to simplify the product implement-

tation. While specific product features and procedures typically are

explained in a practical business context, it is not implied that those

features and procedures are the only approach in solving a specific

business problem using SAP NetWeaver. Should you wish to receive

additional information, clarification or support, please refer to SAP

Consulting.

Any software coding and/or code lines / strings (“Code”) included in this

documentation are only examples and are not intended to be used in a

productive system environment. The Code is only intended better explain

and visualize the syntax and phrasing rules of certain coding. SAP does

not warrant the correctness and completeness of the Code given herein,

and SAP shall not be liable for errors or damages caused by the usage of

the Code, except if such damages were caused by SAP intentionally or

grossly negligent.

Disclaimer

Some components of this product are based on Java™. Any code change

in these components may cause unpredictable and severe malfunctions

and is therefore expressively prohibited, as is any decompilation of these

components.

Any Java™ Source Code delivered with this product is only to be used by

SAP’s Support Services and may not be modified or altered in any way.

Document History

Document Version Description

1.0 First official release of this guide

1.10 Included how to define Parent-Child Hierarchy

2.0 Improvements

3.0 Adjustments for SP 4

Typographic Conventions

Type Style Description

Example Text Words or characters quoted

from the screen. These

include field names, screen

titles, pushbuttons labels,

menu names, menu paths,

and menu options.

Cross-references to other

documentation

Example text Emphasized words or

phrases in body text, graphic

titles, and table titles

Example text File and directory names and

their paths, messages,

names of variables and

parameters, source text, and

names of installation,

upgrade and database tools.

Example text User entry texts. These are

words or characters that you

enter in the system exactly

as they appear in the

documentation.

<Example

text>

Variable user entry. Angle

brackets indicate that you

replace these words and

characters with appropriate

entries to make entries in the

system.

EXAMPLE TEXT Keys on the keyboard, for

example, F2 or ENTER.

Icons

Icon Description

Caution

Note or Important

Example

Recommendation or Tip

Table of Contents

1. Business Scenario .................................................................................................................1

2. Prerequisites ......................................................................................................................... 2

3. How to Define a Level Hierarchy .......................................................................................... 3

3.1 Background Information ................................................................................................. 3

3.2 Step-by-Step Procedure.................................................................................................. 4

3.2.1 Create database objects .................................................................................... 4

3.2.2 Create a package to store new modeler content ............................................. 8

3.2.3 Create an attribute view defining the hierarchy............................................... 9

3.2.4 Create an analytic view to join transactional data ..........................................12

3.2.5 Create a calculation view using hierarchy for enhancing the data ...............15

3.2.6 Consume the hierarchy and sales data from the Analytic View using Excel

2007 ................................................................................................................... 18

3.2.7 Consume the hierarchy and sales data from the Calculation View using

Excel 2007 ......................................................................................................... 24

4. How to Define a Parent-Child Hierarchy ............................................................................ 29

4.1 Background Information ............................................................................................... 29

4.2 Step-by-Step Procedure.................................................................................................31

4.2.1 Create database objects ...................................................................................31

4.2.2 Create a package to store new modeler content ........................................... 34

4.2.3 Create an attribute view defining the hierarchy............................................. 35

4.2.4 Create an analytic view to join transactional data ......................................... 38

4.2.5 Create a calculation view using hierarchy for enhancing the data .............. 41

4.2.6 Consume the hierarchy and sales data via Excel 2010 ................................. 45

4.2.7 Consume the parent child hierarchy and sales data from Calculation View

via Excel 2007 ....................................................................................................51

5. Appendix ............................................................................................................................. 55

May 2012 1

1. Business Scenario

Organizations define hierarchies for information classification, allowing roll-up and drill-down

analysis. For example, a sales organization might allocate a sales person to a country and a country

to a region. Sales data can then be aggregated and analyzed by region, country, or sales person.

Common hierarchies are:

Cost center

Profit center

Asset

Product

Organization

Geographic region

Time (for example, year, quarter, month, week, or day)

Analysis of high-volume transactional data that is easily navigated as a hierarchy is possible with SAP HANA.

May 2012 2

2. Prerequisites

To build the examples presented in this how-to guide the reader will require the following software.

Knowledge of using the software is expected.

Server

HANA 1.0 SP04 (release 28 was used to build the examples)

Client

HANA 1.0 SP04 (release 28) 32bit* client

HANA 1.0 SP04 (release 28) Studio

Microsoft Excel 2007 or Excel 2010*

* Excel 2010 is available as 32 or 64 bit, if the 64 bit version is being used the 64 bit HANA client

must be installed.

May 2012 3

3. How to Define a Level Hierarchy

3.1 Background Information

Hierarchy data is easily modeled in a relational database. The following entity model shows a

regional/sales hierarchy.

To use a HANA level hierarchy with this interpretation, the physical implementation of this model

can be simply replicated into HANA without modification. The definition of the HANA hierarchy is

done using an attribute view.

To allow high-performance analysis of high-volume sales data by sales person, country or region,

the sales data is joined to the hierarchy definition in an analytic view.

Section 3.2 details a step-by-step procedure to build this example.

analytic view

transactional data attribute view

hierarchy region

country

sales

person

n

n sales n

region

country

sales person

n n

May 2012 4

3.2 Step-by-Step Procedure

It is assumed that a HANA database user is already created and a HANA system already configured

in the studio.

3.2.1 Create database objects

In the HANA studio, with the modeller perpective open, open a new SQL Editor window.

The following script will create a new schema and sample tables, and populate them with some

sample data. Either copy and paste the script, or use the script attached in the Appendix. Execute

the script to create all the sample database content.

/* create database objects */

create schema hier_demo_01;

grant select on schema hier_demo_01 to "_SYS_REPO" with grant option;

create column table hier_demo_01.region(

region_id int,

region_name varchar(30),

May 2012 5

primary key (region_id)

);

comment on column hier_demo_01.region.region_name is 'Sales Region';

create column table hier_demo_01.country(

country_id int,

country_name varchar(30),

region int,

primary key (country_id)

);

comment on column hier_demo_01.country.country_name is 'Sales Country';

comment on column hier_demo_01.country.region is 'foreign key to region';

create column table hier_demo_01.sales_person(

sales_person_id int,

sales_person_name varchar(30),

country int,

primary key (sales_person_id)

);

comment on column hier_demo_01.sales_person.sales_person_name is 'Sales

Person';

comment on column hier_demo_01.sales_person.country is 'foreign key to

country';

create column table hier_demo_01.sales(

sales_id int,

sales_person int,

sales_date date,

sales_amount int,

primary key (sales_id)

);

comment on column hier_demo_01.sales.sales_amount is 'Sales Amount';

comment on column hier_demo_01.sales.sales_person is 'foreign key to

sales_person';

/* insert test data */

insert into hier_demo_01.region values(1, 'Americas');

insert into hier_demo_01.region values(2, 'Europe');

insert into hier_demo_01.region values(3, 'Africa/Middle East');

insert into hier_demo_01.region values(4, 'Asia Pacific');

insert into hier_demo_01.country values(1, 'Andean & Caribbean ', 1);

insert into hier_demo_01.country values(2, 'Argentina ', 1);

insert into hier_demo_01.country values(3, 'Bolivia ', 1);

insert into hier_demo_01.country values(4, 'Brazil ', 1);

insert into hier_demo_01.country values(5, 'Canada ', 1);

insert into hier_demo_01.country values(6, 'Caribe ', 1);

insert into hier_demo_01.country values(7, 'Chile ', 1);

insert into hier_demo_01.country values(8, 'Colombia ', 1);

insert into hier_demo_01.country values(9, 'Mexico ', 1);

insert into hier_demo_01.country values(10, 'Paraguay ', 1);

insert into hier_demo_01.country values(11, 'Peru ', 1);

insert into hier_demo_01.country values(12, 'Uruguay ', 1);

insert into hier_demo_01.country values(13, 'USA ', 1);

May 2012 6

insert into hier_demo_01.country values(14, 'Venezuela ', 1);

insert into hier_demo_01.country values(15, 'Austria ', 2);

insert into hier_demo_01.country values(16, 'Baltics ', 2);

insert into hier_demo_01.country values(17, 'Belgium ', 2);

insert into hier_demo_01.country values(18, 'Bulgaria ', 2);

insert into hier_demo_01.country values(19, 'Croatia ', 2);

insert into hier_demo_01.country values(20, 'Cyprus ', 2);

insert into hier_demo_01.country values(21, 'Czech Republic ', 2);

insert into hier_demo_01.country values(22, 'Denmark ', 2);

insert into hier_demo_01.country values(23, 'Estonia ', 2);

insert into hier_demo_01.country values(24, 'Finland ', 2);

insert into hier_demo_01.country values(25, 'France', 2);

insert into hier_demo_01.country values(26, 'Germany ', 2);

insert into hier_demo_01.country values(27, 'Greece ', 2);

insert into hier_demo_01.country values(28, 'Hungary ', 2);

insert into hier_demo_01.country values(29, 'Italy ', 2);

insert into hier_demo_01.country values(30, 'Kazakhstan ', 2);

insert into hier_demo_01.country values(31, 'Latvia ', 2);

insert into hier_demo_01.country values(32, 'Lithuania ', 2);

insert into hier_demo_01.country values(33, 'Luxembourg ', 2);

insert into hier_demo_01.country values(34, 'Netherlands ', 2);

insert into hier_demo_01.country values(35, 'Norway ', 2);

insert into hier_demo_01.country values(36, 'Poland', 2);

insert into hier_demo_01.country values(37, 'Portugal ', 2);

insert into hier_demo_01.country values(38, 'Romania ', 2);

insert into hier_demo_01.country values(39, 'Russia', 2);

insert into hier_demo_01.country values(40, 'Serbia ', 2);

insert into hier_demo_01.country values(41, 'Slovakia ', 2);

insert into hier_demo_01.country values(42, 'Slovenia ', 2);

insert into hier_demo_01.country values(43, 'Spain ', 2);

insert into hier_demo_01.country values(44, 'Sweden ', 2);

insert into hier_demo_01.country values(45, 'Switzerland ', 2);

insert into hier_demo_01.country values(46, 'Turkey ', 2);

insert into hier_demo_01.country values(47, 'Ukraine ', 2);

insert into hier_demo_01.country values(48, 'United Kingdom & Ireland ',

2);

insert into hier_demo_01.country values(49, 'West Balkans ', 2);

insert into hier_demo_01.country values(50, 'Africa ', 3);

insert into hier_demo_01.country values(51, 'Algeria ', 3);

insert into hier_demo_01.country values(52, 'Egypt ', 3);

insert into hier_demo_01.country values(53, 'Israel ', 3);

insert into hier_demo_01.country values(54, 'Kenya', 3);

insert into hier_demo_01.country values(55, 'MENA ', 3);

insert into hier_demo_01.country values(56, 'Morocco ', 3);

insert into hier_demo_01.country values(57, 'Nigeria ', 3);

insert into hier_demo_01.country values(58, 'Saudi Arabia ', 3);

insert into hier_demo_01.country values(59, 'South Africa ', 3);

insert into hier_demo_01.country values(60, 'Tunisia ', 3);

insert into hier_demo_01.country values(61, 'United Arab Emirates ', 3);

insert into hier_demo_01.country values(62, 'Australia ', 4);

insert into hier_demo_01.country values(63, 'China ', 4);

insert into hier_demo_01.country values(64, 'Hong Kong', 4);

insert into hier_demo_01.country values(65, 'India ', 4);

insert into hier_demo_01.country values(66, 'Indonesia ', 4);

insert into hier_demo_01.country values(67, 'Japan ', 4);

insert into hier_demo_01.country values(68, 'Korea ', 4);

insert into hier_demo_01.country values(69, 'Malaysia ', 4);

insert into hier_demo_01.country values(70, 'New Zealand ', 4);

insert into hier_demo_01.country values(71, 'Pakistan ', 4);

May 2012 7

insert into hier_demo_01.country values(72, 'Philippines ', 4);

insert into hier_demo_01.country values(73, 'Singapore ', 4);

insert into hier_demo_01.country values(74, 'Taiwan ', 4);

insert into hier_demo_01.country values(75, 'Thailand ', 4);

insert into hier_demo_01.country values(76, 'Vietnam ', 4);

/* create 2 sales people for each country */

insert into hier_demo_01.sales_person (

select country_id, 'Sales Person 1-' || country_id, country_id from

hier_demo_01.country

union

select 100 + country_id, 'Sales Person 2-' || country_id, country_id

from hier_demo_01.country

);

/* create 3 sales records for each sales_person

in a real-world example this table contains a large number of rows,

which are

aggreagted in an analytic view when data is queried */

insert into hier_demo_01.sales(

select sales_person_id, sales_person_id, '2011-01-01', sales_person_id

from hier_demo_01.sales_person

union

select 1000 + sales_person_id, sales_person_id, '2011-02-01',

sales_person_id * 2 from hier_demo_01.sales_person

union

select 2000 + sales_person_id, sales_person_id, '2011-03-01',

sales_person_id * 3 from hier_demo_01.sales_person

);

/* uncomment the following line to remove all the hier_demo_01 database

objects */

--drop schema hier_demo_01 cascade;

May 2012 8

3.2.2 Create a package to store new modeler content

Right-click the Content node in the navigator pane to create a new package.

Name the new package hier-demo01, or if it already exists specify a different name and use that in

the following steps.

May 2012 9

3.2.3 Create an attribute view defining the hierarchy

Right-click the new package and select New -> Attribute View…

Name the new view AT_SALES_HIER.

May 2012 10

Select the COUNTRY, REGION and SALES_PERSON tables from the HIER_DEMO_01 schema, then

choose Finish.

On the Data Foundation tab, add a 1 to many (1..n) join between REGION.REGION_ID and

COUNTRY.REGION, and COUNTRY.COUNTRY_ID and SALES_PERSON.COUNTRY. Joins can be added by dragging one column to another.

Next we need to add some of the table’s columns as attributes. This can be done by right-clicking on the column. Add SALES_PERSON.SALES_PERSON_ID as a key attribute, and

SALES_PERSON.SALES_PERSON_NAME, COUNTRY.COUNTRY_NAME and REGION.REGION_NAME as attributes. Note that the column descriptions have been propagated to the attribute definition, this is important as this is displayed in Excel. The output pane should look similar to the following screenshot:

May 2012 11

Right-click the Hierarchy folder.

Choose Create new level hierarchy. Drag and drop attributes from the output pane to define the levels of the hierarchy, REGION_NAME should be level 1, COUNTRY_NAME level 2, and SALES_PERSON_NAME level 3.

May 2012 12

The attribute view definition is now complete. Save and activate the view.

3.2.4 Create an analytic view to join transactional data

Right-click the new package and select New -> Analytic View…

Add the SALES table from the HIER_DEMO_01 schema.

May 2012 13

Add the attribute view AT_SALES_HIER from the hier-demo01 package, then choose Finish.

With the Data Foundation tab selected, right-click the SALES_AMOUNT column and select Add as

Measure. Add the SALES_PERSON_ID column as an Attribute.

May 2012 14

Switch to the Logical View and add a one to many join between

AT_SALES_HIER.SALES_PERSON_ID and the Data Foundation SALES_PERSON columns.

The definition is complete. Save and activate the view.

May 2012 15

3.2.5 Create a calculation view using hierarchy for enhancing the data

Right-click the new package and select New -> Calculation View…

Choose Next and on the subsequent screen select the analytic view AN_SALES from the hier-demo01 package. The following screen is displayed:

May 2012 16

Insert a projection, connect all processes as displayed in the picture below, and add all the fields on the Analytic View as Output for projection:

Right-click the calculated columns folder and choose New. Create a calculated column that shows 10% of the sales amount under the Average discount caption:

As a result, the following screen is displayed:

May 2012 17

On the output process, select all columns to output parameters either as attributes or measures accordingly:

Choose Create new level hierarchy. Drag and drop attributes from the output pane to define the levels of the hierarchy, REGION_NAME

should be level 1, COUNTRY_NAME level 2, and SALES_PERSON_NAME level 3.

The calculation view is created, Save and activate it.

May 2012 18

3.2.6 Consume the hierarchy and sales data from the Analytic View using Excel 2007

Open a new Workbook in Excel. Select Data -> From Other Sources -> From Data Connection

Wizard.

In the Data Connection Wizard, select Other/Advanced. Choose Next.

May 2012 19

In the Data Link Properties window, select the SAP HANA MDX Provider. Choose Next.

Enter the credentials for your HANA system. Click OK.

May 2012 20

Select the hier-demo01 database (HANA package) and the AN_SALES cube (HANA analytic view).

Choose Next.

May 2012 21

In the next window, it is possible to save your password so that you don’t need to enter it again.

Note the security message if you select this option. Choose Finish.

In the Import Data window choose OK.

May 2012 22

With the pivot table added to the workbook, select the Sales Amount and Sales hierarchy

checkboxes to display the sales data.

This will display the results of the MDX query in the pivot table. Note that the PivotTable Field List

shows the descriptions from the attributes defined in the HANA views.

Clicking on the + next to a node in the hierarchy will display subordinate nodes.

May 2012 23

May 2012 24

3.2.7 Consume the hierarchy and sales data from the Calculation View using Excel 2007

Open a new Workbook in Excel. Select Data -> From Other Sources -> From Data Connection

Wizard.

In the Data Connection Wizard, select Other/Advanced. Choose Next.

May 2012 25

In the Data Link Properties window, select the SAP HANA MDX Provider. Choose Next.

Enter the credentials for your HANA system. Choose OK.

Select the hier-demo database (HANA package) and the CV_SALES cube (HANA calculation

view). Choose Next.

May 2012 26

In the next window, it is possible to save your password so that you don’t need to enter it again.

Note the security message if you select this option. Choose Finish.

May 2012 27

In the Import Data window choose OK.

With the pivot table added to the workbook, select the Sales Amount and Sales hierarchy

checkboxes to display the sales data.

This will display the results of the MDX query in the pivot table. Note that the PivotTable Field List

shows the descriptions from the attributes defined in the HANA views.

Clicking on the + next to a node in the hierarchy will display subordinate nodes.

May 2012 28

May 2012 29

4. How to Define a Parent-Child Hierarchy

4.1 Background Information Refer to section 3.1 for an example of an entity model of a hierarchy.

Section 3.1.2 details a step-by-step procedure to build this example.

In our Hierarchy Tree situation, the tree looks like this:

Defining the Hierarchy Tree Within the REGHIR table we are defining the Hierarchy Tree with regard to the Parent-Child relationship. A data preview of this table shows the following:

May 2012 30

The REGHIR.MEMBER column defines the Child and the REGHIR.HIERPARENT column defines the Parent. To ensure that your Parent-Child relationship is defined correctly you will need to ensure that the Parent Values are defined once as members within the Member column.

May 2012 31

4.2 Step-by-Step Procedure

It is assumed that a HANA database user is already created and a HANA system already configured

in the studio.

4.2.1 Create database objects

In the HANA studio with the modeller perpective open, open a new SQL Editor window.

The following script will create a new schema and sample tables, and populate them with some

sample data. Either copy and paste the script, or use the script attached in the Appendix. Execute

the script to create all the sample database content.

May 2012 32

/* create database objects */

create schema hier_parentchild01;

grant select on schema hier_parentchild01 to "_SYS_REPO" with grant option;

/* Create Region Hierarchy Table */

create column table hier_parentchild01.REGHIR(

MEMBER varchar(20),

DESCRIPTION varchar(30),

HIERPARENT varchar(20),

primary key (MEMBER)

);

/* Create SALESFACT Table */

create column table hier_parentchild01.SALESFACT(

COUNTRY varchar(20),

SALES decimal(15,2),

COSTOFSALE decimal(15,2),

YEAR int,

primary key (COUNTRY)

);

/* insert test data into REGHIR(REGION Hierarchy Table) */

insert into hier_parentchild01.REGHIR values('FRANCE','Rep of France',

'EUROPE');

insert into hier_parentchild01.REGHIR values('GERMANY','Rep of Germany

','EUROPE');

insert into hier_parentchild01.REGHIR values('AUSTRIA','Rep of Austria',

'EUROPE');

insert into hier_parentchild01.REGHIR values('MEXICO','Rep of Mexico',

'AMERICA');

insert into hier_parentchild01.REGHIR values('USA','Rep of United

States','AMERICA');

insert into hier_parentchild01.REGHIR values('CANADA','Rep of Canada',

'AMERICA');

insert into hier_parentchild01.REGHIR values('CHINA','Rep of China',

'ASIA');

insert into hier_parentchild01.REGHIR values('VIETNAM','Rep of Vietnam',

'ASIA');

insert into hier_parentchild01.REGHIR values('JAPAN','Rep of Japan',

'ASIA');

insert into hier_parentchild01.REGHIR values('SA', 'Rep of South

Africa','AFRICA');

insert into hier_parentchild01.REGHIR values('CONGO', 'Rep of

Congo','AFRICA');

insert into hier_parentchild01.REGHIR values('NIGERIA','Rep of Nigeria',

'AFRICA');

insert into hier_parentchild01.REGHIR values('EUROPE','Europe','GLOBAL');

insert into hier_parentchild01.REGHIR values('AMERICA','America

','GLOBAL');

insert into hier_parentchild01.REGHIR values('ASIA','Asia','GLOBAL');

insert into hier_parentchild01.REGHIR values('AFRICA','Africa','GLOBAL');

insert into hier_parentchild01.REGHIR values('GLOBAL','Top of Tree',null);

May 2012 33

/* insert test data into SALES FactTABLE*/

insert into hier_parentchild01.SALESFACT

values('FRANCE',32000,21000,'2012');

insert into hier_parentchild01.SALESFACT

values('GERMANY',45000,19000,'2012');

insert into hier_parentchild01.SALESFACT

values('AUSTRIA',23600,15000,'2012');

insert into hier_parentchild01.SALESFACT

values('MEXICO',30000,25000,'2012');

insert into hier_parentchild01.SALESFACT values('USA', 21000,17000,'2012');

insert into hier_parentchild01.SALESFACT

values('CANADA',22000,18000,'2012');

insert into hier_parentchild01.SALESFACT

values('CHINA',24000,19000,'2012');

insert into hier_parentchild01.SALESFACT

values('VIETNAM',35000,25000,'2012');

insert into hier_parentchild01.SALESFACT

values('JAPAN',31000,20000,'2012');

insert into hier_parentchild01.SALESFACT values('SA',21000,18000,'2012');

insert into hier_parentchild01.SALESFACT

values('CONGO',20000,17000,'2012');

insert into hier_parentchild01.SALESFACT

values('NIGERIA',18000,15000,'2012');

insert into hier_parentchild01.SALESFACT Values('EUROPE',null,null,null);

insert into hier_parentchild01.SALESFACT Values('AMERICA',null,null,null);

insert into hier_parentchild01.SALESFACT Values('ASIA',null,null,null);

insert into hier_parentchild01.SALESFACT Values('AFRICA',null,null,null);

insert into hier_parentchild01.SALESFACT Values('GLOBAL',null,null,null);

/* uncomment the following line to remove all the hier_parentchild01

database objects */

--drop schema hier_parentchild01 cascade;

May 2012 34

4.2.2 Create a package to store new modeler content

Right-click the Content node in the navigator pane to create a new package.

Name the new package pchier-demo-01, or if it already exists specify a different name and use

that in the following steps.

May 2012 35

4.2.3 Create an attribute view defining the hierarchy

Right-click on the new package and select New -> Attribute View…

Name the new view AT_REGION_HIER.

May 2012 36

Select the REGHIR table from the HIER_PARENTCHILD01 schema, then choose Finish.

Next we need to add the table’s columns as attributes, this can be done by right-clicking the column. Add REGHIR.MEMBER as a key attribute, and REGHIR.DESCRIPTION and REGHIR.HIERPARENT as attributes. Note that the column descriptions have been propagated to the attribute definition, this is important as this is displayed in Excel. The output pane should look similar to the following screenshot.

Right-click the Hierarchy folder.

May 2012 37

. Choose New Parent Child Hierarchy.

Select the attributes from the drop down list to define the Parent and Child hierarchy.

The attribute view definition is now complete. Save and activate the view.

May 2012 38

4.2.4 Create an analytic view to join transactional data

Right-click the new package and select New -> Analytic View…

May 2012 39

Add the SALESFACT table from the HIER_PARENTCHILD01 schema.

Add the attribute view AT_REGION_HIER from the pchier-demo-01 package, then choose Finish.

With the Data Foundation tab selected, right-click the SALES column and select Add as Measure.

Repeat this for COSTOFSALE column. Add the COUNTRY and YEAR columns as attributes.

May 2012 40

Switch to the Logical View and add a one to many join between AT_REGION_HIER.MEMBER and the

Data Foundation COUNTRY columns.

The definition is complete. Save and activate the view.

May 2012 41

4.2.5 Create a calculation view using hierarchy for enhancing the data

Right-click the new package and select New -> Calculation View…

Choose Next and on the subsequent screen select the analytic view AN_SALES from the hier-demo01 package. The following screen is displayed;

May 2012 42

Insert a projection, connect all processes as displayed in the picture below and add all the fields on the Analytic View as Output for projection:

Right-click the calculated columns folder and choose New. Create a calculated column that shows 10% of the sales amount under the Average discount caption:

As a result, the following screen is displayed:

May 2012 43

On the output process, select all columns to output parameters either as attributes or measures accordingly:

Choose Create New Parent Child Hierarchy.

Define the hierarchy as described below:

May 2012 44

The calculation view is created. Save and activate it.

May 2012 45

4.2.6 Consume the hierarchy and sales data via Excel 2010

Open a new Workbook in Excel. Select Data -> From Other Sources -> From Data Connection

Wizard.

In the Data Connection Wizard, select Other/Advanced. Choose Next.

May 2012 46

In the Data Link Properties window, select the SAP HANA MDX Provider. Choose Next.

Enter the credentials for your HANA system. Choose OK.

May 2012 47

Select the pchier-demo-01 database (HANA package) and the AN_SALES cube (HANA analytic

view). Choose Next.

In the next window, it is possible to save your password so that you don’t need to enter it again.

Note the security message if you select this option. Choose Finish.

May 2012 48

In the Import Data window choose OK.

With the pivot table added to the workbook, select the Sales Amount and Sales hierarchy

checkboxes to display the sales data.

May 2012 49

This will display the results of the MDX query in the pivot table. Note that the PivotTable Field List

shows the descriptions from the attributes defined in the HANA views.

Clicking on the + next to a node in the hierarchy will display subordinate nodes.

May 2012 50

May 2012 51

4.2.7 Consume the parent child hierarchy and sales data from Calculation View via Excel 2007

Open a new Workbook in Excel. Select Data -> From Other Sources -> From Data Connection

Wizard.

In the Data Connection Wizard, select Other/Advanced. Choose Next.

May 2012 52

In the Data Link Properties window, select the SAP HANA MDX Provider. Choose Next.

Enter the credentials for your HANA system. Choose OK.

May 2012 53

Select the hier-demo-01 database (HANA package) and the CV_SALES cube (HANA calculation

view). Choose Next.

In the next window, it is possible to save your password so that you don’t need to enter it again.

Note the security message if you select this option. Choose Finish.

May 2012 54

In the Import Data window choose OK.

May 2012 55

5. Appendix

Appendix A – Level Hierarchy – Database object creation DDL and DML

Hierarchy_level_based.sql

Appendix B – Parent Child Hierarchy – Database object creation DDL and DML

Hierarchy_parent_child_based.sql

Appendix C – Further Testing – Parent Child Hierarchy

Parent Child Hierarchy further testing.docx

www.sap.com/contactsap

www.sdn.sap.com/irj/sdn/howtoguides