cancel
Showing results for 
Search instead for 
Did you mean: 

Mobile Apps to HANA

Chandan_EA
Advisor
Advisor
0 Kudos

Hi Gurus,

  I researched a lot about the connectivity options between a mobile app and HANA, but all I get is about retrieving data from HANA and sending it back to a mobile device/app.

Is there a way of sending data to HANA from a Mobile App ?

Currently, I am aware of one way but I do not see any documents of implementing it:

--> Doing a Http post in an android api and consuming that in XS engine and then passing it to HANA.

If anybody could provide any documents on the above way, I would be more than happy.

Also, do you see any better ways of achieving this ?

Best Regards,

Chandan

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

HI

can any one tell how we can pass value from .js file to .xsjs .??

I need to set data according to the Id which i will be getting on clicked in xs file ..

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Please do no post new questions to existing threads.  Start your own new thread.

.js files execute on the client side in the browser.  XSJS executes on the server side and is exposed via HTTP to the client.  Therefore from .js on the client side you need to call this service (usually via AJAX).

Former Member
0 Kudos

Hi Chandan,

Documentation around XS is a little limited at the moment, and more should come out with the release of SPS05. With regards to your question, it is possible to call a Stored Procedure from XS and pass values into the Stored Procedure. You could create a Stored Procedure that would then insert, or update values in SAP HANA. Let me know if you need more details and I'll check with one of my colleagues who have done this.

Regards,

Gary Elliott

Former Member
0 Kudos

Hi,

It is supported only on developer editions as I know.

Chandan_EA
Advisor
Advisor
0 Kudos

Hi Gary,

First of all - Thanks
If you can provide some info on the details, it would be great.

But how does the connection happen between an App and a stored procedure on XS ?

Best Regards,

Chandan

Chandan_EA
Advisor
Advisor
0 Kudos

Hi Erhan,

I have the CoE/sandbox HANA servers, I am assuming those are the developer editions one.

Former Member
0 Kudos

Hi Chandran,

The stored procedure is called through a JS Server Script within XS. I'm not sure how this is called from an App, as I'm a HANA guy, not an App guy. I suggest that you hold out for SPS05 as I'm led to believe that there will be documentation on XS released as part of this release.

Cheers,

Gary

Former Member
0 Kudos

Hi,

XSEngine doee not have this capability now. You can not insert data uaing it. You can use miidlewares for example SUP. Or you can code for it. Using Jdbc you can connect HANA.

henrique_pinto
Active Contributor
0 Kudos

Actually, creating a .xsjs file that receives input parameters as URL parameters and embedding a INSERT statement in it is fairly achievable.

Then you could just consume this .xsjs in any part of your HTML or any javascript function.

Chandan_EA
Advisor
Advisor
0 Kudos

Hi Henrique,

Are you talking about the Http post from the API class in Eclipse?
My challenge is to read that data in HANA

Best Regards,

Chandan

Chandan_EA
Advisor
Advisor
0 Kudos

Hi Erhan,

That's a cool post from you

But then what I am looking is sending data to HANA, all I understand from your post is that it tells us how to get data from HANA.

So would love to see if you have something for sending data to HANA

Best Regards,

Chandan

Former Member
0 Kudos

As I said before it is not official yet. I only read it from TechEd Session. And may be this might be not supported on your server. And I think right approache is using a middleware for this. Check SAP NW Gateway. You can read data from HANA too. But you can write custom code for inserting data.

http://scn.sap.com/community/netweaver-gateway/blog/2012/07/24/get-your-hana-data-from-everywhere-wi...

henrique_pinto
Active Contributor
0 Kudos

Not really.

I was talking about creating a .xsjs file in HANA (it stands for server side JavaScript) with something like this:

insert.xsjs

var id = $.request.getParameter("id");

if (id === null) {

    $.response.setContentType("text/plain");

    $.response.addBody("id is null!");

}

var val1 = $.request.getParameter("val1");

if (val1 === null) {

    $.response.setContentType("text/plain");

    $.response.addBody("val1 is null!");

}

var output = {};

output.data = [];

var conn = $.db.getConnection();

conn.prepareStatement("SET SCHEMA \"TEST\"").execute();

conn.prepareStatement("INSERT INTO \"TABLE1\" values('" + id + "', '" + val1 + "')").execute();

conn.commit();

var record = [];

record.push(id);

record.push(val1);   

output.data.push(record);

conn.close();

$.response.setContentType("text/json");

$.response.addBody(JSON.stringify(output));

And then, in order to call it, just do a HTTP GET to the URL pointing to your .xsjs file, passing the URL parameters.

In order to test it, you can just access the URL in the browser directly.

If everything goes ok, you should see the inserted record sent back as the response to the HTTP GET command (in JSON format).

Anything else should be interpreted as an error.

For example, calling http://<host>:<port>/test/logic/insert.xsjs?id=1&val1=10.5 in your browser, will get you this record being inserted in the TABLE1 table:

And this is the output you should see in your browser:

Best regards,

Henrique.

PS: in my case, TABLE1 had "ID" as a primary key. Hence, if I just call the same URL again, it will try to insert another record with the same key, and hence it will fail. But since I didn't handle the exception in my code, it will throw a HTTP 500 error. If you want to avoid that, you'll need to do some exception handling in your .xsjs file.

PS2: in order to properly test your .xsjs file, you'll need to define a XS application for the package that contains it.

Just make sure to create a .xsapp file like below in the root folder of that package in order to tell HANA that this is an existing XS Application, or else trying to call that URL above will just throw a HTTP 404 error.

test.xsapp

{

          "auth_required": true

}