opensap hana1-1 week 05 exposing and consuming data with server-side javascript presentation
DESCRIPTION
sap hanaTRANSCRIPT
© 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
© 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
© 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
© 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
© 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
© 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
© 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
© 2013 SAP AG. All rights reserved. 4Public
Creating an XSJS ServiceFunctions and Variables
FunctionsperformMultiply()
Variablesbodynum1num2answeraCmd
© 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
© 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
© 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
© 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
© 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
© 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
© 2013 SAP AG. All rights reserved. 3Public
Calling XSJS from the UISAPUI5 Basics
SAPUI5 project
Base HTML page
UI controller/view
JavaScript
© 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
© 2013 SAP AG. All rights reserved. 2Public
Debugging XS JavaScriptDebugger Administration
1. Add/Enable thedebugger parameter inSAP HANA
2. Grant the Debugger roleto the SAP HANA user
© 2013 SAP AG. All rights reserved. 3Public
Debugging XS JavaScriptDebugger Configuration
Debug Configuration NameSAP HANA hostnameSAP HANA port number
80<SAP HANA Instance No.>
User Name/Password:Logon credentials of SAP HANA userrunning the debugging session
© 2013 SAP AG. All rights reserved. 4Public
Debugging XS JavaScriptThe Debug Perspective
Debug view
Breakpoints view
Variables view
Source-code view
Outline view
© 2013 SAP AG. All rights reserved. 5Public
Debugging XS JavaScriptDebugging XSJS Code
The XS JavaScript editor
Debug session ID
Debug breakpoints
Step between functions
Find variable (right-click)
Start/stop debugger
Pause/resume debugger
© 2013 SAP AG. All rights reserved. 6Public
Debugging XS JavaScriptBreakpoints
Interactive debugging
Enable breakpoint
Disable breakpoint
Toggle breakpoint
© 2013 SAP AG. All rights reserved. 7Public
Debugging XS JavaScriptVariables
List XSJS variables
View variable context
Display variable value
Change variable value
© 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.