Part 2 of 10, Setup and configure your initial SAP HANA XS application for use with your IoT Data

Details

You are now going to build a simple and quick SAP HANA XS application, if you already have experience doing this feel free to jump ahead as you feel fit.

SAP HANA XS are extended services applications based on JavaScript, HTML and CSS, as you well as several built in features such as OData within the SAP HANA environment.

Step 1: Log into server

Login to the server provided during this event or to your own SAP HANA server and go to the SAP HANA Web Based Development Workbench

http://xx.xx.xx.xx/sap/hana/xs/ide/editor

Your login is: user name CODEJAMMER and CodeJam2015 (or whichever username and password you have been given to login with)

Step 2: Create new package

Once you have your editor loaded you will need to create a package name under the CODEJAMMER package with your name. This is done by right clicking on the CODEJAMMER package and choosing New > Package and then entering your name. If the CODEJAMMER package does not exist then simply create a new package under the root package which is simply the “Content” folder.

Step 3: Create another new package

Then under your new package you will want to create another new package called myiot. This will be the package that you place all of our XS code under for our application.

Step 4: Create application

Now you will need to right-click on your myiot package and choose Create Application.

Step 5: Accept defaults

Accept the default values, and an empty application with the basic .xsapp and .xsaccess files you need will be created.

Step 6: Add data objects

Now that you have the basic application you will add in some data objects so you can store data from your devices. The first object you need will be a schema file. Select your myiot package, right-click and choose New > File. Use something simple like your name (in all caps) for the first part of the file name. In this example, JOHNDOE was used.

Name the file: YOURNAME.hdbschema

Be sure to use all capital letters for the schema filename

Step 7: Add content

Enter the following content into your .hdbschema file, replacing JOHNDOE with your name.

Ensure you use all capital letters for the schema name

schema_name="JOHNDOE";

Step 8: Create table definition file

The the next file you need to create is a table definition file. Right-click on your myiot package, select New > File and name the file mydata.hdbdd. This file will define the table and data types that you will use to store the data as well as access it later.

Step 9: Add content

Enter the following content in your mydata.hdbdd file, and replace instances of johndoe and JOHNDOE with the name you used.

Once table definition file is saved it will activate and create your table. You will now need to create a stored procedure and an OData service file. The OData service file will allow you to access any data and set the connection to the stored procedure for enabling the insertion of new data into the table.

Step 11: Create a sequence

To create a sequence (an incrementing number for the ID field in your table), right-click on your myiot package, select New > File and name the file johndoe_id_seq.hdbsequence.

You will notice the use of the “name” in these examples it is “JOHNDOE” so be sure to make the appropriate changes.

Step 12: Add content

Enter the following content in your .hdbsequence file, and replace instances of johndoe and JOHNDOE with the name you used.

Now that you have your table and incrementing ID field you need to create the stored procedure that will insert new data into the table. Follow the same procedure as above to add new file to your myiot package and name it: newdata.hdbprocedure

Step 14: Enter content

Enter the following content in your .hdbprocedure file, and replace instances of johndoe and JOHNDOE with the name you used.

Your service enabled table is almost ready for use. You also need to give some authorizations and to do this you will create a “ROLE”. Right-click on your myiot package and select New > Role. Enter johndoe_myiot for the role name (modify the name accordingly) and click Create.

Step 18: Add your name

Once created, click on Object Privileges, then the + sign. Enter your name (**JOHNDOE** used here) and a schema and sequence Object Type should appear in the Matching Items list.

Step 19: Add the role

Select the schema item then click OK to add it to the role.

Step 20: Select all privileges

Once the schema is added, select all the checkboxes under Privileges (on the right hand side).

You will need to add your schema, table, sequence and procedure to this and then save.

Step 22: Apply role to user

Now that you have a role defined you need to apply that role to your user. Be sure to SAVE the role before continuing! To apply the role to your user, click the small link icon in the editor and choose Security. When the page updates, unroll the Users hierarchy, and select CODEJAMMER (or which ever user you were given for this server).

Step 23: Select your role

Click the + symbol under the Granted Roles tab and search for the role you created (e.g. johndoe). Select your role, click OK and Save.￼