Jan's Blog

4 Posts
Today, SAP HANA is one of the most compelling and innovative development platforms worldwide. It offers opportunities for various types of new applications which work on huge amounts of data and need very fast access to them. In this blog I focus on
  • data that originate in the Cloud or are best stored in the Cloud: therefore, HANA One (http://www.saphana.com/community/learn/cloud-info) in the Amazon Cloud, is the platform of choice
    • there are also other Cloud Service Providers running HANA One like Portugal Telecom or Korea Telecom and others, please search the Web for them
  • small smartphone apps that show the new opportunities in a very concise way and at the same time leverage all important aspects of the technology stack - I start with a tutorial on Android.
I try to use the leanest setup possible. Therefore, in the base scenario, I don't use HTML5, I just select data out of a simple table in HANA via the simplest possible SQL statement, but I do create a small HANA XS app because this is the way to connect to HANA directly via http/ https. There are some extension scenarios to show more technology to enrich your application, see at the bottom.
I did it on a Windows machine. But it should also run on other OS.

App idea

The example app I build further down is comparing some stock exchange data and their development over time. Therefore, I propose some fictive names for all the artifacts you will create.

Prerequisites and Installs

Before starting the app creation in 20 minutes we need to make sure to install the following components (this would exceed the 20 minutes...):

Create an Android App

Create an Adnroid Application:
  • Start your Eclipse version that you installed for Android development.
  • In the Package Explorer of the Java perspective right-click "New --> "Android Application Project".
  • Application Name "Android App on HANA base scenario"
  • keep all the other settings on New Adnroid Application Name screen as defaulted
  • Select any start icon you want on Configure Launcher Icon screen
  • Select a Blank Activity on the Create Activity screen
  • Use Activity name "ShowMarketPriceData" on the New Blank Activity screen
Give the application an Id:
  • In the the Package Explorer double click --> res --> layout --> activity_show_market_price_data.xml
  • Use the XML layout instead of the Graphical Layout tab (bottom) in the middle part and exchange the id-line in the <TextView ... /> part with this one:
    • android:id="@+id/MyTextResponse"
Allow access to the internet for the new app
  • In the Package Explorer double-click on AndroidManifest.xml
  • In the middle part of the screen, use the Permissions tab (bottom)
  • Add Uses Permission and assign name android.permission.INTERNET
Download additional library:
  • Download json-simple-1.1.1.jar for instance from http://code.google.com/p/json-simple/downloads/list
  • Put it into your lib directory, for instance C:\blabla\workspace_android\AndroidAppOnHANABaseScenario\libs\json-simple-1.1.1.jar
  • Right-click on Package Explorer double click --> libs and Refresh: it should show up
Add code to show some data (see also http://www.mkyong.com/android/android-gridview-example/):
  • In the the Package Explorer double click --> src --> com.example.androidapponhanabasescenario --> ShowMarketPriceData.java
  • Add imports at the top:
    • import android.widget.TextView;
    • import android.os.AsyncTask;
    • import android.util.Base64;
    • import java.net.URL;
    • import java.net.URLConnection;
    • import java.io.BufferedReader;
    • import java.io.InputStreamReader;
  • 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();
aTask.execute();
  • 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>{
                              @Override
                              protected String doInBackground(Void... arg0) {
                                   return getOdata();
                                }
                              @Override
                              protected void onPostExecute(String result) {
                                    TextView tv = (TextView) findViewById(R.id.MyTextResponse);
                                   tv.setText(result);
                                }
   }
Use overall Save, again select activity_show_market_price_data.xml and click Run as Android Application
Your Android or Android Emulator should bring up a screen that shows "You will get there!".
Congrats! For now, your done on the Android side!

Create a HANA XS app

Start your HANA Studio. Connect to your HANA (as described in the SCN link mentioned further up).
 
Create a new HANA workspace:
  • In the SAP HANA Development perspective in the SAP HANA Repositories window on the left, right-click and select "New repository workspace"
  • Select your HANA SYSTEM, put the name "CompareStockMarketData" and define the workspace root directory or leave it as defaulted
Create and share a project for SAP HANA XS:
  • In the SAP HANA Development perspective, in the Project Explorer on the left, right-click New --> Project and select SAP HANA Development --> XS Project, put name "androidapponhana",  click Finish
  • In Project Explorer, right-click androidapponhana --> Team --> Share Project... 
  • Select your SAP HANA System, select Workspace Name CompareStockMarketData, (leave Repository package empty for now) and click Finish
Add necessary minimum artifacts
  • Within project androidapponhana, Right-click --> JavaScript Resources --> androidapponhana and select New --> Other
    • In the upcoming Wizard select General --> File and click Next, put ".xsapp" as name and click Finish (it shall remain empty for our purposes)
  • Do the same thing again - let's call this proceeding XS artifact addition - and create file ".xsaccess"
    • In the Project Explorer double click on file .xsaccess and put the following content into it
{
"exposed"
: true,
"authentication"
: [ { "method" : "Basic" } ]
}
  • Perform XS artifact addition and create file "COMPARE_STOCK.hdbschema" and put the following content into it
schema_name="COMPARE_STOCK";
  • Perform XS artifact addition and create file "PRICE_HISTORY.hdbtable" and put 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"];
  • Perform XS artifact addition and create file "StockDataIF.xsodata" and put the following content into it
               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:
  • Go to SAP HANA Studio, for instance to the Quicklaunch perspective, in the Navigator view on the left open an SQL COnsole
  • Type and execute (make sure to put your user instead of the placeholder):
call _SYS_REPO.GRANT_SCHEMA_PRIVILEGE_ON_ACTIVATED_CONTENT('select', 'COMPARE_STOCK', '<your user>');
call _SYS_REPO.GRANT_SCHEMA_PRIVILEGE_ON_ACTIVATED_CONTENT('insert', 'COMPARE_STOCK', '<your user>');
  • Type and execute
    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);
Now open a browser and test (put IP address and port/HANA instance number of your HANA server instead of the placeholders):
Congrats! This was the HANA XS stuff. Let's go back to the Adnroid side.

Calling the XS app from the Android App

Enhance Android Java code to show your HANA XS data:
  • In the the Package Explorer double click --> src --> com.example.androidapponhanabasescenario --> ShowMarketPriceData.java
  • In public class ShowMarketPriceData replace the line "   // some more code is to come here" by:
          try {
                URL myhana = new URL(

                URLConnection hanacon;
               hanacon = myhana.openConnection();
               hanacon.setReadTimeout(1000);
               hanacon.setConnectTimeout(1000);

               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;
               in.close();
           } catch (Exception e) {
               e.printStackTrace();
               return "Error";
          }
  • Make sure to replace user (for instance SYSTEM) and <your pw> (for instance manager).
  • Save and test your Android app. It shall return a lot of JSON text on your screen starting with the string "You will get there!".
    Congrats! That's it.
    Don't be shocked - it should look like this,
    Android1.png
    but in my next Blog I will make it look a little bit nicer !

    Closing remarks and extension Scenarios

    Now, of course this is just a "Hellow World!" type of application. But it shows nicely what technology can be used.
    So far, I will leave it to the user to imagine a more appropriate way of putting user credentials. To reach a good security level for an App you should think of: SSL, do save user credentials on local device not at all or only encrypted (use OAUTH if you can) and save local data in a secure way.
    In the subsequent blogs on this topic I will make it look nicer and put more business sense to it. I decided to also create tutorials for some extension scenarios. These are very much built on top of the base scenario, but they make the app look more appealing and they show a lot more interesting technology.
    1. Android: Show HANA data in a gridview
    2. Android: Show HANA data as a graph
    3. Android: Use HTML5 to show data
    4. XS: Show data from a CalcView
    5. XS: Show data tweaked by SQLScript

    When we embarked on the SAP Social Sabbatical program for South Africa many people asked questions like “what kind of job will you do there?” and “what is it that they need from SAP?” or even “have you got the right skill set to help those guys?”. Not really sure of what the correct answer would be I still replied reassuringly that a professional development solution company had planned the whole project and we would eventually find out.

     

    Of course, the entire setup of the program was promising loads of new experiences, challenges and also fun. Firstly, the foreign culture in this emerging, somewhat exotic country with a mixture of Afrikaans and Black African as well as Indian heritage bathed us in cold and hot waters of fear and excitement. Secondly, those initial questions went straight into heart of what modern “real” adventures are made of. Would we be smart enough to defy the adverseness of this unusual business background? Because, in addition, we knew that we would be assigned to non-profit, small business organizations operating in survival mode which are not the standard type of SAP customers we normally deal with. And finally, we would be placed in a country where many people like to spend their vacation – with lots of opportunities for touristic sightseeing. All in all, a terrific mixture of what makes up a good closing of a year of change for many of us. So, it seemed OK to take on the job.

     

    I want to skip so many stories which are worth telling and already have been covered by other blogs – at least some of them.

     

    After having given the final presentation to the leadership of our organization today: What is the impact we made?

     

    This is one of the best questions to pose: Everybody we will meet in the next few weeks will expect us to give an answer to it, be it positive or negative. The organizations in our Pretoria project are eagerly interested in it. And finally, the SAP Corporate Social Responsibility (CSR) program as well as the SAP management want to see whether SAP’s investment bears good fruit.

    Eunice.jpg

     

    To give an answer to this question – presumably preliminary, but the best one I can give at the end of this assignment, but still before any of the recommendations is implemented – I must say: Measuring impact of a social, highly cause-driven, not profit-driven organization is a big task on its own. And it was part of our job to provide good measures for this. Those measures are coming down to numbers we all know very well: how many employments have been created, how many financially sustainable businesses have been founded, how many women entrepreneurs have got their opportunity? And then we added a whole set of other Key Performance Indicators which describe if a growing company is doing well or not, ranging from basic business training, financial viability, marketing effectiveness to organizational growth enablement. This type of discussion then is not so unknown to us...

    hate credit.png

     

    But the question on impact was not only about measures of the social enterprise itself but on the impact of our assignment. What was our impression how much our recommendations really help PEN-Tekanô, a business development program that specializes in developing enterprises specifically for the Bottom of the Pyramid (BOP) tier in the economy in the inner-city of Pretoria?

    Sediba House.jpg

     

    Firstly, our thorough discovery and analysis of their situation today was a good start. When simply presenting what we had learned from their business owners and PEN’s staff, we earned feedback like “we wouldn’t have been able to do such an assessment within 2 years’ time – this is excellent”.

     

    Secondly, not only the big topics, but also many small remarks, hints and ideas gave them a lot of food for thought and seemed to convince them.

     

    Thirdly, we knew that we had effectively communicated when managers in the meeting came across with “ah, now I understand what you are aiming at: what you propose is much more than what we are doing today, it’s like incubating a small grain until it gets mature for the free market and then let it go” – even before we had started talking about the big term “incubator model”. And then: “oh, I would like to be part of this” by a women who had not been involved in enterprise development before – that really blew me away: What a wonderful reaction to a proposal that all of us find challenging - and even hard for some of the stakeholders.

     

    The best reaction yet was still to come at the end, the statement given by the CEO: “We were somewhat frustrated with all the effort we invest and the little results we see. I already thought about shutting down the whole initiative. But you showed us: enterprise development is a difficult task and others aren’t doing better than we do either. And yes, we can get to the next level and it is worth it!”

     

    So far, we couldn’t have done a better job!

     

    Will they implement everything we have put on their table? No.
    Will they ultimately become profitable and take their business owners to the next level? Yes, definitely. Not all of them, but the ones who have got a real chance.
    Will PEN become an even more socially impactful enterprise in the center of Pretoria, serving the “underserved” people by following some of our lines of thought? Yes, I believe so.

     

    We are still waiting for some more well reflected feedback– after some time to think – and, of course, for some good results after having implemented this. But the ship has left its harbor – and it will not return empty.
    We know, we did a job that was worth it.

     

    Still being very much impressed by the work PEN is doing, now we are discussing a more personal but even more challenging question: Would we be willing to quit our jobs and take up a “calling” in one of our NGOs – may be not tomorrow, but in 10 years from now when kids are grown up?

    Enterprise Development is such a cool idea: By putting some money in, plus some help to setup a new business like office space, mentoring, marketing support etc. you can achieve goals like long-term sustainable jobs, more tax, inner cities that are worth living and so lifting the yoke of poverty of whole nations.
    Such was the motivation for  PEN – but on a smaller scale – to start the Tekanô (meaning “enough” in Northern Sotho) project in Sediba house in the middle of Pretoria, South Africa, some 8 years ago. They already owned a large block of flats which was used for social housing at subsidized rent. The profit coming out of this in turn is contributing to fund their even more charitable wellness and wholeness programs to serve the marginalized communities in the broader Tshwane area. So, they took 2 floors of that building, remodeled them and invited some 30 startups or struggling small businesses to rent cheap office space and get a whole package of close support from PEN.

     

    How are entrepreneurs residing in Sediba house doing? Is the concept working fine?

     

    Us, a small team from SAP is currently investigating some randomly chosen draw of 12 out of ~ 30. Surely, there are those success stories like self sufficiency - one entrepreneur at a time. These are the ones showing that it is worth trying. But how about the rest?

     

    When you dig into it you really find more jewels – although they are still fighting their day-to-day live. Here are 2 more:


    Sophie* is running her tailoring business for 8 years now. She employs 1 to 3 seamstresses depending on the demand and – from time to time - has difficulties in getting paid by government when she is producing school uniforms. We have learnt in between that this is a pretty common pattern if government contracts are in the game. Now, what is really special about Sophie is her will to improve: She is constantly taking entrepreneurship training classes at University – and she has motivated 3,365 !! other fellows to also participate in these trainings. Also, she regularly organizes sales shows for her and her colleagues’ products in tents on church street, Pretoria’s most touristic site. So, she is a real influencer and multiplier. How can you leverage such a potential even more?

     

    In contrast to this, Nancy's* business, just some doors further down the floor, has grown a little bit bigger: She has 8 employees, is using 4 sales channels – web, yellow pages, direct sales and word-of-mouth of course. After some bad experiences with outstanding bills she now has a strict rule she follows: 50% deposit when ordering, 50% payment in cash when garments are delivered – “When I am too soft I kill my business”. That already impresses. But still she has another simple yet effective conviction: “I hate credit”. She never takes loans. Combine that with hard work and you will be successful: the day we talked to her she turned 40.

     

    So far, we are still collecting material. But some inferences can already be seen: All businesses need help in marketing. Also book-keeping is a hurdle for many of them. And the basic principles to run a business need to be applied in all of the enterprises. The overall concept is at break-even for PEN. And yes, there are some steps to be taken to make the different businesses more profitable.

    All in all, enterprise development is not such an easy job to be done and some more innovative ideas are necessary to enhance the quality of life of these people. But: counting the 100+ jobs that have been created plus the making a living for their families, a good start has been made.

     

    * real names have been omitted due to confidentiality

    It all started off with Dr. Marinda van Niekerk DSCN3988klein.jpgand 4 other theology students who had the particular feeling of the necessity to start an urban ministry among the new, predominantly black population in CBD (Central Business District) of Pretoria, South Africa. That matched the dream of Frik Huysamen, then senior pastor of  Bosman Straat Groote Kerk – a downtown, formerly white Dutch Reformed Church – to build a new, faster moving organisation: PEN was founded as a non-denominational Christian-based Section 21 Company. It is a non-profit and qualified Public Benefit Organization, registered in 1992 working in close relation with local churches as well as other organisations (Governmental and NGO's).

    Today, PEN’s 145 staff members are serving some 55,000 meals a month in several primary and nursery schools, are currently housing 61 orphaned children in several managed houses, are performing 2,200 Health Care Treatments a year in Sediba Hope Clinic (335 individuals, 16% tested HIV positive). Furthermore they have been asked to look after all Dutch Reformed churches all over Pretoria – evidence of their accepted and growing role in the inner city of Tshwane.

    So, how can an understaffed NGO with so few resources have so much impact within 20 years since they started off, even when South African society has changed at the same time even more: surrounding population in their area has again exchanged itself to a large extent from South African blacks to neighboring African nationals? What type of leadership is it that can make many staff members rather do with less money and see much poorer people slowly recover than go for a better paid job and live a normal life?

    Marinda, CEO of PEN, says “Many of them are not here for making money. They are motivated, they love what they are doing. Leading a team like that is just awesome: instead of pushing the wheel barrow ahead it’s like running on a racehorse where you have a few leashes in your hand and the horse is just running“. When asked for her leadership style she answers: “Always why we do what we do is important to me: I strongly believe that people deserve a space where they can be acknowledged for who they are – and to me that’s the space that I experience in my relationship with God. That is what PEN should be about.”

    She smiles at you and you know that such a motivation makes the difference. It drives Marinda and all of these people to serve the ‘underserved’ people whom you meet when you step out of PEN into Bosman Street.

     

     

    For an introduction of what a small SAP team is doing here, read this blog.