building simple data models with sap hana1

Upload: mangesh-kothuri

Post on 03-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    1/35

    BUILDING SIMPLE DATA MODELS WITH SAP HANA

    EIM162

    Exercises / SolutionsSpeakers Name / CompanyRichard Bremer, Werner Steyn, Masato Inoue / SAP CSA

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    2/35

    2

    Exercise Objectives

    SAP HANA comes with an application tool called SAP HANA Studio which incorporates the data modelling function

    within Information Modeller.

    After completing this lesson, you will be able to

    Use the Information Modeller

    Create Attribute Views and Analytic Views

    Add or remove text tables

    Create basic JOIN operations

    Activate and deploy views

    1 Preparations: Set up your SAP HANA StudioIn this exercise, you will work on an SAP HANA system with the following system properties:

    Host name: coe-he-37.wdf.sap.corp

    Instance number: 37

    SAP System ID (SID): H37

    Database user name: EIM162_XX

    Initial password: Init1234

    You will work with the administration and modelling tool for SAP HANA, named SAP HANA Studio.

    In this software, one can maintain connections to several SAP HANA backend systems, and for each such systemseveral database users can be configured.

    As preparatory steps, we will make sure a connection to the correct SAP HANA database system is defined with youruser (EIM162_XX).

    1. Start the SAP HANA studio from theWindows Desktop(the icon labelled HANA DB Studio)

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    3/35

    3

    2. Optional:If SAP HANA Studio is started for thefirst time on a given PC/user account, awizard appears that allows choosing aworking mode.

    For this exercise, choose theInformation Modeler perspective (OpenInformation Modeler)

    3. Alternative: if your local SAP HANAStudio has already been started bysomeone else, the above selectionwizard will not appear.

    To make sure the following exercisescan be followed, you can explicitlyswitch the application into theinformation modeler mode:

    Choose the menu path Window Open PerspectiveOther

    From the pop-up, select InformationModeler

    the system will switch intomodelling mode.

    However, there may still be a user-specific UI configuration active froma previous session.

    Choose the menu path Window Reset Perspective

    Confirm the Pop-up dialog with OK

    this will create the default UI

    configuration for creatingInformation Models.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    4/35

    4

    4. In the following steps we are going toset up a connection to a SAP HANAdatabase system.

    The system/user definitions appear inthe left-hand part of the screen, the so-called Navigator.

    5. If there are already connections to SAPHANA systems defined in your localSAP HANA studio, you can removethem by right-clicking the system entryand choosing Delete from the contextmenu.

    Confirm the pop-up dialog with OK.

    This will only delete the connectiondefinition from your local SAP HANAstudio, it will not delete the actual SAPHANA system.

    6. In order to add a new system, right-clickthe background of the white area in theNavigator view.

    Choose Add System from the

    context menu.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    5/35

    5

    7. Register a new System. Click > RegisterSystem within the Navigator view.

    Enter the Hostname, InstanceNumber and Description.

    Host:coe-he-37.wdf.sap.corp

    Instance: 37

    Description: free choice

    Click > Next.

    8. Enter your assigned UserandPassword credentials.

    Use EIM162_xxwhere xxrepresents your assigned number

    The initial password is Init1234

    Click > Finish.

    9. You will be asked to change your

    password.

    Change the password to Abcd1234

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    6/35

    6

    10. Click Ok.

    11. The representation of the SAP HANAsystem in the Navigator tree consists oftwo parts:

    The Catalog is the databaseadministrators view of the SAPHANA system. It contains alldatabase objects, e.g. databaseschemas (with tables, views,procedures) or an authorizationfolder in which one can find all

    database users and available roles.

    The Content is the modelers viewof the SAP HANA system: here onecan create multi-dimensional datamodels, organized in a packagestructure.

    12. The Catalog contains folders for alldatabase schemas

    Each Schema contains a folder forColumn Views, Procedures, Tablesand Views.

    Also notice the Catalog has a folderfor Authorizations.

    13. The Content contains folders for allpackages in the system

    Packages can have a hierarchicalstructure

    Inside of each package there arefolders for the different types ofobjects one can build to create adata model in SAP HANA.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    7/35

    7

    14. Create your own package namedEIM162.xx(where xx is your user number for thisclass):

    Right-click on the Content folder

    Select New Package from thecontext menu

    15. In the creation wizard, enter:

    Name: eim162.xx

    Description: free choice

    Delivery Unit: ignore this field

    16. Finally, we set a few user parameters aspreparations:

    We are working on SAP tables, so theclient will play a role in the data models.

    In the Catalog, expand the path:AuthorizationUsers

    Double-click your User name

    EIM162_xx

    In the user editor, set the field SessionClient to 800

    Save (via save button or by hittingCtrl + S)

    17. When reporting off the data models, thesystem can filter on the data client andthe language of text fields dynamically.

    In order to enable dynamic client andlanguage handling, do the following:

    In the menu, go to:WindowPreferences

    In the pop-up, go to InformationModelerDefault Model Parameters

    Set Default Client and Default Language

    to dynamic.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    8/35

    8

    In the same pop-up windows, go toInformation ModelerData Previewand enable the display of calculatedcolumns.

    2 Create the Attribute Views

    1. Please navigate in the InformationModeler to your own package.

    NOTE:Please make sure you selectyour own package:

    eim162.xx

    2. Create a new Attribute View:

    Select the Attribute View of yourpackage and using Right MouseButton Menu New > Attribute Viewto create new Attribute View.

    Enter the name of the AttributeView: LOCATION_XX anddescription, Customer Location XX.

    Select StandardAttribute ViewType.

    Press next.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    9/35

    9

    3. From the EIM162 schema select thetable KNA1to build the AttributeView.

    Enter KNA1 then press the filterbutton.

    Proceed to select EIM162.KNA1and press theAddbutton to movethe table into the Selectedarea.

    Repeat the above steps to add tableT005U from schema EIM162.

    Click Finish to get into the AttributeView Editor

    Tip: In case you closed the creationwizard for the Attribute view beforeselecting all tables, you can press the

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    10/35

    10

    "Add table" button and continue thetable selection.

    4. The Attribute View editor getspopulated with the selected tables.

    This is where you will define therelationships of the attributes.

    5. User will now select the fields foruse in the attribute view

    Select the key field KUNNR andright mouse click on field. ChooseAdd as Key Attribute.

    Result: The KUNNR:KNA1.KUNNR

    shows in the Output frame.

    6. Display the properties of KUNNR.Select KUNNR from the Outputframe.

    On the Property Tab for fieldKUNNR, select Description Mappingand choose the fieldEIM162.KNA1.NAME1 from thedrop down list.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    11/35

    11

    7. Join field LAND1 from KNA1 toLAND1 of T005U as a text table

    join.

    Click on the join and change the jointype in the property view.

    Text Table (Join Type)

    1..1 (Cardinality).

    Select SPRAS for the LanguageColumn.

    8. Join field REGIO from KNA1 toT005U field BLAND.

    Check the join properties:

    Join Type: TextCardinality: 1:1Language Column: SPRAS

    Save.

    9. Add a second text table to theattribute view.

    You can do it by selecting the "Addtable" button and continue thetable selection.

    Enter table T005T and select thetable from schema EIM162 from thelist.

    Click OK.

    Result: Table EIM162.T005T isadded to the Data Foundation tab.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    12/35

    12

    10. Define a text join between fieldLAND1 from KNA1 to field LAND1from T005T

    Select the join and change the jointype in the property view.

    At the join Property frame selectas Language Column -> SPRAS

    HINT: Dont forget to make the jointype = textTable.

    11. Add KNA1.LAND1 as an attribute ->right click on LAND1 -> Add as

    Attribute.

    Select LAND1 from the Outputframe

    12. On the Property Tab for fieldLAND1, select Description Mappingand choose the fieldEIM162.T005T.LANDX

    13. Add KNA1.REGIOas an attribute ->right click on KNA1.REGION ->Add as Attribute

    14. Select KNA1.REGIO from the

    Output. On the Property Tab for field

    REGIO, select Description Mappingand choose the fieldEIM162.T005U.BEZEI.

    Save.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    13/35

    13

    15. Add ORT01 as an attribute.

    This is a description field for CITYso in this case there is no need tomap to a text table.

    Save.

    The Attribute View is fully defined.We can now activate it:

    On the Attribute ViewLOCATION_XX, right click andselect Activate.

    Result: The Job Log will showsuccessful or give an errormessage.

    HOT TIP: If presented with the errormessage attribute view needs at leastone key attribute or key measure youlikely saved at a point in time when nokey attribute was selected. To solve this

    problem, close the studio and open thestudio again. Activate the attribute viewwithout opening it.

    16. Choose Attribute View,LOCATION_XX. Right click tochoose Data Preview.

    Note that KUNNR, LAND1 andREGIO has a description displayedin the Data Preview due to thedescription mapping assignment.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    14/35

    14

    17. Next create a new Attribute View forproduct.

    Name it PRODUCT_XX withdescription PRODUCT_XX.

    Join table MARA and table MAKT(on field MATNR)

    Define the join as a text join on the

    properties tab.

    Define the language column asSPRAS on the Property Tab.

    HINT: Define the descriptionmapping for the key attributeMAKT.MAKTX MARA.MATNR.

    Save, Activate & Preview.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    15/35

    15

    3 Create the Analytic View

    1. Close all open views prior to creating anew analytical view.

    Create an analytic view CEA1_XXwith the description ContributionMargin for Actuals.

    2. Find a table, CE1IDEA and click Add.

    Remember you have to find thetable by clicking on the arrow next tothe input field

    ImportantDo not click finish or youwill have to start over.

    Click Next.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    16/35

    16

    3. On the next screen of the wizard,navigate to your package, expand thefolder and select the attribute views forPRODUCT_XX and LOCATION_XX.

    Click on Finish.

    4. Choose the Data Foundation Tab. Result: You will see table CE1IDEA

    in your data foundation tab.

    5. Navigate to the Logical View Tab to seethe two attribute views.

    Note that the Data Foundation isempty.

    It will be filled once you select yourfields (attributes and measures)

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    17/35

    17

    6. Navigate to the Data Foundation Tab.

    Select the two fields KNDNR andARTNR from CE1IDEA and add

    them as attributes (right click).

    7. Navigate to the Logical Tab.

    Notice that the Data Foundationnow has two fields.

    Join DataFoundation.ARTNR toPRODUCT_xx.MATNR.

    Join DataFoundation.KNDNR toLOCATION_xx_KUNNR.

    8. Navigate to Data Foundation Tab,where we will define filters.

    Apply filters on the fieldsPALEDGER and VRGAR (recordtype).

    Select PALEDGER > right click >Apply Filter.

    o Choose Operator Equalfrom the Apply Filter dialogbox

    o Specify the value 01.

    For VRGAR, choose Operator Equaland specify the value F.

    Save.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    18/35

    18

    9. Notice there is now a filter icon next tothe PALEDGER and VRGAR.

    10. Next select the private attributes to beincluded in the analytic view.

    Choose from CE1IDEA thefollowing fields in addition toKNDNR and ARTNR:

    o PERIO,

    o VKORG,

    o PLIKZ.

    HINT: To find the fields quicklyenter thename of the filed in the Find Column field.

    11. Next select the measures to be includedin the analytic view.

    Choose from CE1IDEA the following

    fields: (Right click on the field > Addass measure)

    o VV010

    o VV070

    o VV290

    o VV960

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    19/35

    19

    12. Rename the measures in the Name fieldof the Property Tab for each measure.

    Use copy and paste from the tableto ensure that use the exactdescriptions.

    Change From Change To

    VV010 GrossRevenue

    VV070 SalesDeduction

    VV290 ProductionVariance

    VV960 OtherExpenses

    Save.

    13. Next define the calculated measures tobe included in the analytic view.

    Right click on Calculated Measuresand choose New.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    20/35

    20

    14. Create the first Calculated Measure,NetRevenue.

    - Select Decimal data type withlength 15, Scale 2

    - Double click on the desired

    measure for it to appear in theexpression editor. Either type inthe minus sign or double clickon the Operator.

    Continue to create all other needed Calculated Measures.

    Name Description Data Type Length Formula

    NetRevenue Net Revenue DECIMAL 15 GrossRevenue - SalesDeduction

    CM1 Contribution Margin 1 DECIMAL 15 NetRevenue - ProductVariance

    CM2 Contribution Margin 2 DECIMAL 15 CM1 - OtherExpenses

    Save and Activate your Analytic View.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    21/35

    21

    15. Display the data in your Analytic View.

    Right click on Analytic View andselect Data Preview

    4 User Management and Security

    This exercise will demonstrate which minimum set of privileges a user needs in order to read data from one particulardata model in HANA.You will find a reporting user named TESTXX (XX being your group number) which you will supply with sufficientprivileges to read data from the data model you have created earlier.In this Exercise you will do the following tasks:

    Add Package Privileges to user TESTXXthese will allow browsing the list of packages and seeing the views inside of the packagesit is only needed for preview from inside of HANA Studio. The privilege is not required for using other reporting

    tools.for simplicity, we collected all require package privileges into one role.

    Add SQL privileges to user TESTXX

    Create an Analytic Privilege based on the Analytic View you created

    Assign this Analytic Privilege to user TESTXX

    Verify that the security concept works as described.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    22/35

    22

    Part 1: Add user TESTXX to your SAP HANA Studio:

    1. Right-click the entry for System H37 inthe Navigator tree

    Choose Add Additional User

    2. Enter user name TEST00

    Password Init1234

    Klick Finish

    3. Enter and confirm the new password

    Suggestion: Abcd1234

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    23/35

    23

    4. Right-click the new entry for SystemGBS and user TestXX in the Navigatortree

    Choose Refresh from the contextmenu

    This will update the system status inyour Navigator tree.

    Part 2: Check the Privileges assigned to user TESTXX

    5. Open the user editor for user TESTXX

    Work as user EIM162_XX

    Navigate to the following path:H37 (EIM162_XX)Default CatalogAuthorizationUsers

    Either: Right-click user TESTXX andchoose Open

    Or: double-click user TESTXX

    6. Check all tabs for the different types of

    privileges (Granted Roles, SQLPrivileges, Analytic Privileges, SystemPrivileges and Package Privileges

    Verify that the only granted privilege isrole PUBLIC

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    24/35

    24

    7. In the user editor for user TESTXX, setthe Session Client field to 800

    In our ERP tables, the client is 800.

    If you have the default client for your

    data models set to dynamic, theSession Client from your user profile willbe substituted at query run time.

    8. Save the user profile:

    Either click the Save icon

    Or hit Ctrl+s

    We will continue using this user editor

    for user TESTXX, so do not close it.

    Part 3: Verify that the user cannot view your Analytic Views or the Calculation View you havecreated:

    9. Work as user TESTXX

    Try navigating to the following pathH37 (TESTXX)Contenteim162.xxAnalytic Views

    On trying to expand folder Content youshould receive an error message asshown on the right.

    This is because access to the contenttree (design time versions of InformationModels) is restricted by PackagePrivileges. User TESTXX does not haveany Package Privileges assigned.

    Part 4: Add Package Privileges to user TESTXX

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    25/35

    25

    10. Switch to the user editor for userTESTXX

    Verify that the user who opened thedialog is your user EIM162_XX

    Within the editor, switch to tab GrantedRoles

    11. We created a predefined role thatcontains all privileges needed to browse

    the Content Tree and allow you toattempt a preview.

    Click the green -icon to add a newrole to user TESTXX.

    In the search dialog, start typingREPO_ADMIN_ROLE.

    Once the Search-as-you-type finds thedesired role, highlight roleREPO_ADMIN_ROLE in the list of

    Matching items, then click OK

    12. Save the user profile:

    Either click the Save icon

    Or hit Ctrl+s

    We will continue using this user editorfor user TESTXX, so do not close it.

    Part 5: Verify that the user cannot view your analytic views nor the calculation view you havecreated:

    13. Work as user TESTXX

    Right-click the Content-folder

    Select Refresh from the context menu.

    This should now show the list of allpackages in the system.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    26/35

    26

    14. Work as user TESTXX

    Navigate to the following path

    H37 (TESTXX)Contenteim162.xxAnalytic Views

    Right-click the Analytic View CEA1_XX

    Select Data Preview from the contextmenu.

    (You may do the same for the otherAnalytic Views or for the Calculationview)

    15. Data preview should give you an errormessage as in the screenshot to theright.

    The reason for this message is that theuser is missing SQL privileges to accessthe runtime object of the Analytic View.

    The runtime object of the Analytic Viewis the Consumption Column View

    created in Schema _SYS_BIC.

    That view is named:_SYS_BIC./

    Part 6: Add SQL Privileges to the user

    16. Again make sure the user editor for userTESTXX is opened by user EIM162_XX.

    Switch to tab SQL Privileges.

    Click the -icon

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    27/35

    27

    17. In the search window, start typingeim162.XX/CEA1_XX (where bothoccurences of XX must be replaced byyour group number).

    Hint: including the package name in the

    search will greatly help you find therequired view (compared to only tryingto search for CEA1_XX

    Select the appropriate cube from the listof Matching items.

    Click OK.

    18. Now you have selected the object for

    which you want to grant SQL privileges,you also have to choose what privilegeto grant.

    For reading from an object, we need togrant the SELECT-privilege.

    Highlight the SQL Objecteim162.XX/CEA1_XX

    Activate the check box for theSELECT-Privilege.

    19. Save the user profile:

    Either click the Save icon

    Or hit Ctrl+s

    We will continue using this user editorfor user TESTXX, so do not close it.

    Part 7: Verify that the user still cannot read from the views

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    28/35

    28

    20. Work as user TESTXX

    Navigate to the following pathH37 (TESTXX)Contenteim162.xx

    Analytic Views

    Right-click the Analytic View CEA1_XX

    Select Data Preview from the contextmenu.

    21. Data preview should give you a differenterror message now, see the screenshotto the right.

    The reason for this message is the userhas SQL access to the run time object,but is still missing an Analytic Privilege.

    You may test this for the other views aswell.

    Part 8: Create an Analytic Privilege based on Analytic View CEA1_XXIn the following we are going to grant Analytic Privileges to user TESTXX which will finally allow reporting off the

    Analytic and Calculation Views. We are restricting access to only Material Number P-103.

    22. Work as user EIM162_XX

    Navigate to the following pathH37 (EIM162XX)Contenteim162.xxAnalytic Privileges

    Right-click the folder name AnalyticPrivileges

    Select NewAnalytic Privilege fromthe context menu.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    29/35

    29

    23. In the creation wizard, type the name:AP_CEA1_P103_XX(replacing XX appropriately)

    Enter a description

    Click Next

    24. In the second step of the wizard, selectyour view eim162.XX/CEA1_XX

    Highlight that view in the Content treeon the left.

    Click Addthis will add the view tothe right-hand part of the display.

    Click Finish.

    25. Implementing the privilege is now donein three steps:

    1) Select further views for which thisprivilege should be valid (optional)We will not add further views in thisstep.

    2) Select attributes on which a restrictionshall be defined(All fields of all views selected in 1)will be offered)

    3) Define value restrictions for theattributes selected in 2)

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    30/35

    30

    26. Add the field MATNR to the list ofAssociated Attributes Restrictions.

    Click the corresponding Add button

    Select field MATNR from the

    presented field list

    Click OK

    27. Define the value restriction for fieldMATNR

    Highlight the MATNR field underAssociated Attributes Restrictions

    Click the Add button for AssignRestrictions (this increases the counterfor the number of restrictions forMATNR)

    Click into the Value field in AssignRestrictions. Click the -icon.

    In the search window, search forMaterial P-103

    Select the material from the search list(if the search list remains empty, youare probably working with user TESTXX

    this user does not have sufficientprivileges to read the list of values)

    Click OK

    (Note: you could also have typed in thevalue directly, without opening thesearch window).

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    31/35

    31

    28. Save the Analytic Privilege:

    Either click the Save icon or hitCtrl+s.

    Then activate the Analytic Privilege

    Part 9: Assign Analytic Privilege AP_CEA1_P103_XX to user TESTXX

    29. Work as user EIM162_XX

    Open the User Editor for user TESTXX

    In that Editor, switch to tab AnalyticPrivileges

    30. Click the green +-icon

    In the search dialog, start typingeim162.XX/AP_CEA1_P103_XX (replacing XX appropriately)

    From the list of Matching items, selectprivilegeeim162.XX/AP_CEA1_P103_XX

    Click OK

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    32/35

    32

    31. Save the user profile:

    Either click the Save icon

    Or hit Ctrl+s

    Part 10: Verify that the user can read from Analytic View CEA1_XX

    32. Work as user TESTXX

    Navigate to the following pathH37 (EIM162_XX)Contenteim162.xxAnalytic Views

    Right-click the Analytic View CEA1_XX

    Select Data Preview from the contextmenu.

    33. Data Preview should now return a list of474 output values.

    (Make sure to set Max Rows to at least500, recommended value for this test is2000)

    Verify that the list contains only recordswith MATNR = P-103

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    33/35

    33

    5 Optional Reporting Exercise: SAP BusinessObjects Analysis for Office

    1. Open the program Analysis forMicrosoft Excel from the start menu:

    Start Menu

    Programs SAP

    SAP BusinessObjects

    Analysis for Microsoft Excel

    2. Start the Insert Data Source wizard:

    Make sure to work in ribbon-areaAnalysis

    Select InsertSelect Data Source

    3. Select Skip on the first screen of thewizard

    4. The system presents you with a list ofknown ODBC connections and SAPSystems.

    Choose the entry EIM162 which isan ODBC connection to SAP HANAdatabase system coe-he-37 (H37)

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    34/35

    34

    5. If you completed exercise 4 (UserManagement and Security), you cannow enter the credentials of your userTESTxx

    Otherwise enter the credentials of

    your user EIM162_xx

    6. The software presents you with a listof all packages in the SAP HANAdatabase system H37. Open yourpackage (eim162.xx) and open your

    Analytic View (CEA1_xx).

    7. This opens the view. You can use thefunctionalities of SAPBusinessObjects Analysis forMicrosoft Excel to navigate this view.

  • 8/12/2019 Building Simple Data Models With Sap Hana1

    35/35

    2011 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 orregistered 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 such products and services, if any. Nothing herein should be construed as constituting an additional warranty.