SapHanaTutorial.Com HOME     Learning-Materials Interview-Q&A Certifications Quiz Online-Courses Forum Jobs Trendz FAQs  
     Explore The World of Hana With Us     
About Us
Contact Us
 Apps
X
HANA App
>>>
Hadoop App
>>>
Tutorial App on SAP HANA
This app is an All-In-One package to provide everything to HANA Lovers.

It contains
1. Courses on SAP HANA - Basics, Modeling and Administration
2. Multiple Quizzes on Overview, Modelling, Architeture, and Administration
3. Most popular articles on SAP HANA
4. Series of Interview questions to brushup your HANA skills
Tutorial App on Hadoop
This app is an All-In-One package to provide everything to Hadoop Lovers.

It contains
1. Courses on Hadoop - Basics and Advanced
2. Multiple Quizzes on Basics, MapReduce and HDFS
3. Most popular articles on Hadoop
4. Series of Interview questions to brushup your skills
Apps
HANA App
Hadoop App
';
Search
Stay Connected
Search Topics
Topic Index
+
-
XSA Overview
+
-
XS Overview
+
-
Hello World Example
+
-
XS OData Service
+
-
HANA XSJS Service
+
-
Core Data Service
+
-
Others

Introduction to XSJS Service

Introduction:

In the article Introduction to SAP HANA XS, we explained that SAP HANA XS can be used to expose data from Tables, Views and Modeling Views to UI layer.
In HANA XS, there are major 2 ways to expose data the data to clients – OData and XSJS.
In this article we will explain:
  • What is XSJS services in HANA?
  • How to create XSJS service with examples.

Note: For OData, read the article SAP HANA OData Service

What is SAP HANA XS JavaScript (XSJS)?

SAP HANA XS JavaScript (XSJS) is an application programming language in JavaScript. It can be used to exposes data stored in database tables or views to client side. Additionally we can also implement any business logic.

Unlike XSODATA, XSJS is a free flow approach where we can write our own logic using JavaScript.

Below is an example of XSJS service:

SAP HANA XSJS Service

Create Hello World XSJS Service:

Let us create a simple XSJS service to understand the concept better.
We have also provided a list of XSJS examples for you. To know more about that, read the article SAP HANA XSJS Examples
Now let us see how to create an XSJS service.


Prerequisites:


Note: In this example we will use HANA Studio to create XSJS Service. You can also create it using HANA Web-based tools. For HANA Web-based tool, you should first read Create Your First HANA XS Application using HANA Web-Based Tool

Steps to create XSJS Service:

  1. Create a XS project as mentioned in the article Create Your First HANA XS Application using HANA Studio
  2. Right click on the project and select New à XS JavaScript File. Specify the name “HelloWorld” and click on Finish.

SAP HANA XSJS Service

  1. Copy and paste the below code.

$.response.contentType = "text/html";
var output = "Hello, " + $.session.getUsername() + " <br><br>";

var conn = $.db.getConnection();
var pstmt = conn.prepareStatement( "SELECT CURRENT_USER FROM DUMMY" );
var rs = pstmt.executeQuery();

if (!rs.next()) {
                $.response.setBody( "Failed to retrieve data" );
                $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
}
else {
                output = output + "The current user is: " + rs.getString(1);
}
rs.close();
pstmt.close();
conn.close();
$.response.setBody(output);
Click here to download the source code.
  1. Right click and select Team à Activate. This will activate the file.

SAP HANA XSJS Service

  1. Right click and select Run As à XS Service. This will open the XSJS service in default browser.
  2. Enter user id and password of HANA system. You will see the result as
SAP HANA XSJS Service

Done!! You have successfully created your first XSJS service.

Continue reading:




Support us by sharing this article.



Explore More
Close X
Close X

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *

 © 2017 : saphanatutorial.com, All rights reserved.  Privacy Policy