28.01.2013 Views

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9.3.2 Writing Server-Side JavaScript Libraries<br />

Server-side JavaScript libraries are a special type of JavaScript program that can be imported and called in other<br />

JavaScript programs. You can use JavaScript libraries to perform simple, repetitive tasks, for example, to handle<br />

forms and form date, to manipulate date and time strings, to parse URLs, and so on.<br />

JavaScript libraries are internally developed extensions for <strong>SAP</strong> <strong>HANA</strong>. However, you can write your own libraries,<br />

too. JavaScript libraries exist in the context of a package, which is referenced when you import the library. To<br />

write a JavaScript library to use in your server-side JavaScript application, perform the following steps:<br />

1. Create the file that contains the JavaScript library you want to add to the package and make available for<br />

import.<br />

In <strong>SAP</strong> <strong>HANA</strong> XS, server-side JavaScript libraries have the file extension .xsjslib, for example<br />

greetLib.xsjslib.<br />

The following example creates a simple library that displays the word “Hello” along with a supplied name and<br />

adds an exclamation point (!) as a suffix.<br />

var greetingPrefix = "Hello, ";<br />

var greetingSuffix = "!";<br />

function greet (name) {<br />

return greetingPrefix + name + greetingSuffix;<br />

}<br />

2. Save the new JavaScript library.<br />

It is important to remember where the JavaScript library is located; you have to reference the package path<br />

when you import the library.<br />

3. Activate your new library in the repository so that it is available for import by other JavaScript applications.<br />

9.3.3 Importing Server-Side JavaScript Libraries<br />

Server-side JavaScript libraries are a special type of JavaScript program that can be imported and called in other<br />

JavaScript programs. You can use JavaScript libraries to perform simple, repetitive tasks, for example: handle<br />

forms and form date, manipulate date and time strings, parse URLs, and so on.<br />

JavaScript libraries are internally developed extensions for <strong>SAP</strong> <strong>HANA</strong>. The libraries exist in the context of a<br />

package, which is referenced when you import the library. The following example of a JavaScript library displays<br />

the word "Hello" along with a name and an exclamation mark as a suffix.<br />

var greetingPrefix = "Hello, ";<br />

var greetingSuffix = "!";<br />

function greet (name) {<br />

return greetingPrefix + name + greetingSuffix;<br />

}<br />

Note: This procedure uses the illustrated example JavaScript library to explain what happens when you<br />

import a JavaScript library, for example, which objects are created, when, and where. If you have your own<br />

library to import, substitute the library names and paths shown in the steps below as required.<br />

To import a JavaScript library for use in your server-side JavaScript application, perform the following tasks<br />

1. Import the JavaScript library into a JavaScript application.<br />

220<br />

Open the server-side JavaScript file into which you want to import the JavaScript library.<br />

P U B L I C<br />

© 2012 <strong>SAP</strong> AG. All rights reserved.<br />

<strong>SAP</strong> <strong>HANA</strong> <strong>Developer</strong> <strong>Guide</strong><br />

Writing Server-Side JavaScript Applications

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!