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.

Server-side JavaScript files have the file suffix .xsjs, for example, hello.xsjs and contain the code that is<br />

executed when <strong>SAP</strong> <strong>HANA</strong> XS handles a URL request.<br />

$.response.contentType = "text/plain";<br />

$.response.setBody( "Hello, World!");<br />

6. Check the layout workspace.<br />

Your application package structure should have a structure that looks like the following example:<br />

.<br />

\<br />

helloxsjs<br />

\.xsapp<br />

.xsaccess<br />

hello.xsjs<br />

7. Save and activate your changes and additions.<br />

8. View the results.<br />

The <strong>SAP</strong> <strong>HANA</strong> XS Web server enables you to view the results immediately after activation in the repository,<br />

for example: http://dbhost:80/helloxsjs/hello.xsjs<br />

9.3 Writing JavaScript Libraries<br />

9.3.1 Server-Side JavaScript Libraries<br />

The elements defined in normal server-side JavaScript programs cannot be accessed from other JavaScript<br />

programs. To enable the reuse of program elements, <strong>SAP</strong> <strong>HANA</strong> Extended Application Services support serverside<br />

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 />

Note: JavaScript libraries are internally developed extensions for <strong>SAP</strong> <strong>HANA</strong>.<br />

The following example shows how to import a JavaScript mathematics library using the import function:<br />

// import math lib<br />

$.import("sap.myapp.lib","math");<br />

// use math lib<br />

var max_res = $.sap.myapp.lib.math.max(3, 7);<br />

The import function requires the following parameters:<br />

● Package name<br />

Full name of the package containing the library object you want to import, for example, sap.myapp.lib<br />

● Library name<br />

Name of the library object you want to import, for example, math<br />

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

Writing Server-Side JavaScript Applications<br />

P U B L I C<br />

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

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

Saved successfully!

Ooh no, something went wrong!