Skip to Content

Create Calculation View in SAP HANA Cloud

Create your own calculation views in SAP HANA Cloud, SAP HANA database with SAP Business Application Studio.
You will learn
  • How SAP HANA modeling is performed using SAP Business Application Studio
  • How to create and use HDI containers
venkatps1Venkata Reddy P SOctober 10, 2021
Created by
venkatps1
October 10, 2021
Contributors
venkatps1

Prerequisites

  • You have Set Up a BTP Account for Tutorials. Follow the instructions to get an account, and then to set up entitlements and service instances for the following BTP services.
    • SAP Business Application Studio
    • SAP Analytics Cloud trial

In this tutorial, you will learn about the creation of a calculation view in SAP HANA Cloud. The created calculation view is later consumed in SAP Analytics Cloud using Live Data Connection to create a story for detailed data analysis.

  • Step 1
    1. Login to your BTP trial subaccount, navigate to subscriptions and select SAP Business Application Studio.

      SAP Business Application Studio

      This will open the dev spaces.

    2. Click Create Dev Space.

      DevSpace Creation
    3. Select SAP HANA Native Application for the Dev Space type and specify a name.

      We have provided the name as HANADevSpace.

      DevSpace Creation
    4. Click Create Dev Space.

      In a minute, the Dev Space will get created. You need to start the Dev Space, which will by default be in stopped state.

      DevSpace Starting

      After starting, the state of the Dev Space changes to Running.

      DevSpace Starting
  • Step 2
    1. Click on the Dev Space name to launch SAP Business Application Studio.

      BAS Starting

      After launching SAP Business Application Studio, you need to log in to Cloud Foundry.

    2. To log in, click View > find command and enter CF. From the available options, select Login to Cloud Foundry.

      CF Login
    3. Specify your Cloud Foundry endpoint.

      CF Login
    4. Enter your e-mail address.

      CF Login
    5. Select the space from the CF Subaccount. This will set the CF Organization and Space for the application we are building

      CF Login
    6. A confirmation message will be shown at the bottom of the screen.

      CF Login
  • Step 3

    You will start the creation of the project now.

    1. Select File > Project from Template, which shows the list of available templates to create applications using BAS.

      HANA Project Creation
    2. For this scenario, select SAP HANA Database project and then click Start.

      HANA Project Creation
    3. Specify a name to the project

      HANA Project Creation
    4. Leave the basic properties as is (for example, module name is db).

      HANA Project Creation
    5. Leave the namespace and schema fields empty. Check ‘Yes’ for the binding the database module to a Cloud Foundry service instance property.

      HANA Project Creation
    6. Leave default values for HDI Container service and then click Finish.

      HANA Project Creation

      The SAP HANA database project generation will start.

      HANA Project Creation

      Now you will be able to see the project in the Explorer section of SAP Business Application Studio.

      HANA Project Creation
  • Step 4
    1. Click View > find command, type HANA and then select the option Create SAP HANA Database Artifact.

      HANA Table Creation
    2. Select the source folder in the project to create the artifact and choose the artifact type as Table (hdbtable).

      Name the table customers.

      HANA Table Creation
    3. Include the following code for the table definition:

      SQL
      Copy
      COLUMN TABLE "customers"(custid integer, custname varchar(40), custcountry varchar(3), custregion varchar(4));
      
      HANA Table Creation
    4. Click

      HANA Table Creation
      button on the top-right corner to deploy the table.

      HANA Table Creation
    5. Similarly, you can create another table called sales by simply right-clicking the source folder and selecting the option new file.

      Enter the name sales.hdbtable.

      HANA Table Creation
    6. Add the following definition to the sales.hdbtable file.

      SQL
      Copy
      COLUMN TABLE "sales" ( sid integer, pid varchar(5), sdate date, samt integer, custid integer )
      
    7. Click

      HANA Table Creation
      button on the top-right corner to deploy the sales table.

    HANA Table Creation
  • Step 5
    1. Click the SAP HANA projects in explorer, then click the database explorer

      HANA Table Creation
      icon.

      HANA Table Creation

      This opens SAP HANA Database Explorer in a new window where you can see the details of the HDI container.

      HANA Table Creation
    2. Select the tables folder in the HDI Container to see the customers and sales tables that you created.

      HANA Table Creation
    3. Click the customers table. This shows the table definition.

      HANA Table Creation
    4. Click open data and then click

      HANA Table Creation
      to insert a few sample records into the table.

      HANA Table Creation
    5. Follow similar steps to insert a few sample records into the sales table.

      HANA Table Creation

    Now you can go back to the project in SAP Business Application Studio to create a CUBE calculation view.

  • Step 6
    1. Select the source folder in the project to create the calculation view and choose the artifact type as Calculation View.

      Then, specify for the name customerwisesales, and then click Create.

      HANA CV Creation
    2. Open the file customerwisesales.hdbcalculationview.

      HANA CV Creation
    3. Add a Join node into the canvas.

      HANA CV Creation
    4. Click the following icon:

      HANA CV Creation

      Search for customers and sales tables and add them to the join node.

      HANA CV Creation

      After adding both the tables, the join node looks like the following.

      HANA CV Creation
    5. Double-click the join node.

      HANA CV Creation
    6. Drag the CUSTID field of the customers table onto the CUSTID field of the sales table. This will add a join condition between the tables.

      HANA CV Creation
    7. Navigate to the mapping tab of the join node and map the fields from both customers and sales into output columns.

      HANA CV Creation
    8. Link the join node to the aggregation node by using the following button:

      HANA CV Creation

      It looks like this.

      HANA CV Creation
    9. Double-click the aggregation node. Move all the columns from the join node to the output columns.

      HANA CV Creation
    10. Double-click the semantics node in the calculation view. Select CUSTID and SID fields and mark them as attributes.

      HANA CV Creation
    11. Maintain all the other semantics as needed.

    12. Click the

      HANA Table Creation
      button to deploy the calculation view.

      HANA CV Creation
    13. Navigate to the database explorer. Select the HDI container and choose column view. This shows the calculation view.

      HANA CV Creation
    14. Select the calculation view and click Open Data. This presents the data from the calculation view.

      HANA CV Creation
    15. You can go to the Analysis tab to view the data in the form of graphs, charts and other elements.

      Here the country wise sales is shown in a donut chart.

      HANA CV Creation
  • Step 7

    The type of calculation view that we have created in this scenario is:

Back to top