Você está na página 1de 29

Week 5 Unit 1: Server-Side

JavaScript (XSJS)

Server-Side JavaScript (XSJS)


Development Model (XSJS)

UI rendering completely in
the client
Server-side procedural
logic in JavaScript

UIS
SAPUI5
XSODATA

XSJS

XSXMLA

All artifacts stored in the


SAP HANA repository

InA
HDBRole

HDBTable
CDS
SQLScript
SQL
Views

2013 SAP AG. All rights reserved.

AFL

Public

Server-Side JavaScript (XSJS)


Development Model (XSJS)

Server-side JavaScript (XSJS)

UIS

Lightweight procedural logic

SAPUI5

Fast/open

XSODATA

XSJS

XSXMLA

Reuse

InA

One language:
Client
Server side

CDS

Widespread knowledge
Rapid development

2013 SAP AG. All rights reserved.

HDBRole

HDBTable

SQLScript
SQL
Views

AFL

Public

Server-Side JavaScript (XSJS)


Server-Side JavaScript (XSJS)

Native application-specific
code
Control data flow between
client and SAP HANA
Store XS JavaScript
programs in the repository
JavaScript editor/debugger

2013 SAP AG. All rights reserved.

Public

Server-Side JavaScript (XSJS)


The XSJS Application-Programming Interface (API)

Interact with the SAP HANA


XS runtime environment
Access SAP HANA database
capabilities directly
Expose, update, insert, and
delete data
Request API
Control HTTP request/response

Database API
Open DB connection, roll back
changes in SAP HANA

2013 SAP AG. All rights reserved.

Public

Server-Side JavaScript (XSJS)


XS JavaScript Libraries

Reuse program elements


Reuse 3rd party/open source
code
Perform repetitive tasks
Handle forms
Manage date/time strings
Parse URLs

Import into other XSJS


programs
Call from other XSJS
programs

2013 SAP AG. All rights reserved.

Public

Week 5 Unit 2: Creating an XSJS


Service

Creating an XSJS Service


Simple XS JavaScript Service

Create XSJS source file


Define custom application logic
Commit/activate files in SAP HANA
Call program from a client UI
Display the result set

2013 SAP AG. All rights reserved.

Public

Creating an XSJS Service


Custom Logic

Function Logic
performMultiply()

Get input values


$.request.parameters.get

Perform multiplication
cmd=multiply

Put result in response body


$.response.setBody()

Set response code OK


$.response.status

2013 SAP AG. All rights reserved.

Public

Creating an XSJS Service


Functions and Variables

Functions
performMultiply()

Variables
body
num1
num2
answer
aCmd

2013 SAP AG. All rights reserved.

Public

Week 5 Unit 3: Extending the XSJS


Service

Extending the XSJS Service


Extended XS JavaScript Service

Extract data (with SQL)


Define custom output format
Format extracted data
Display the result set in Excel

2013 SAP AG. All rights reserved.

Public

Extending the XSJS Service


JavaScript Libraries

Reusable external libraries


Create custom libraries
Look up reusable languageindependent texts from the SAP
HANA database

Share library between projects


Share library between XSJS
services

2013 SAP AG. All rights reserved.

Public

Extending the XSJS Service


JavaScript Functions

Download Excel
Retrieval data from tables
Format data as tab-delimited list
Display data in Excel instance
embedded in a Web browser

2013 SAP AG. All rights reserved.

Public

Extending the XSJS Service


Custom Output Formats

Apply custom format to


extracted data
Format as tab-delimited list
Set response headers

2013 SAP AG. All rights reserved.

Public

Extending the XSJS Service


Data Extraction with SQL Statements

Build SQL query


Syntax similar to JDBC/ODBC
Connect to SAP HANA
Pass SQL query to database

2013 SAP AG. All rights reserved.

Public

Week 5 Unit 4: Calling XSJS from


the UI

Calling XSJS from the UI


Calling an XS JavaScript Service

UI with 2 input fields


Call XSJS service when
user enters new value
XSJS runs on UI trigger and
performs defined action

2013 SAP AG. All rights reserved.

Public

Calling XSJS from the UI


SAPUI5 Basics

SAPUI5 project
Base HTML page
UI controller/view
JavaScript

2013 SAP AG. All rights reserved.

Public

Calling XSJS from the UI


Event Trigger = Change Input Value in UI Text Box

AJAX calls to the XSJS


service:
Method: GET
Datatype: JSON

Values for UI input fields:


Event: live input value

URL of XSJS service:


./services/workshop.xsjs

2013 SAP AG. All rights reserved.

Public

Week 5 Unit 5: Debugging XSJS

Debugging XSJS
Debugger Configuration Part 1

Debug activation
Debug port configuration

2013 SAP AG. All rights reserved.

Public

Debugging XSJS
Debugger Configuration Part 2

Debug configuration name


SAP HANA hostname
SAP HANA port number
Debug session ID

2013 SAP AG. All rights reserved.

Public

Debugging XSJS
The Debug Perspective

Debug view
Breakpoints view
Variables view
Source code view
Outline view

2013 SAP AG. All rights reserved.

Public

Debugging XSJS
Debugging XSJS Code

The XS JavaScript editor


Debug session ID
Debug breakpoints
Stepping between functions
Find variable (right-click)
Start/stop debugger
Pause/resume debugger

2013 SAP AG. All rights reserved.

Public

Debugging XSJS
Breakpoints

Interactive debugging
Enable breakpoint
Disable breakpoint
Toggle breakpoint

2013 SAP AG. All rights reserved.

Public

Debugging XSJS
Variables

List XSJS variables


View variable context
Display variable value
Change variable value

2013 SAP AG. All rights reserved.

Public

Thank you

Contact information:
open@sap.com

2013 SAP AG. 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 AG.
The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or
warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group
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.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in
Germany and other countries.
Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.

2013 SAP AG. All rights reserved.

Public

Você também pode gostar