58
7/21/2019 Introduction to SQLScript in SAP HANA http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 1/58 Introduction to SAP HANA SQLScript Rich Heilman SESSION CODE: BT162

Introduction to SQLScript in SAP HANA

Embed Size (px)

DESCRIPTION

SAP HANA

Citation preview

Page 1: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 1/58

Introduction to SAP HANA SQLScript

Rich Heilman

SESSION CODE: BT162

Page 2: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 2/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 3Public

Disclaimer 

This presentation outlines our general product direction and should not be relied on in making a

purchase decision. This presentation is not subject to your license agreement or any other agreement

with SAP. SAP has no obligation to pursue any course of business outlined in this presentation or to

develop or release any functionality mentioned in this presentation. This presentation and SAP's

strategy and possible future developments are subject to change and may be changed by SAP at anytime for any reason without notice. This document is provided without a warranty of any kind, either 

express or implied, including but not limited to, the implied warranties of merchantability, fitness for a

particular purpose, or non-infringement. SAP assumes no responsibility for errors or omissions in this

document, except if such damages were caused by SAP intentionally or grossly negligent.

Page 3: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 3/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 4Public

 Agenda

Overview

Wizard, Editor & Viewer 

Debugger 

SQLScript Language Features

User Defined Functions(UDFs)

Triggers

 ABAP Connectivity

Page 4: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 4/58

Overview

Page 5: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 5/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 6Public

Overview

What?

SQLScript is

§  An interface for applications to access SAP HANA

§ Extension of ANSI Standard SQL

§ Language for creating stored procedures in HANA

§ Declarative Logic§ SELECT queries

§ Calculation Engine(CE) functions

§ Orchestration Logic§ Data Definition Language(DDL)

§ Data Manipulation Language(DML)

§  Assignment & imperative logic

Page 6: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 6/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 7Public

Overview

Why?

Main goal is to allow the execution of data intensive calculations inside SAP HANA

Two reasons why this is required to achieve the best performance:

§ Eliminate data transfer between database & application tiers

§ Calculations need to be executed in the database layer to get the maximum benefit from SAP HANA

features such as fast column operations, query optimization and parallel execution.

Page 7: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 7/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 8Public

Overview

 Advantages

Compared to plain SQL queries, SQLScript has the following advantages:

§ Returns multiple results, while a SQL query returns only one result set

§ Complex logic can be broken down into smaller chunks of code. Enables modular programming,

reuse and a better understandability by functional abstraction. For structuring complex queries,

standard SQL only allows the definition of SQL views. However, SQL views have no parameters

§ SQLScript supports local variables for intermediate results with implicitly defined types. With

standard SQL, it would be required to define globally visible views even for intermediate steps

§ SQL Script has control logic such as if/else that is not available in SQL

Page 8: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 8/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 9Public

Front-end Technologies

§ http/s

§ HTML5 / SAPUI5

§ Client-side JavaScript

Control Flow Technologies§ OData

§ Server-Side JavaScript

§ XMLA

Data Processing Technologies§ SQL / SqlScript

§ Calculation Engine Functions

§  Application Function Library (AFL)

Presentation logic

Control flow logic

Data

Client: Browser or Mobile

SAP HANA

XS

Calculation logic

Overview

 Application Development Technologies

Page 9: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 9/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 10Public

DB Layer 

Code

Traditional: “ Data to Code” New Model: “ Code to Data”

Massive datacopies creates

bottleneck

Transfer Minimum

Result Set

Overview

Traditional Programming Model vs. New Programming Model

 Application Layer  Application Layer 

DB Layer 

Code

Page 10: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 10/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 11Public

Overview

SQLScript Code Example

BEGI N...

- - Query 1product _i ds = select "ProductId", "Category", "DescId"

from "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::products"

where "Category" = 'Notebooks' or "Category" = 'PC';

- - Query 2

pr oduct _t exts = select "ProductId", "Category", "DescId", "Text"from :product_ids as prod_ids

inner join "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::texts"

as texts on prod_ids."DescId" = texts."TextId";

- - Query 3out _not ebook_count = select count(*) as cnt from 

: pr oduct _t ext s where "Category" = 'Notebooks';

- - Query 4out _pc_count = select count(*) as cnt from 

: pr oduct _t ext s where "Category" = 'PC';

- - Query 5out _t otal _count = select count(*) as cnt

from "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::products“;

...

END;

Notebooks PCs

Input

Q3 Q4

Q2

Q1 Q5

Total

Page 11: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 11/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 12Public

Overview

Parallel Processing

SELECT statements are executed in parallel unless:

§ Any local scalar parameters and variables are used in the procedure

§ Any read/write procedures or DML/DDL operations are executed

§ Any imperative logic is used within the procedure, such as IF statements of FOR loops

§ Any SQL statements are used that are not assigned to a intermediate variable or parameter 

Page 12: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 12/58

Wizard, Editor & Viewer 

Page 13: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 13/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 14Public

§ “Stored Procedure” under “Database

Development”

§ Two file formats

§ .hdbprocedure is the new artifact type

which will be the recommended file

format moving forward.§ .procedure is still supported, but has

been deprecated and eventually will be

removed.

§ Target schema definition

Wizard, Editors & Viewer 

Stored Procedure Wizard in SAP HANA Studio

Page 14: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 14/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 15Public

Wizard, Editor & Viewer 

Editor Integration with SAP HANA Development Perspective

§ Source code based editor 

§ Client side syntax checking

§ Code hints

§ Syntax highlighting

§Semantic code completion§ CTRL+SPACE to trigger 

§ Lists relevant objects

based on context

§ Searches for any matches

within the object name

Page 15: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 15/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 16Public

Wizard, Editor & Viewer 

Editor Integration in the Web-Based Development Workbench

§ Keyword code completion

§ Syntax highlighting

§ .hdbprocedure file format only

Page 16: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 16/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 17Public

§ Procedures in the catalog can now be viewed in the SQLScript editor in read-only mode.

§  Allows for setting/removing of breakpoints within the runtime object.

Wizard, Editor & Viewer 

SQLScript Procedure Viewer 

Page 17: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 17/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 18Public

Wizard, Editor & Viewer 

Procedure Code Breakdown

§ Schema definition – developer can define which schema in which the run-time object of the

procedure will be created

Page 18: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 18/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 19Public

Wizard, Editor & Viewer 

Procedure Code Breakdown

§ Package hierarchy and procedure name – contains the complete package hierarchy as well as the

name of the procedure, separated by double colon(::)

Page 19: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 19/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 20Public

Wizard, Editor & Viewer 

Procedure Code Breakdown

§ Input/output parameter definition – developer can define both input parameters with default values as

well as output parameters. Parameters can reference simple types, in-line table types, or global

types defined via CDS

Page 20: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 20/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 21Public

Wizard, Editor & Viewer 

Procedure Code Breakdown

§ Metadata declarations: developer can set language(SQLScript/R), security(invoker/definer),

default schema and read/write access

Page 21: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 21/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 22Public

Wizard, Editor & Viewer 

Procedure Code Breakdown

§ Script body – developer writes the body of the script between the BEGIN and END statements

Page 22: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 22/58

Debugger 

Page 23: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 23/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 24Public

Debugger 

Debug Perspective within SAP HANA Studio

§ Resume/Terminate

§ Variable evaluation

§ Breakpoint management

§ Break on break-points

§ Basic step debugging

Page 24: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 24/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 25Public

§ Define procedure to be

debugged

§ Debug both repository

and catalog procedures

Debugger 

Debug Configuration

Page 25: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 25/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 26Public

§ Debug with input parameters

Debugger 

Debug Configuration

Page 26: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 26/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 27Public

Debugger 

External Debugging

§  Attach to running session

§ By connection ID

§ By application user ID

Page 27: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 27/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 28Public

Debugger 

Debugging in the Web-based Development Workbench

§ Set breakpoints in the

runt-time object in the

catalog

§ Call procedure from the

SQL console

§ Resume & step over functions

§ Scalar & table

variable/parameter 

evaluations

Page 28: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 28/58

SQLScript Language Features

Page 29: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 29/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 30Public

SQLScript Language Features

Declarative Logic

 Allows the developer to declare the data selection via SELECT or CE(Calculation Engine) functions

§ Developer defines the what

§ Engine defines the how and executes accordingly

§ Massive parallelized

Page 30: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 30/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 31Public

SQLScript Language Features

Imperative Logic

§  Allows developer to controlthe flow of the logic withinSQLScript.

§ Scalar variablemanipulation

§DDL/DML logic

§ WHILE loops

§ Branching logic based onsome conditions, for example IF/ELSE

§ Executed exactly asscripted, procedurally

§

No parallel processing

Page 31: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 31/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 32Public

SQLScript Language Features

 Arrays

§  Allows the developer to define and

construct arrays within SQLScript

§ Set elements

§ Return elements

§

Remove elements§ Concatenate two arrays

§ Turn array into a table

§ Turn a column of a table into an

array

§ Return cardinality of an array

Page 32: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 32/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 33Public

SQLScript Language Features

Dynamic Filtering

§  Allows developers to apply a dynamic

WHERE clause to SELECT statements

§ Both database tables and intermediate

table variables are supported

Page 33: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 33/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 34Public

§ Exception handling is a method for handling exception and completion conditions in an SQLScript

procedures

§ The DECLARE EXIT HANDLER statement allows you to define exception handlers to process

exception conditions in your procedures.

§ You use the DECLARE CONDITION parameter to name exception conditions, and optionally, their 

associated SQL state values.

§ You can use SIGNAL or RESIGNAL with specified error code in user-defined error code range. A

user-defined exception can be handled by the handler declared in the procedure. Also it can be

handled by the caller which can be another procedure or client.

SQLScript Language Features

Exception Handling

Page 34: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 34/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 35Public

SQLScript Language Features

Exception Handling

§ Declare exit handlers for 

generic SQL exceptions

§ Declare exit handlers for 

specific SQL error codes

Page 35: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 35/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 36Public

SQLScript Language Features

Exception Handling

§ Signaling and catching user-defined conditions

Page 36: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 36/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 37Public

SQLScript Language Features

Exception Handling

§ RESIGNAL user defined

exceptions to the caller 

§ RESIGNAL can also be executed

explicitly within the body of the exit

handler 

Page 37: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 37/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 38Public

SQLScript Language Features

 Autonomous Transactions

§  Allows developer to create an isolated block of code which runs as an independent transaction

§ BEGIN AUTONOMOUS TRANSACTION … END statement block

§ Committed statements inside autonomous transaction block will be persisted regardless of a

rollback of the main transaction.

§

COMMIT & ROLLBACK areallowed only within the

 AUTONOMOUS

TRANSACTION block

§ For tables updated within the

main procedure body, access

to those tables is not allowed

in the autonomoustransaction block

§ Used commonly for logging

tasks

Page 38: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 38/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 39Public

SQLScript Language Features

Cursors

§  Allows developers to iterate over a result set and perform row-based processing and calculations.

Page 39: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 39/58

User Defined Functions(UDF)

Page 40: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 40/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 41Public

User Defined Functions

Overview

Language used within the body is SQLScript, other languages are

supported.

Functions are read-only, side effect free.

Two types, both have a wizard and associated editor:

§

Table User Defined Function(.hdbtablefunction artifact)§ Scalar User Defined Function(.hdbscalarfunction artifact)

Page 41: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 41/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 42Public

User Defined Functions

Table UDF§ Can have any number of input

parameters

§ Returns exactly one table

§ Table operations are allowed within

the body

§ Consumed in the FROM clause of a

SELECT statement

Page 42: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 42/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 43Public

User Defined Functions

Scalar UDF

§ Can have any number of input

parameters

§ Can return multiple values

§ Cursors, SELECT INTO, and

procedure calls are allowed within the

body but not recommended

§ Input parameters can not be table type

§ Consumed from the field list or the

WHERE clause of the SELECT

statement. Also callable via direct

assignment( x := my_scalar_func() )

Page 43: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 43/58

Triggers

Page 44: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 44/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 45Public

Triggers

Overview

§ Special type of stored procedure that automatically executes when an event occurs in the

database server 

§ Triggers can be executed BEFORE or AFTER an event on a given table, such as INSERT,

UPDATE, or DELETE

§ Management of objects can only be done via SQL Console. Support for storing the artifacts in the

repository is coming in a future support package

Page 45: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 45/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 46Public

Triggers

Limitations

§ INSTEAD_OF trigger not supported

§ Statement level trigger is only supported for row-store tables

§  Access to subject table is blocked, no operations on the table which the trigger was created on.

§ Maximum trigger number per single table per DML is 1024, which means a table can have

maximum 1024 insert triggers, 1024 update triggers and 1024 delete triggers in the same time§ Trigger execution order is not guaranteed

§ Statements not supported in the body of a trigger include:

§ Result set assignments(select resultset into table)

§ Exit/Continue/Return statements

§ Cursor operations

§ Procedure calls(before SPS09)

§ Dynamic SQL

Page 46: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 46/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 47Public

Triggers

Examples

Page 47: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 47/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 48Public

Triggers

Examples

Page 48: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 48/58

 ABAP Connectivity

Page 49: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 49/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 50Public

How can my ABAP code benefit from SAP HANA?

The new paradigm

AS ABAP 

SAP HANA

Database 

Calculation

Calculation

“ Data to Code” “ Code to Data”

Code pushdown means delegating data intense calculations to the database

layer 

Page 50: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 50/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 51Public

Secondary database connections

Secondary connections

can be used to access local or remote database systems

are maintained via SM30 for table DBCON; entries can be

transported require specification of connection data including user (=DB

schema) and password

are supported in the Open SQL syntax by using the

CONNECTION supplement

form an own transaction context

Service note 1597627 describes the prerequisites and

procedure for setting up a secondary connection to HANA.

Page 51: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 51/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 52Public

 ABAP Database Connectivity(ADBC)

CL_SQL_CONNECTION

GET_CONNECTION

CREATE_STATEMENTand PREPARE_STATEMENT

ROLLBACK and COMMIT

CL_SQL_PREPARED_STATEMENT / CL_SQL_STATEMENT PREPARE / CLOSE  – Prepare / release an SQL Statement

SET_PARAM - Set an Input/Output Parameter (variants for CLOB, BLOB, STRUCT, TABLE (available soon))

PREPARED_QUERY, PREPARED_UPDATE - Execute a Prepared Query / DML Operation

EXECUTE_DDL, EXECUTE_QUERY, EXECUTE_UPDATE - Execute DDL, Query, DML (Insert, Update, Delete)

CL_SQL_RESULT_SET

SET_PARAM - Set an Input/Output Parameter (variants for CLOB, BLOB, STRUCT, TABLE)

 NEXT, NEXT_PACKAGE  – Read next record in the resulting set, or next set of records for internal tables

Have a look at the

Classbuilder (SE24) or 

Transaction

SE80!

Page 52: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 52/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 53Public

How can my ABAP code benefit from SAP HANA?

New features in ABAP 7.4

Benefits of In-Memory Architecture

DB-near programming

Transparent optimizations

Usage of HANA-specific

features

external views SP2

database procedure proxies SP2

HANA transport container SP2

SAP HANA content integration

* might also supp ort HANA-specific features in the futu re (> SP5) / ** ‘>= SP5’ means SP5 or later 

advanced Open SQL SP5

advanced ABAP view building

SP5*

 ABAP-managed procedures SP5

Fulltext index in DDIC SP2

 Advanced ABAP database

programming

Fast Data Access (new data exchange protocol) >= SP5** optimized SELECT. . . I NTO I TAB and SELECT SI NGLE >= SP5**

optimized FOR ALL ENTRI ES-clause >= SP5**

Page 53: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 53/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 54Public

Calculation view in SAP HANA

Consumption from ABAP

Integrated development options across ABAP and HANA

Consuming HANA views in ABAP

SAP HANA offers advanced view modeling, e.g.

• Attribute views (join views)

• Analytic views (star schemas)

• Calculation views (modeled or coded via SQL script)

With ABAP < 7.40 these views can be accessed low-

level via ADBC.

With ABAP 7.40 they are natively supported in ABAP

• Access possible via standard Open SQL• Support for automatic client handling

• Mapping to DDIC types possible

Page 54: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 54/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 55Public

Invocation from ABAP

Stored procedure in SAP HANA

Integrated development options across ABAP and HANA

Calling HANA database procedures from ABAP

SAP HANA offers writing stored procedures in SQL

Script – a extension to SQL - for expressing data

intensive application logic.

With ABAP < 7.40 stored procedures can be calledusing ADBC, which requires

• Manual handling of transfer tables for input and output

parameters via temporary tables or result views

• Manual mapping of database types to DDIC types

With ABAP 7.40 they are natively supported in ABAP

• Exporting/Importing parameters like for function

modules (including mapping parameter to DDIC types)

Page 55: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 55/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 56Public

Basic idea: manage database procedures and their li fecycles from

within the ABAP development infrastructure

 ABAP method is used as container for database procedures addition BY DATABASE PROCEDURE indicates that a method is executed in the database

addition FOR db_platform indicates the database platform (currently supported HDB = SAP HANA database)

Implementation of method body is done in SQLScript

editing environment is the ABAP class editor 

embedded syntax check is available for SQLScript code (different from native SQL!)

other languages might be supported in the future (for example R)

 ABAP server creates database procedure in database catalogue during generat ion runtime artifact is generated into schema SAP<SID> (and not _SYS_BIC)

 ABAP-managed Database Procedures

Overview

Page 56: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 56/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 57Public

 ABAP-managed Database Procedures

Example

CLASS zcd201_cl _sni ppet _amdp DEFINITION. . .I NTERFACES if_amdp_marker_hdb.METHODS: det er mi ne_sal es_vol ume

I MPORTI NG VALUE( i v_cl i ent ) TYPE mandtEXPORTI NG VALUE( et _sal es_vol ume) TYPE t t _sal es_vol ume.

ENDCLASS.

CLASS zcd201_cl _sni ppet _amdp IMPLEMENTATION.METHOD det er mi ne_sal es_vol ume BY DATABASE PROCEDURE

FOR HDB LANGUAGE SQLSCRIPT

USING snwd_so_i snwd_so_sl snwd_pd .-- here you use SQLScript

ENDMETHOD.ENDCLASS.

Marker interface

method additions

forward declaration of accessed

database objects

Page 57: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 57/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved.

Thank you

Contact information:

Rich Heilman

[email protected]

Page 58: Introduction to SQLScript in SAP HANA

7/21/2019 Introduction to SQLScript in SAP HANA

http://slidepdf.com/reader/full/introduction-to-sqlscript-in-sap-hana 58/58

© 2015 SAP SE or an SAP affiliate company. All rights reserved. 59Public

© 2015 SAP SE or an SAP aff il iate 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 l iable for errors or omissions with respect to the materials. The only warranties for SAP SE or SAP affiliate company products andservices 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 SE’s 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 forward-

looking 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 rel ied upon in making purchasing decisions.