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
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
Hadoop App
Stay Connected
Search Topics
Topic Index
XSA Overview
XS Overview
Hello World Example
XS OData Service
Core Data Service

XSJS Libraries


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.


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


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.status = $.net.http.OK; 

  1. Run XSJS service and pass the parameter as


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

3 thoughts on “SAP HANA XSJS Libraries – xsjslib

  1. Anne says:

    I get error-
    500 – Internal server error

    An error occurred during the processing of your request.
    Data might be lost.

    Possible solution

    Please contact your system administrator.

    • CK says:

      One possible case might be:-
      The $.import statement not able to recognize the xsjslib file location. Therefore, please specify the correct path of your xsjslib.

      $.import(“xsjslibtutorial”, “greetLib”);
      In the above statement, you have to replace “xsjslibtutorial” with –> “<>.<>”

Leave a Reply

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

Current day month ye@r *

 © 2017 :, All rights reserved.  Privacy Policy