Node.js Code Samples (SAP HANA)

Aus MattWiki

This entry contains SAP HANA specific code listings which can be executed in either XSJS or Node.js runtime within XS Advanced environment.

For basics knowledge on JavaScript language itself see JavaScript Basics

Language Basics on XSJS Runtime

String: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-strings.xsjs

Datum: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-dates.xsjs

Arrays: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-arrays.xsjs

JSON-Output: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-json.xsjs

Objects: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-objects.xsjs

Classes: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-classes.xsjs

Language Basics on Node.js Runtime

The listings are basically the same as for XSJS but they are implemented to be run on Node.js / XSA :

https://github.com/mattxdev/openSAPHANA/blob/master/srv/router/routes/JavaScriptBasics.js

Text Bundles

  • Use TextBundle module @sap/textbundle";
  • Get locale from Client Browser Headers
  • Store language specific text files in _i18n subfolder
  • Create instance bundle of type TextBundle
  • Get text with getText Method of bundle instance

https://github.com/mattxdev/openSAPHANA/blob/master/srv/router/routes/textBundle.js

Object Oriented JavaScript

WebSockets