29
Week 5 Unit 1: Server-Side JavaScript (XSJS)

Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

Embed Size (px)

DESCRIPTION

openSAP HANA Development

Citation preview

Page 1: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

Week 5 Unit 1: Server-SideJavaScript (XSJS)

Page 2: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 2Public

Server-Side JavaScript (XSJS)Development Model (XSJS)

UI rendering completely inthe client

Server-side procedurallogic in JavaScript

All artifacts stored in theSAP HANA repository

SAPUI5

UIS

XSJS XSODATA

InA

XSXMLA

CDS

SQLScriptSQLViews

AFL

HDBTable HDBRole

Page 3: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 3Public

Server-Side JavaScript (XSJS)Development Model (XSJS)

Server-side JavaScript (XSJS)

Lightweight procedural logic

Fast/open

Reuse

One language:ClientServer side

Widespread knowledge

Rapid development

SAPUI5

UIS

XSJS XSODATA

InA

XSXMLA

CDS

SQLScriptSQLViews

AFL

HDBTable HDBRole

Page 4: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 4Public

Server-Side JavaScript (XSJS)Server-Side JavaScript (XSJS)

Native application-specificcode

Control data flow betweenclient and SAP HANA

Store XS JavaScriptprograms in the repository

JavaScript editor/debugger

Page 5: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 5Public

Server-Side JavaScript (XSJS)The XSJS Application-Programming Interface (API)

Interact with the SAP HANAXS runtime environment

Access SAP HANA databasecapabilities directly

Expose, update, insert, anddelete data

Request APIControl HTTP request/response

Database APIOpen DB connection, roll backchanges in SAP HANA

Page 6: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 6Public

Server-Side JavaScript (XSJS)XS JavaScript Libraries

Reuse program elements

Reuse 3rd party/open sourcecode

Perform repetitive tasksHandle formsManage date/time stringsParse URLs

Import into other XSJSprograms

Call from other XSJSprograms

Page 7: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

Week 5 Unit 2: Creating an XSJSService

Page 8: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 2Public

Creating an XSJS ServiceSimple 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

Page 9: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 3Public

Creating an XSJS ServiceCustom Logic

Function LogicperformMultiply()

Get input values$.request.parameters.get

Perform multiplicationcmd=multiply

Put result in response body$.response.setBody()

Set response code “OK”$.response.status

Page 10: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 4Public

Creating an XSJS ServiceFunctions and Variables

FunctionsperformMultiply()

Variablesbodynum1num2answeraCmd

Page 11: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

Week 5 Unit 3: Extending the XSJSService

Page 12: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 2Public

Extending the XSJS ServiceExtended XS JavaScript Service

Extract data (with SQL)

Define custom output format

Format extracted data

Display the result set in Excel

Page 13: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 3Public

Extending the XSJS ServiceJavaScript Libraries

Reusable external libraries

Create custom librariesLook up reusable language-independent texts from the SAPHANA database

Share library between projects

Share library between XSJSservices

Page 14: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 4Public

Extending the XSJS ServiceJavaScript Functions

Download Excel

Retrieval data from tables

Format data as tab-delimited list

Display data in Excel instanceembedded in a Web browser

Page 15: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 5Public

Extending the XSJS ServiceCustom Output Formats

Apply custom format toextracted data

Format as tab-delimited list

Set response headers

Page 16: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 6Public

Extending the XSJS ServiceData Extraction with SQL Statements

Build SQL query

Syntax similar to JDBC/ODBC

Connect to SAP HANA

Pass SQL query to database

Page 17: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

Week 5 Unit 4: Calling XSJS fromthe UI

Page 18: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 2Public

Calling XSJS from the UICalling an XS JavaScript Service

UI with 2 input fields

Call XSJS service whenuser enters new value

XSJS runs on UI trigger andperforms defined action

Page 19: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 3Public

Calling XSJS from the UISAPUI5 Basics

SAPUI5 project

Base HTML page

UI controller/view

JavaScript

Page 20: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 4Public

Calling XSJS from the UIEvent Trigger = Change Input Value in UI Text Box

AJAX calls to the XSJSservice:

Method: GETDatatype: JSON

Values for UI input fields:Event: live input value

URL of XSJS service:./services/workshop.xsjs

Page 21: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

Week 5 Unit 5: Debugging XSJS

Page 22: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 2Public

Debugging XSJSDebugger Configuration Part 1

Debug activation

Debug port configuration

Page 23: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 3Public

Debugging XSJSDebugger Configuration Part 2

Debug configuration name

SAP HANA hostname

SAP HANA port number

Debug session ID

Page 24: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 4Public

Debugging XSJSThe Debug Perspective

Debug view

Breakpoints view

Variables view

Source code view

Outline view

Page 25: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 5Public

Debugging XSJSDebugging XSJS Code

The XS JavaScript editor

Debug session ID

Debug breakpoints

Stepping between functions

Find variable (right-click)

Start/stop debugger

Pause/resume debugger

Page 26: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 6Public

Debugging XSJSBreakpoints

Interactive debugging

Enable breakpoint

Disable breakpoint

Toggle breakpoint

Page 27: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. 7Public

Debugging XSJSVariables

List XSJS variables

View variable context

Display variable value

Change variable value

Page 28: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

Thank you

Contact information:

[email protected]

Page 29: Week 05 Exposing and Consuming Data With Server-Side JavaScript Presentation

© 2013 SAP AG. All rights reserved. Public

© 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 orwarranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Groupproducts and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothingherein 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 inGermany 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.

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 orwarranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Groupproducts and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothingherein 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 inGermany and other countries.Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.