Online Tutorials & Training Materials |
Register Login

Create Android App on SAP HANA One

|| || 0

Create Android App on SAP HANA One

SAP HANA stands for High-Performance Analytic Appliance.

SAP HANA is a technique that is used to store data that contains a heavy amount of data with extraordinary performance. Data is stored in row-wise in many of the databases. If you want to increase the speed while accessing a data in every single table row you can reorganize the data in column-wise.It is a flexible, data source agnostic appliance that allows users to analyze a huge amount of SAP data.It is actually a hardware and software combination that is used to combine a no. of SAP components. It basically provides an optimized appliance in conjunction.

You can create an ANDROID APP from a simple table in HANA for fetching data via the simplest possible SQL statement. For creation, you have to connect HANA directly using http/https .You will use the following steps for the creation of android app:-

  1. Install Eclipse version for Android and start it.
  2. Go to package Explorer of and click right then click on NEW and then click on Android Application project
  3. You will find the  Application Name (Android App on HANA base scenario)
  4. All the other settings must be set Default on New Application Name Screen
  5. You have to click on start icon to be configured with launcher icon screen
  6. You will find Create Activity Screen and select Blank Activity.
  7. You have to Select “ShowMarketPriceData” which is a Activity Name by default
  8. You have to provide  Id to Application
  9. Go to Package Explorer and click two times ,Than you will have to click on

Res -> layout->activity_show_market_price_data.xml

  1. Use the XML layout
  2. You have to allow the access to the internet for new app
  3. Go to Package Explorer click two times Androidmanifest.xml
  4. Use the permission tab
  5. Assign name android. Permission Internet to add uses permission

Download Additional Library:

  • In the the Package Explorer double click --> src --> com.example.androidapponhanabasescenario -->
  • Add imports at the top:
    • import android.widget.TextView;
    • import android.os.AsyncTask;
    • import android.util.Base64;
    • import;
    • import;
    • import;
    • import;
  • In public class ShowMarketPriceData add the following code:
  • In method onCreate, just below setContentView(R.layout.activity_show_market_price_data);

ShowDialogAsyncTask aTask = new ShowDialogAsyncTask();


  • Also add this method and private class:
public String getOdata() {

     String JASONrs = "You will get there!";

                              // some more code is to come here

                              return JASONrs;


                          private class ShowDialogAsyncTask extends        AsyncTask<Void , Void , String>{


                              protected String doInBackground(Void... arg0) {

                                   return getOdata();



                              protected void onPostExecute(String result) {

                                    TextView tv = (TextView) findViewById(;




A) Create a HANA XS app

B) Create a new HANA workspace:

1) You have to select New Repository Workspace

2) You have to select HANA system. While using this you have to define workspace root directory with the name "CompareStockMarketData"

3) Now you have to click on New -> project and select SAP HANA development -> XS Project Give name "androidapponhana", and than finish.

4) Now click on androidpponhana to shar project

5) Than select SAP HANA system

6) Select Workspace name CompareStockMarketData and Than finish

7) Click on androidpponhana to select New -> Other

8) Now select Geneneral -> File And Click Next and then enter “.xsapp”

9) Now create file “.xsaccess

10) Now you have to put following content to “.xsaccess”


: true,

: [ { "method" : "Basic" } ]


11) Create file "COMPARE_STOCK.hdbschema" and  Create file "PRICE_HISTORY.hdbtable" and submit  the following content into it

table.schemaName = "COMPARE_STOCK";

table.tableType = COLUMNSTORE;

table.columns = [

{name = "NSIN"; sqlType = SHORTTEXT; nullable = false; length = 12;  },

{name = "DATE"; sqlType = DATE; nullable = false; },

{name = "TIME"; sqlType = TIME; nullable = false; },

{name = "DAY_OPEN"; sqlType = DECIMAL; nullable = false; precision = 8; scale = 3;},

{name = "DAY_HIGH"; sqlType = DECIMAL; nullable = false; precision = 8; scale = 3;},

{name = "DAY_LOW"; sqlType = DECIMAL; nullable = false; precision = 8; scale = 3;},

{name = "DAY_CLOSE"; sqlType = DECIMAL; nullable = false; precision = 8; scale = 3;},

{name = "VOLUME"; sqlType = INTEGER; nullable = false; }


table.primaryKey.pkcolumns = ["NSIN", "DATE", "TIME"];

12) Now again create file "StockDataIF.xsodata" and submit this content             

  service {

                    "androidapponhana::PRICE_HISTORY" as "History" ;


Click the overall Save button.

In Project Explorer, right-click androidapponhana --> Team --> Commit.

In Project Explorer, right-click androidapponhana --> Team --> Activate.

Now, grant privileges to your user and put some test data in:

13 )Now you have to Search SAPHANA Studio ,you have to open SQL console using the navigator view on the left side

14) Type and execute to call data



Type and execute for submitting data
insert into "COMPARE_STOCK"."androidapponhana::PRICE_HISTORY" ( NSIN, DATE, TIME, DAY_OPEN, DAY_HIGH, DAY_LOW, DAY_CLOSE, VOLUME ) values ('000716460', '20130205','130000', 60.19, 60.55, 59.91, 60.2, 2313291);

15) X ML File will be created that will contain the data you inserted into the table

You should see a longer XML file containing the data you inserted into the table.

Now you have to call xs app from the android app

C) Call the XS App for the Android App

D) Execute Android Java code to show HANA XS data:

1) Go to the Package Explorer click two times you will get src-> com.example.androidapponhanabasescenario -->

2) In public class ShowMarketPriceData replace the line “You will get the new code" by:    

      try {

                URL myhana = new URL(
                URLConnection hanacon;

               hanacon = myhana.openConnection();



               String userpass = "SYSTEM" + ":" + "<your pw>";

               String basicAuth = "Basic " + new String(Base64.encode(userpass.getBytes(), 0));

               hanacon.setRequestProperty ("Authorization", basicAuth);

               BufferedReader in = new BufferedReader(new InputStreamReader(hanacon.getInputStream()));

               String inputLine;

               while ((inputLine = in.readLine()) != null) JASONrs += inputLine;


           } catch (Exception e) {


               return "Error";


3) replace the user and password for instance system and manager

4) Now you can test and save your android app. And enjoy your android app as you want.



Related Articles