Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
YVL
Advisor
Advisor
8,602

Utilizing the most recent HANA XS engine web server ability, the mobile device can directly communicate to HANA appliance via HTTP protocol.  This simplifies the system architecture and extends HANA to all kinds of possibilities.

HTTP body in JSON format in WRITE API

ROOT {

  "name1" : "value1",

  "arrayname1": [ "arrayvalue11", "arrayvalue12" ],

  "name2" : "value2"

  "arrayname2" : [ "arrayvalue21", "arrayvalue22" ]

}

Parsing JSON in HANA:

var body = $.request.body.asString();

var obj = JSON.parse(body);

var name1 = obj.name1;

var name2 = obj.name2;

var arrayname1 = obj.arrayname1;

var arrayname2 = obj.arrayname2;

var i = 0

for (i; i< arrayname1.length; i++){

//write to HANA

}

HTTP body in JSON format in READ API:

{"entry":[

                    [    

                            ["name11","value11"],

                             ["name21", "value21"]

                    ],

                    [

                              ["name12","value12"],

                              ["name22","value21"]

                    ]

               ]

}

Constructing JSON in HANA:

var root = {

               entry: []

}

//rs is the return of table data

while (rs.next()){

     var jsonObj = [];

     var i = 1;

     for (i; i< columncount+1; i++){

          var record = [];

          record.push(columnlabel, rs.getString(i));

          jsonObj.push(record);

     }

     root.entry.push(jsonObj);

}

The JSON constructed from HANA this way is valid; however, it seems not necessarily represent the object array concept well.  Hope to see alternative approach.

These JSON format http body are either constructed in iPhone or consumed in iPhone for display.

6 Comments