You are on page 1of 15


[ SAP HANA Tutorial ] mayato How-To Papers in the Area of Business Intelligence
Title: Author(s): Topic Published: Create some analytic privileges on a table Thorsten Fg SAP HANA December 2012

This tutorial describes how to create some simple analytic privileges on a table in SAP HANA. You limit the access to a table (which is in default client independent) for a user with the help of analytic privileges. Prerequisites o You have access to an SAP HANA system. o You have SAP HANA Studio installed on your machine. o You have SAP HANA Clients installed on your machine. Topics In this tutorial you will learn how to: 1. Create a table and insert some data 2. Create a user and assign a role and SQL privilege 3. Create an analytic privilege 4. Assign the analytic privilege to the user you created in the previous step 5. Delete a user The estimated completion time for this tutorial is 40 minutes. Using a simple data model, you will learn the basic steps about how to model data in the SAP in-memory computing studio.

Create a new tables in SAP HANA

1. In SAP HANA Studio go to your schema. There you will find a folder named tables. Here you can add a new table using a right click. In the screen below the schema TUTORIALS is selected.

2. Choose a name for the table (in this exercise, the name is FINANCIALS) and create the following fields: Fieldname ID MANDANT COUNTRY DATE REVENUE COTS ERNINGS CURRENCY Settings mark the field as key Dim 3 Dim 20 Dim 6, not Null Dim 6, not Null Dim 6, Not Null Dim 3 Data type INT CHAR VARCHAR DATE DECIMAL DECIMAL DECIMAL CHAR

SQL code: Table FINANCIALS create column table "<YOUR SCHEMA>"."FINANCIALS"( "ID" INTEGER not null, "MANDANT" CHAR (3) null default '', "COUNTRY" VARCHAR (20) null default '', "DATE" DATE null, "REVENUE" DECIMAL (8,2) not null, "COSTS" DECIMAL (8,2) not null, "EARNINGS" DECIMAL (8,2) not null, "CURRENCY" CHAR (3) null default '', primary key ("ID")); 3. As final step in this section deploy the table

Fill the new table with data

In the first step right-click on the new table and choose Generate -> Insert Statements from the context menu.

After that, the SQL editor will appear.

Enter the following SQL statements to fill the table with data. SQL code insert statment insert into "<YOUR SCHEMA>"."FINANCIALS" values(1,'100','Germany','01.07.2012',20000.00,5000.00,15000.00,'EUR'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(2,'100','Germany','02.07.2012',25000.00,5000.00,20000.00,'EUR'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(3,'100','Germany','03.07.2012',1000.55,500.10,500.45,'EUR'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(4,'200','USA','01.07.2012',14000.00,4000.00,10000.00,'USD'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(5,'100','Germany','01.07.2012',20000.00,18000.50,1999.50,'EUR'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(6,'300','China','01.07.2012',55000.00,5000.00,50000.00,'CNY'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(7,'300','China','02.07.2012',20000.00,5000.00,15000.00,'CNY'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(8,'300','China','03.07.2012',1000.99,200.99,800.00,'CNY'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(9,'200','USA','02.07.2012',19000.00,5000.18,13999.82,'USD'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(10,'200','USA','03.07.2012',21000.00,4000.00,17000.00,'USD'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(11,'400','England','01.07.2012',99000.00,70000.00,29000.00,'GBP'); insert into "<YOUR SCHEMA>"."FINANCIALS" values(12,'100','Germany','04.07.2012',1111.11,444.44,666.67,'EUR'); After that, open the data preview with right click.

Finally, your filled table will look like the screen shown below:

Create a new attribute view

To create a new attribute view, right-click on your package and choose New.

Choose a name for the new attribute view, and also a description. Click Next after naming. Ensure that you adhere to the SAP naming convention (ATR_)

On the next screen, choose the schema and table you created at begin of this tutorial. After that, click Finish.

Next, add ID as the key attribute and all other fields as attributes.

Finally, save and activate the attribute view

and take a look at the to check that everything went fine.

Create a new analytic privilege

In the first step, go to the folder Contents on your SAP HANA Workspace. If you dont see the folder, switch to the modeler perspective (right corner at the top of SAP HANA Studio).

With a right-click on this folder you can create a new package. You only have to enter a name.

After that, you can create a new analytic privilege by right-clicking on the package.

On the next screen enter a name and click NextEnsure that you adhere to the SAP naming convention (AP_).

After that choose your package and add the attribute view you created before. Then leave the screen by selecting Finish.

In the next step, a new window appears. At this point, define a new associated attribute restriction.

In our case, you select the field MANDANT (client).


After that, you can see the new entry in the area outline in red in the screenshot at the top this page. Now you must assign a restriction for that field, too. To do this, select Add as shown in screenshot. Then a new entry named equal appears in the red marked area in screenshot. Here, you can also choose another operator, but in our case it should be equal. Near to the operator you will find a browse button for selecting a value. If you click this button, you will see a new popup. Here you can search for client (mandant) 100 like on the screenshot below.

Finally you can save and deploy the analytic privilege using this button: In the job log you can take a look at the corresponding success message.


Performe a data preview

Before we assign the new privilege to our user, performe do a data preview on the actual attribute view. To do this, right-click on your attribute view in the content folder and choose Data Preview.

At this moment, you will see other entries apart from the entries of MANDANT 100.


Assign the new analytic privilege

To apply the new analytic privilege to the table FINANCIALS, you must assign the privilege to users. In this tutorial, you assign the analytic privilege a new SAP HANA user. To do this, you switch to the folder Catalog -> Authorization -> Users in the navigator pane. After that, right-click on Users and choose New User.

In the next window, enter a user name and password and add the role ANALYZER. This role includes all thenecessary basic rights for analysts.

After that, switch to the tab named SQL Privileges, add your attribute view and choose SELECT privilege.

Next, add your new analytic privilege:


Finally, click on the deploy button

Test the new analytic privilege

Now you can add a new connection for this user to SAP HANA studio. To do this, right-click on your current connection and choose the menu entry Add Additional User

On the screen that appears, enter username and password of the new user with role ANALYZER. After these initial steps, go to the new connection and choose the content folder. As an analyst you do not have any rights to see tables saved in schemas. For analyses, the modeler creates attribute and analytic views. For this test scenario, you created an attribute view in the previous steps. In the content folder, the tutorial package should be available. Browse to the FINANCIAL attribute view and open the data preview with a right click.


Here you can see the data restricted by the analytic view to client (mandant) 100. Previously, before assigning the privilege, you could see the whole content.

Clean up the system after ending this tutorial. To do this, delete the new user M_ANALYST. First, go into your own connection to the authorization folder and right-click on M_ANALYST, which is in the area Users. Choose Delete and select the option Restrict!

Delete the new connection for M_ANALYST using the right mouse-button, too.

Part of this tutorial is inspired by SAP training material