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

XSJS Libraries

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.
We also explained the how to create XSJS and examples in the articles SAP HANA XSJS Service and SAP HANA XSJS Examples.

In this example we will learn XSJS libraries (xsjslib).

HANA XSJS Libraries:

Server-side JavaScript libraries (xsjslib) are a special type of JavaScript program that can be imported and called in other JavaScript programs.
We can create our own libraries by creating a XSJS library file called xsjslib.

Example:

In this example we will create a method in library file (.xsjslib) to add greeting prefix and call this method from another XSJS file.

Prerequisites:



Steps to create complete application:

  1. Create a XS project as mentioned in the article Create Your First HANA XS Application using HANA Studio
  2. Right click and select New à Others à XS JavaScript Library File. Specify file name as “GreetLib.xsjslib”.
  3. Copy paste below code.

var greetingPrefix = "Hello, ";
var greetingSuffix = "!";
function greet (name) {
        return greetingPrefix + name + greetingSuffix;
}
  1. Create an XSJS file and copy paste below code. Change the package name as your package name.

// import the library 
$.import("xsjslibtutorial", "greetLib");
var GREETLIB = $.xsjslibtutorial.greetLib;
  
var name = $.request.parameters.get("name");
var output = GREETLIB.greet(name);

$.response.setBody(output); 
$.response.status = $.net.http.OK; 

  1. Run XSJS service and pass the parameter as

http://<XS_Webserver>:80<SAPHANA_InstanceNr>/testApp/GetStockValue.xsjs?name=Thomas

SAP HANA XS Library xsjslib
       

Download Full Source Code:

Click here to download the full source code.


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