SapHanaTutorial.Com HOME     Learning-Materials Interview-Q&A Certifications Quiz Online-Courses Forum Jobs Trendz FAQs  
     Explore The World of Hana With Us     
About Us
Contact Us
 Apps
X
HANA App
>>>
Hadoop App
>>>
Tutorial App on SAP HANA
This app is an All-In-One package to provide everything to HANA Lovers.

It contains
1. Courses on SAP HANA - Basics, Modeling and Administration
2. Multiple Quizzes on Overview, Modelling, Architeture, and Administration
3. Most popular articles on SAP HANA
4. Series of Interview questions to brushup your HANA skills
Tutorial App on Hadoop
This app is an All-In-One package to provide everything to Hadoop Lovers.

It contains
1. Courses on Hadoop - Basics and Advanced
2. Multiple Quizzes on Basics, MapReduce and HDFS
3. Most popular articles on Hadoop
4. Series of Interview questions to brushup your skills
Apps
HANA App
Hadoop App
';
Search
Stay Connected
Search Topics
Topic Index
+
-
SAP HANA Modeling
+
-
Spatial Processing
+
-
Predictive Analysis

Build First SAP HANA Model in 10 minutes

In the article SAP HANA Modeling Introduction we explained the basics of SAP HANA data modeling.
This article describes how to build a simple model using data stored on SAP HANA.
By the end of this, you will have created tables, attribute views, and analytical views in SAP HANA.

Prerequisite:
Create new tables in SAP HANA and fill them with data:

  1. Open HANA Studio and expand the SAP HANA system.
  2. Go to your schema. Right-click on your schema and select SQL editor.
    SAP HANA Studio
    Note: In this example schema name is "SAP_HANA_TUTORIAL". In case you want to create a new schema use below query.
create schema <schema_name>;
  • Copy and paste the below script in SQL editor and execute.

  • --REPLACE <YOUR SCHEMA> WITH YOUR SCHEMA NAME

    -- Create Product table
    create column table "<YOUR SCHEMA>"."PRODUCT"(
          "PRODUCT_ID" INTEGER null,
          "PRODUCT_NAME" VARCHAR (100) null default ''
    );

    insert into "<YOUR SCHEMA>"."PRODUCT" values(1,'Shirts');
    insert into "<YOUR SCHEMA>"."PRODUCT" values(2,'Jackets');
    insert into "<YOUR SCHEMA>"."PRODUCT" values(3,'Trousers');
    insert into "<YOUR SCHEMA>"."PRODUCT" values(4,'Coats');
    insert into "<YOUR SCHEMA>"."PRODUCT" values(5,'Purse');
    -- Create Region table
    create column table "<YOUR SCHEMA>"."REGION"(
          "REGION_ID" INTEGER null,
          "REGION_NAME" VARCHAR (100) null default '',
          "SUB_REGION_NAME" VARCHAR (100) null default ''
    );

    insert into "<YOUR SCHEMA>"."REGION" values(1,'Americas','North-America');
    insert into "<YOUR SCHEMA>"."REGION" values(2,'Americas','South-America');
    insert into "<YOUR SCHEMA>"."REGION" values(3,'Asia','India');
    insert into "<YOUR SCHEMA>"."REGION" values(4,'Asia','Japan');
    insert into "<YOUR SCHEMA>"."REGION" values(5,'Europe','Germany');

    -- Create Sales table
    create column table "<YOUR SCHEMA>"."SALES"(
          "REGION_ID" INTEGER null,
          "PRODUCT_ID" INTEGER null,
          "SALES_AMOUNT" DOUBLE null);

    insert into "<YOUR SCHEMA>"."SALES" values(1,1,100);
    insert into "<YOUR SCHEMA>"."SALES" values(1,2,90);
    insert into "<YOUR SCHEMA>"."SALES" values(1,5,85);
    insert into "<YOUR SCHEMA>"."SALES" values(2,2,80);
    insert into "<YOUR SCHEMA>"."SALES" values(2,1,75);
    insert into "<YOUR SCHEMA>"."SALES" values(3,3,85);
    insert into "<YOUR SCHEMA>"."SALES" values(4,4,75);
    insert into "<YOUR SCHEMA>"."SALES" values(5,1,65);
    insert into "<YOUR SCHEMA>"."SALES" values(5,2,65);
  • After executing the scripts you should have 3 tables created. If there are no tables, try right-clicking on your schema and refreshing.
    SAP HANA Studio
  • Note: To know all about create/update/delete tables in HANA, read the article Working with Tables in SAP HANA

    Grant schema SELECT rights to _SYS_REPO user:

    Open the SQL editor of your schema and execute the following command line:
    GRANT SELECT ON SCHEMA <YOUR SCHEMA> TO _SYS_REPO WITH GRANT OPTION;
    If you miss this step, an error will occur when you activate your views later.
    Click here to know more about this.

    Create an attribute view:

    1. Open HANA Studio and make sure you are in Modeler perspective

    2. SAP HANA Studio
    3. Create a new package under the content folder.
      Right-click on the content folder and choose "New" -> "Package." Fill the fields "Name" and "Description" and click "OK."
      If you dont see the new package after this, try right-clicking on the content folder and refreshing.
    4. Right click on the package and choose "New Attribute View." Enter a name and a description and click "Finish"

      SAP HANA Attribute View
    5. The attribute view will be opened in the HANA studio editor. Select "+" sign on "Data Foundation"

      SAP HANA Attribute View
    6. Search for table "REGION" and select it.

      SAP HANA Attribute View
    7. Now add the columns from the REGION table to output. Simply right click on the column and select "Add to Output". Add all 3 columns REGION_ID, REGION_NAME, SUB_REGION_NAME to the output.
      Once it is done, you will see the selected column in right side pane.

      SAP HANA Attribute View
    8. Now select "Semantics". All 3 columns appears under Column pane as attributes.
      SAP HANA Attribute View
    9. Now you need to define attributes and key attributes. Every attribute view must have at least one key attribute.
    10. Click on the "Type" to select key attribute for REGION_ID.

      SAP HANA Studio
    11. Click on the "Save and Activate" button on top right corner to activate the view.

      SAP HANA Studio
    12. In the "Job log" Pane you will see an activation completed message.

      SAP HANA Studio
    13. Attribute view is created and activated.
      To see the output of this view click on the "Data Preview" button on top right corner.
      SAP HANA Studio

      Then select "Raw Data" tab.
      SAP HANA Studio

    Congratulation!! You have successfully created your first modeling view.

    Next step is to create an analytic view.

    Create an Analytic View:

    1. Right click on the package and choose "New Analytic View." Enter a name and a description and click "Finish"

      SAP HANA Analytic View
    2. Click on "+" sign of "Data Foundation" and add table SALES.

      SAP HANA Analytic View
    3. Right Click on the columns of table SALES and add REGION_ID and SALES_AMOUNT to output.

      SAP HANA Analytic View
    4. Click on "+" sign of "Logical Join" and add attribute view "AT_Region" which was created earlier.

      SAP HANA Analytic View
    5. Click on the REGION_ID from "Data Foundation" and connect it to the REGION_ID of attribute view AT_Region. In the properties pane select join type as left outer join and cardinality as n..1

      SAP HANA Analytic View
    6. Select "Sementics". In the right side change the column type of SALES_AMOUNT as measure.

      SAP HANA Analytic View
    7. Activate the analytic view similar to attribute view.
      Right-click on your analytic view and choose "Data Preview." After that, you can browse through the tabs named raw data, distinct values, and analysis.

      SAP HANA Analytic View

      SAP HANA Analytic View

    Congratulation!! You have successfully created your first Analytic View.


    Support us by sharing this article.



    Explore More
    Close X
    Close X

    53 thoughts on “Build Your First SAP HANA Model

    1. Sriram P says:

      Thank you. This tutorial was very helpful

    2. Ranga Baddam says:

      Thank you for building and maintaining this site and helping and encouraging new SAP HANA learners.

      This tutorial is definitely useful to get started

    3. Robson says:

      After clicking in Raw Data, the following message is displayed.

      “Error executing the query
      Error: SAP DBTech JDBC: [258]: insufficient privilege: Not authorized”

      I’m in SAP HANA Cloud Platform

      The grant to _SYS_REPO under DEV_xxxxxxxxxx schema was successful.

      I created the package p123456trial.myhanaxs.sap-hana-tutorial

      Any idea how to solve this problem?

      Thanks!

    4. sambath says:

      Hi, I am MBA graduate, like to study SAP. Anyone help em to choose module which have good scope. thanks

    5. HARI SUBRAMONY says:

      Hi,

      I am totally new to SAP. I was following the website to learn HANA.
      Since SAP was not providing 30 free trial anymore, I have registered via CLOUD and have Added the Cloud system in my eclipse with account p19412607523trial. I was not able to ADD SYSTEM as I did not receive HOSTNAME and INSTANCE number via email.

      When trying to create the schema I am getting the below mentioned error.

      Could not execute ‘create schema SAP_HANA_TUTORIAL’
      SAP DBTech JDBC: [258]: insufficient privilege: Not authorized

      Please suggest if I have missed something here. Thanks.

      • Admin says:

        Hi Hari,
        In cloud trial account, you need to grant permissions to application’s db user.
        Try to call the below procedure from SQL Console.

        CALL “HCP”.”HCP_GRANT_SELECT_ON_ACTIVATED_OBJECTS”

        • Vahid says:

          Hi
          I have the same problem but when run this Call procedure , get this error:
          Could not execute ‘CALL “HCP”.”HCP_GRANT_SELECT_ON_ACTIVATED_OBJECTS’
          SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near “”HCP_GRANT_SELECT_ON_ACTIVATED_OBJECTS”: line 1 col 16 (at pos 16

          • Admin says:

            Hi Vahid,
            It might be the problem of double quote (“).

            • Vahid says:

              Hi
              I get this message then :
              Could not execute ‘CALL “HCP”.”HCP_GRANT_SELECT_ON_ACTIVATED_OBJECTS”‘
              SAP DBTech JDBC: [258]: insufficient privilege: Not authorized

    6. dhanjay says:

      Dear site admin & content folks
      sincerely appreciate your efforts & contribution to Hana ‘talent generation’!
      Yours is a holy task & your are doing it religiously !

    7. BaaRaa says:

      Excellent document to start with. Thanks a lot.

    8. Krishna says:

      This website is really helpful to a beginner from any background. The way it has been developed is awesome. I recommend it to all beginners.

    9. Krishna says:

      Best place to learn for SAP HANA

    10. dharani Kumar says:

      Dear Admin,

      First my heart felt wishes for a excellent site on SAP HANA.
      As a novice in SAP HANA I have gained confidence by reading your tutorials that ‘I too can become SAP HANA consultant someday soon’.

      Keep up your good work and I would like to share the link to my friends.
      Best Regards
      Dharani.

    11. Sivaram says:

      Awesome Tutorial !
      Keep the good work going on !
      All the best !

    12. Javier Sarmiento says:

      Great job! It is a good place to start for beginners like me.

    13. Madhavi Ganatra says:

      hi
      I am getting
      Could not execute ‘create schema SAP_HANA_TUTORIAL’
      SAP DBTech JDBC: [258]: insufficient privilege: Not authorized
      error while creating schema
      i have called below procedure
      CALL “HCP”.”HCP_GRANT_SELECT_ON_ACTIVATED_OBJECTS”
      from sql console which is successfully executed still i am getting the error
      please suggest
      thanks in advance 🙂

      • Leonardo Carvalho says:

        Did you create your tables in DEV_ schema? If you did, delete your tables and recreate it in your NEO_ schema.
        For me this works!

    14. prakash says:

      It is very very nice & useful thank you very much ….

    15. Rajkumar says:

      Nice learning material for HANA. Its really helpful.

    16. Mantri Shekar says:

      Iam getting this error while i click on Display preview for analytical view Cannot get the data provider outline insuficient privilege not authorized

    17. Johnson Jos says:

      Really nice document. Everything i explained in required detail. I was able to start with HANA modelling only because of this document

    18. venkat says:

      I get this error while creating schema, can anyone help me

      Could not execute ‘create schema SAP_HANA_TUTORIAL’
      SAP DBTech JDBC: [258]: insufficient privilege: Not authorized

    19. Manojkumar Kotti says:

      Really appreciate your great efforts for providing important insights of HANA.

      All the documents are very clear and to the point.

      Thanks a lot guys.

    20. Gbans Srini says:

      Hi Site Admin & HANA Developers,

      I am trying to create a simple AttributeView.

      Have followed all the steps in your tutorial and everything goes fine and at the final save and validate AttributeView am getting an error “Repository: Encountered an error in repository runtime extension;Index $IDX$ out of range [$BEG$, $END$)”

      This has been happening consistently for the past 5-10 times, not sure what i am doing incorrectly.
      Have searched the net, but no useful info about this error in SDN…

      Please let me know how to proceed, if anyone have encountered this error.

      Thanks,
      Srini

      • Admin says:

        Hello,

        Thank you for reaching us, we would be glad to help you if it’s in our reach.

        But to conclude anything, we need to know the steps you were following and atleast screenshots of some your steps with error .

        Thanks,
        Admin

    21. Nagarjuna says:

      Hi i really got the useful information that i wanted. really i should appreciate your efforts for this.

    22. Dineshkumar says:

      Hi Admin,
      Really Nice learning material for HANA.
      I’m Fresher,I need some help regarding the Hana,
      can i get another a mini project or sample project for Calculation view.
      Because i need to know what type of question,the customer will arise for modeling & reporting.
      And is there any possibility to get sample project form other site links for an example for working.

      Thanks,
      Admin.

    23. RAMs says:

      Thanks lot for good job

    24. Srinivasareddy says:

      Excellent tutotorial ..Really it is very much useful for beginners.

    25. John says:

      Thank you for the tutorial !

      But I have one question:
      why do you state the cardinality as 1:N in this case ?
      Each REGION_ID is a unique REGION_SUBREGION pair and thus in the resulting joint table there will be only a single line with corresponding SALE number.

      The same would be if I create another analytical view AV_SALES_BY_PRODUCT: 1 to 1 cardinality as each product appears only only once in a resulting table.

      This would be different of course for AV_SALES_BY_REGION_BY_PRODUCT.

      Am I correct here or totally confused ?

      Thank you

    26. John says:

      I also try to understand the principle difference between Attribute View and Analytical View.
      For instance,

      I can create AT_SALES_PRODUCT Attribute View by joints.
      Does it do the work?
      Do I need to create a similar Analytical View AV_SALES_BY_REGION_BY_PRODUCT as well?
      Will the Analytical View created be of any advantages in comparison to AT_SALES_PRODUCT ?

      Thank you a lot !

    27. Vikash says:

      Thank you for this useful and beautifully explained article.

    28. ram says:

      Hi,Thanks for this article.
      Can we add HANA cloud as DB,if we are not able to download HANA studio.
      If so can you tell me where we have to add.

      • Admin says:

        Hello,

        We are unable to understand your query, could please explain further?

        SAP HANA Cloud is a cloud platform , we are not sure how could you add the HANA cloud platform as a database and where could you add it…..
        Did you mean to say “adding DB instance in Cloud”? Please, provide more clarity on your query…

        Thanks,
        Admin

    29. Javed Akhter says:

      While creating my view I struggled to resolve and find a solution to get a Count of Unique values from a Column in Calculated View.

      Can you please assist me in this regard.

      I have following query:

      SELECT

      YEAR (TABLE_1.COLUMN1) as YEAR,

      MONTH (TABLE_1.COLUMN1) as MONTH,

      MONTHNAME (TABLE_1.COLUMN1) as TRANX_MONTHNAME,

      TABLE_1.COLUMN2,

      SUM (TABLE_1.CURRENCY_AMT) as CURRENCY_AMT, —- measure , sum , decimal

      Count (TABLE_1.TRANX_ID) as TRANX_COUNT, —- measure , count, decimal

      Count (Distinct TABLE_1.ACCOUNT_ID) as ACCT_ID_COUNT

      FROM TABLE_1

      Where TABLE_1.COLUMN2 in (’23’)

      GROUP BY

      YEAR (TABLE_1.COLUMN1),

      MONTH (TABLE_1.COLUMN1),

      MONTHNAME (TABLE_1.COLUMN1),

      TABLE_1.COLUMN2

      /*

      I am looking for count of unique values for “Distinct TABLE_1.REWARD_ACCOUNT_ID” . I can run it in SQL but view doesn’t allow me. I am looking for following value in HANA Syntax. You have provided a solution but I am unable to understand.

      Count (Distinct TABLE_1.ACCOUNT_ID) as ACCT_ID_COUNT —- measure , count, decimal

      What I am always getting is below:

      Count(TABLE_1.ACCOUNT_ID) as ACCT_ID_COUNT —- measure , count, decimal

      */

      Can you please provide me a SQL syntax to get a unique count value.

      I will really appreciate.

    30. Javed Akhter says:

      Please some one solve this query.

    31. devesh says:

      Insufficient privilege (EXECUTE on REPOSITORY_REST) error when creating package
      I am getting the above error under content.
      I have added the cloud system in sap hana

      • Admin says:

        Hello,

        Send us the screenshots at “admin@saphanatutorial.com” along with mentioning steps you were following.
        The screenshots would help us to understand better.

        Thanks,
        Admin

    32. Mahesh M says:

      Hello ,

      This is Mahesh my education is MCA, Iam working in M M MODULE end user last 6 years. How can I convert to software field suggest me.

      Thanks

    33. Nilesh Bhayani says:

      I am using HANA cloud trial platform and facing below issue while using HANA studio(version: 2.1.11) to create views(Attribute, Analytical…).

      When I am trying to create Attribute view from HANA Studio it gives error ‘Failed to create the part’s control’, Unhandled event loop exception.

      Same attribute view, I am able to create using same User ID and Database using eclipse in another machine.

      Can u please help, what could be wrong with HANA studio?

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Current day month ye@r *

     © 2017 : saphanatutorial.com, All rights reserved.  Privacy Policy