How to build a basic solution with SAP HANA – part 2 – “Flow Controller”

In the first part of the tutorial we had created a basic data structure for Flights with 3 tables and some rows in each. This second part is named “Flow Controller” and includes the creation of SAP HANA views and an OData service to publish the information of the tables as a service.

All the components have been implemented with low complexity but with powerful scope. The idea is to share with you an easy but complete solution, and prepare you for more complex scenarios in the future.

Prerequisites

The first part of this tutorial is the views creation. There are several views types in SAP HANA (Attributes, Analytics, Calculation), and their use depend of the requirement.

Step-by-Step

Connect to your HANA system as was explained in the first part of the tutorial. In Systems view, open the Content folder, right click / New and create a new Package.

01


You can use the name that you prefer for the package. Is recommended the same name as your schema. Write a name and a description (optional), and press OK.

02


Right click on your package and create a new attribute view for each table created before (T_SBOOK, T_SFLIGHT and T_SPFLI).

03


Is recommended to use a prefix for the view name (e.g. ATV = attribute view, ANV = analytical view, CAV = calculated view). Fill the fields as is showed in the image and press Finish.

04


In the view editor: 05

  1. Press the add object button.
  2. Type the table name.
  3. Select the table that exist in your schema and press OK.

06

  1. Click in the Data Foundation
  2. In the Detail section you can see the table selected. Select all the fields as Output, clicking on each circle beside the field name.
  3. Check the columns added in Output.

07

  1. Click in Semantics
  2. In Details section select the Key fields (T_SPFLI: CARRID, CONNID. T_SFLIGHT: CARRID, CONNID, FLDATE. T_SBOOK: CARRID, CONNID, FLDATE, BOOKID).
  3. Click on Save and Activate.

Now you need to create a Calculation View. On your package Right click / New / Calculation View.

08


Fill the fields as in the image shown and press Finish.

09


10

  1. Select a Join object, drag and drop in the
  2. Click on Add Objects
  3. Type the attribute view name (ATV_SFLIGHT).
  4. Select the view created in your schema and press OK.

Repeat the steps 2, 3 & 4, for ATV_SBOOK.

 


11

  1. Select Join_1
  2. Select all the fields of ATV_SFLIGHT as Output, clicking on each circle beside the field name.
  3. Join both tables doing drag and drop. Select the fields of ATV_SBOOK as Output, clicking on each circle beside the field name (CARRID, CONNID, FLDAT are not required).
  4. In Properties the Join Type is Inner and the Cardinality is 1..n.

12

  1. Add another Join
  2. Click on Add Objects
  3. Type the attribute view name (ATV_SPFLI).
  4. Select the view created in your schema and press OK.

13

  1. Connect Join_1 with Join_2.
  2. Select Join_2
  3. Join both tables doing drag and drop.
  4. Select all the fields of Join_1 as
  5. Select the fields of ATV_SPFLI as Output, (CARRID, CONNID are not required).
  6. In Properties the Join Type is Inner and the Cardinality is 1..n.
  7. Connect Join_2 with Agregation block.

  1. Select Aggregation
  2. Select all the fields as output. Right click on table header.
  3. Click on Add all to Output option.

14


  1. Select the Semantics
  2. Select Key fields as the image shown.
  3. For each field is needed select a Type. Only PRICE and PAYMENTSUM are Measure, the others are Attribute.
  4. Press Save and Activate.
  5. Press Data Preview.15

16

  1. Add attributes as Label axis.
  2. Add measures (PRICE and PAYMENTSUM), as Values axis.
  3. Check the result as graphic.
  4. You can change the graphic type.
  5. You can see the result as Raw Data.

Finally your package should look like this.

17



 

The second part is the ODATA service creation.

In your eclipse IDE:

  1. Press Open Perspective.
  2. Select SAP HANA Development
  3. Select the Project Explorer view

18


On Project Explorer view, Right click / New / Other.

19


Select SAP HANA / Application Development / XS Project and press Next.

20


Check the Share project in SAP repository. You can type the name that you prefer. Press Next.

21


  1. Press Add Workspace
  2. Select the SAP HANA System and press Finish.
  3. Press Next.

22


Check XS Application Access and XS Application Descriptor option. Press Finish.

23


If you see the error Unsupported encoding CP1252…Right click in the error (on Problems view). Select Quick Fix.

24


Select All and press Finish.

25


We need to Activate our project when it is created and when files are created or modified, because this process delivers our changes in the server. Right click in the Project Folder / Team / Activate.

26


Open .xsaccess file. We only need the sentence “exposed” : true

27


Create a folder. Right click in the Project Folder / New / Folder.

28


Select your project and type services as name. Press Finish.

29


In services folder create a new odata file. Right click / New / XS OData File.

30


Type a name for your odata service file and press Finish.

31


In your service file you need to declare your calculation view as odata services (SCHEMA::CAL_VIEW), and type an alias name (whatever you like), the key generated local sentence (create an automatic key),and Save. Remember Activate your changes.

32


Now is time to publish the OData service. Right click on xsodata service file / Run As/ XS Service.

33


A new Web Browser is opened automatically. Type your SAP HANA MDC Data base user and password. Maybe you will need to refresh the windows after the login.

34


The service is running. The atom:title is the alias that you selected for the service.

35


To validate the service structure we can see the meta data adding /$metadata at the end of the URL. Please check the data types, the key that was defined in the xsodata file.

36


To see the data using xml format we can add /FlightService/?$format=xml at the end of the URL. Please check that the values are as were inserted in the tables.

37


To see the data using json format we can add /FlightService/?$format=json at the end of the URL. Please check that the values are as were inserted in the tables.

38



39The second part have finished… See you soon!!!

 

 

spanish-version

Advertisements

One thought on “How to build a basic solution with SAP HANA – part 2 – “Flow Controller”

  1. Pingback: How to build a basic solution with SAP HANA – part 3 – “Visualization & Beyond” | Innovators at Heart

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s