Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Target Audience: Beginner

Why I'm posting this simple example?

============================

I'm from different programming background, just started to catch up with HANA development. I was following examples from official hana_dev_en.pdf (google it to download).

Actually logic of code piece given on page 78 is similar to the one I extracted from SAP documentation.

I could understand that Newbies usually fed up when they couldn't get the output when they follow the examples from book.

Prerequisite

=========

1. should should have added new system(database), setup new work space and created project if not follow this simplified guidance (http://www.saphana.com/docs/DOC-3017)

2. Follow the tutorial from hana_dev_en.pdf , you should have other files already in your project (.xsaccess , .xsapp)

Note: don't confuse yourself about DUMMY table. it is actually a public synonym accessible for all users regardless of whatever  SCHEMA you are currently using

Lets start

clear  content of your  MyFirstSourceFile.xsjs file and paste the following code (clearly documented for better understanding)

// execute query
var conn = $.db.getConnection();
var pstmt = conn.prepareStatement( "select * from DUMMY" );
var rs = pstmt.executeQuery();
// writing result set to response body
$.response.contentType = "text/plain";
if (!rs.next()) {
    $.response.setBody( "Failed to retreive data" );
    $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
} else {
    $.response.setBody("Response: " + rs.getString(1));
}
// cleanup
rs.close();
pstmt.close();
conn.close();

Commit your file

Activate it

and Run it on your browser

Labels in this area