You are on page 1of 43

Week 4 Unit 1:

Week Introduction

Week Introduction
Architecture Overview diagram
Browser
R

SAP HANA XS Adv. (New in SAP HANA SPS 11)

SAP Web
Dispatcher

Application Router

HTML5
App

XSJS
Compt.
XSJS
App

Central
Security
Service

Node.js

Tomcat / TomEE

Node App

Java App

SAP HANA
XS Classic
(existing
runtime
still for
several
SPS
levels)

Other
Containers

OData (JavaScript) HANA Database


OData (Java)
SAP HANA XS Adv. Runtime Platform / HCP

User Account
and
Authentication

2016 SAP SE or an SAP affiliate company. All rights reserved.

SAP
HANA DI

SAP HANA Database

Public

Week Introduction
Node.js
FLP

Node.js

SAPUI5/Fiori

Asynchronous, non-blocking program flow


Openness (modules and npm)
De facto standard for server-side JavaScript

ODATA

XSJS/
Node.js/
Java

XMLA
SINA

HDBRole

HDBTable
HDBCDS
SQLScript
SQL
Views

2016 SAP SE or an SAP affiliate company. All rights reserved.

AFL

Public

Thank you

Contact information:
open@sap.com

2016 SAP SE or an SAP affiliate company. All rights reserved.


No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forwardlooking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Week 4 Unit 2:
Modules and NPM

Modules and NPM


Overview
Modules are reusable JavaScript functions
NPM Node Package Manager tool to
maintain dependencies to external modules
Most SAP-specific logic for XSA Node.js is
delivered via modules
SAP Web IDE for SAP HANA has a local
NPM registry

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Modules and NPM


Module exports
Modules are normal JavaScript .js files
They use module.exports statement to
expose functions to the outside

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Modules and NPM


require
The JavaScript keyword require is used
to access a module
File extension not required; Node.js will
look for .js, .json, and .node files in that
order
Search order when not using (/, ./, or ../):
core module then node_modules

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Modules and NPM


XSJS
XSJS can now also access Node.js
modules with the new $.require API

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Modules and NPM


Core modules
Central functionality in Node.js runtime itself is
exposed as special modules known as core
modules

http node.js http server


path parsing and processing of file paths

fs file I/O
os access to the server operating system

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Modules and NPM


NPM
Most node modules are not local to a project
NPM the Node Package Manager loads these
modules from a central repository and copies them
into your project
NPM manages dependences and versions
Package.json defines the needed modules and their
versions

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Modules and NPM


NPM registry
NPM needs a registry from which to pull
the dependent Node modules
Public registry: https://www.npmjs.com
SAP Web IDE for SAP HANA has local
NPM registry cache to proxy calls to
public registry plus contains the private
SAP modules

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Thank you

Contact information:
open@sap.com

2016 SAP SE or an SAP affiliate company. All rights reserved.


No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forwardlooking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

10

Week 4 Unit 3: Asynchronous


Non-Blocking I/O

Asynchronous Non-Blocking I/O


Overview
Node.js is not true parallelism
Node.js achieves high concurrency for
requests still because I/O is all nonblocking and event-driven
Most JavaScript functions in Node use a
callback event to report to the caller when
finished

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Thank you

Contact information:
open@sap.com

2016 SAP SE or an SAP affiliate company. All rights reserved.


No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forwardlooking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Week 4 Unit 4:
SAP HANA DB Access

SAP HANA DB Access


Overview
XS Advanced applications connect with
technical users to the database
Previously, this was only an option (using
SQLCC), but in XSA this will be the
standard

This enables efficient pooling of database


connections and improves performance
The application user is known to the
database processing for instance-based
authorization

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

SAP HANA DB Access


Define the HDI container resource
Within the mta.yaml, you can define a resource of
type com.sap.xs.hdi-container
This will create the container if it doesnt exist upon
build of an HDI module, or upon deploy/install of
the entire project
Includes parameter to specify the target schema
name when created via the deploy/install command
The schema configuration is ignored during build
from SAP Web IDE, and instead Developer
Username and Project are used to make the
schema unique

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

SAP HANA DB Access


Maintain the connection from Node.js module to HDI container
Within the mta.yaml, in the requires section of
the Node.js module, you can maintain
dependent modules and resources
Add the HDI resource container here and the
Node.js module will use it to connect to the
SAP HANA database

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

SAP HANA DB Access


SAP Node.js modules
The core Node.js APIs provided by SAP are offered as
Node.js modules
Maintain dependencies for these modules in your
package.json
sap-hdbext: HDB extension library and utility functions for
using SAP HANA in node.js
sap-xsenv: Utility for easy setup and access of SAP HANA
XS Advanced environment variables
sap-xssec: XS Advanced Container Security API for Node.js
sap-cds: SAP HANA Core Data Services client for Node.js
sap-xsjs: Compatibility layer to run XS Classic applications
on XS Advanced
2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

SAP HANA DB Access


Initialize XSA UAA into Node.js Express
The UAA service provides the login
authentication and authorization
requirements
sap-xssec will generate a JWT token from
the XSA UAA service bound as a required
resource in a Node.js module
The passport module can use this JWT
token and be injected as a middleware into
Node.js Express (common lightweight Web
server)

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

SAP HANA DB Access


sap-hdbext
Module sap-hdbext provides the SAP
HANA database client
It can be used directly or as a Node.js
middleware
Designed specifically for Node.js with
its non-blocking I/O concepts
Each DB operation is non-blocking
and has callback events for completion
Data is returned as a JSON object

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

SAP HANA DB Access


sap-hdbext as Express middleware
sap-hdbext can be used as a Node.js
middleware
Express is responsible for the connection
pooling
The connection is automatically returned
to the pool when the express request is
closed or finished
The request object of the route handler
will already have an HDB client object in it

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

SAP HANA DB Access


sap-hdbext with stored procedures
sap-hdbext can also call stored procedures
Input and output parameters use standard
JavaScript variables and JSON

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

SAP HANA DB Access


sap-hdbext parallel request
Thanks to the Node.js concept of nonblocking I/O, it is simple and quite efficient to
call multiple database operations in parallel
via sap-hdbext
Here, we use the Node.js module async to
provide a synchronization point after both
database requests have returned their results

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

10

SAP HANA DB Access


Advanced consumption of Core Data Services

XS Adv + = Best in class SAP HANA support


simplified

SAP HANA consumption


in all runtimes

Java | node.js | XSJS

2016 SAP SE or an SAP affiliate company. All rights reserved.

consumption of
Core Data Services (CDS)
Public

11

SAP HANA DB Access


SAP HANA Core Data Services from Node.js
Automated content library XS Data Services (XSDS) for XS classic since SPS 09
Re-implementation in XS Advanced as Node.js module sap-cds
CDS support in JavaScript:
Import of CDS entities (metadata) into application
Managed mode (= lightweight ORM):
Data consistency between code and database
Limited query functionality
Unmanaged mode (= query builder):
Incrementally construct queries with implicit joins

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

12

SAP HANA DB Access


sap-cds example
namespace ex.data;
context bboard {

entity user {
key uid: Integer not null;
Name: String(63) not null;
Email: String(63);
};

Import
metadata
Get & modify
entity instances

type text {
Text: String(255);
Lang: String(2);
};
entity post {
key pid: Integer not null;
Title: String(63) not null;
Text: text;
Author: association [1] to
user;
Rating: Integer; };
};
bboard.hdbcds
2016 SAP SE or an SAP affiliate company. All rights reserved.

Complex
queries

cds.$importEntities([
{ $entity: "ex.data::bboard.post" },
{ $entity: "ex.data::bboard.user" }
], main);
function mainModify(error, entities) {
var Post = entities["ex.data::bboard.post"];
var User = entities["ex.data::bboard.user"];
Post.$get({ pid: 101 }, function(error, post) {
post.Rating++;
post.$save(function(error) { /* */ });
});
}

function mainQuery(error, entities) {


Post.$query()
.$project({Author:{ Name:true, Email:true },
Title: true
})
.$matching({ Rating: { $gt: 2 } })
.$execute(function(err, res) {/* */ });
bboard.js
Public

13

SAP HANA DB Access


sap-cds Unmanaged Query

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

14

SAP HANA DB Access


sap-cds Managed Get

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

15

SAP HANA DB Access


sap-cds Managed Get and Update

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

16

SAP HANA DB Access

syntax changes,
sequential
imports

Comparison between sap-cds and XSDS


Import
metadata
Get &
modify
entity
instances
Complex
queries

cds.$importEntities([
{ $entity: "ex.data::bboard.post" },
{ $entity: "ex.data::bboard.user" }
], main);
function mainModify(error, entities) {
var Post = entities["ex.data::bboard.post"];
var User = entities["ex.data::bboard.user"];
Post.$get({ pid: 101 }, function(error, post){
post.Rating++;
post.$save(function(error) { /* */ });
});
}

var Post=xsds.$importEntity("ex.data",
"bboard.post"};
var User=xsds.$importEntity("ex.data",
"bboard.user"};
function mainModify(error, entities) {
var post = Post.$get({ pid: 101 });
post.Rating++;
post.$save;
synchronous
Synchronous
}

no callbacks
callbacks

function mainQuery(error, entities) {


Post.$query()
.$project({Author:{ Name:true, Email:true },
Title: true
})
.$matching({ Rating: { $gt: 2 } })
.$execute(function(err, res) {/* */ });
}

function mainQuery(error, entities) {


var res = Post.$query()
.$project({Author:{ Name:true, Email:true },
Title: true
})
.$matching({ Rating: { $gt: 2 } })
.$execute();
}

bboard.js

bboard.xsjs

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

17

Thank you

Contact information:
open@sap.com

2016 SAP SE or an SAP affiliate company. All rights reserved.


No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forwardlooking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

19

Week 4 Unit 5: Web Sockets

Web Sockets
Overview
Web Sockets is an advanced technology that makes it
possible to open an interactive communication session
between the user's browser and a server.
Standard TCP-based protocol

Two-way (bi-directional) ongoing conversation


Makes more seamless interaction between a browser
and Web server possible
Supported by most major browsers (Chrome, IE, Firefox,
Safari, Opera)

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Web Sockets
SAPUI5

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

Thank you

Contact information:
open@sap.com

2016 SAP SE or an SAP affiliate company. All rights reserved.


No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate
company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products and
services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop
or release any functionality mentioned therein. This document, or any related presentation, and SAP SEs or its affiliated companies strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time
for any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forwardlooking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.

2016 SAP SE or an SAP affiliate company. All rights reserved.

Public

You might also like