28.01.2013 Views

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SAP HANA Developer Guide - Get a Free Blog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

7 Developing Procedures<br />

SQL in <strong>SAP</strong> <strong>HANA</strong> includes extensions for creating procedures, which enables you to embed data-intensive<br />

application logic into the database, where it can be optimized for performance (since there are no large data<br />

transfers to the application and features such as parallel execution is possible). Procedures are used when other<br />

modeling objects, such as analytic or attribute views, are not sufficient.<br />

Some of the reasons to use procedures instead of standard SQL:<br />

● SQL is not designed for complex calculations, such as for financials.<br />

● SQL does not provide for imperative logic.<br />

● Complex SQL statements can be hard to understand and maintain.<br />

● SQL queries return one result set. Procedures can return multiple result sets.<br />

● Procedures can have local variables, eliminating the need to explicitly create temporary tables for<br />

intermediate results.<br />

Procedures can be written in the following languages:<br />

● SQLScript: The language that <strong>SAP</strong> <strong>HANA</strong> provides for writing procedures.<br />

● R: An open-source programming language for statistical computing and graphics, which can be installed and<br />

integrated with <strong>SAP</strong> <strong>HANA</strong>.<br />

There are additional libraries of procedures, called Business Function Library and Predictive Analysis Library, that<br />

can be called via SQL or from within another procedure.<br />

SQL Extensions for Procedures<br />

SQL includes the following statements for enabling procedures:<br />

● CREATE TYPE: Creates a table types, which are used to define parameters for a procedure that represent<br />

tabular results. For example:<br />

CREATE TYPE tt_publishers AS TABLE (<br />

publisher INTEGER,<br />

name VARCHAR(50),<br />

price DECIMAL,<br />

cnt INTEGER);<br />

● CREATE PROCEDURE: Creates a procedure. The LANGUAGE clause specifies the language you are using to<br />

158<br />

code the procedure. For example:<br />

CREATE PROCEDURE ProcWithResultView(IN id INT, OUT o1 CUSTOMER)<br />

LANGUAGE SQLSCRIPT READS SQL DATA WITH RESULT VIEW ProcView AS<br />

BEGIN<br />

o1 = SELECT * FROM CUSTOMER WHERE CUST_ID = :id;<br />

END;<br />

P U B L I C<br />

© 2012 <strong>SAP</strong> AG. All rights reserved.<br />

<strong>SAP</strong> <strong>HANA</strong> <strong>Developer</strong> <strong>Guide</strong><br />

Developing Procedures

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!