Sunteți pe pagina 1din 4

ABAP Managed Database Procedures - why should I use them?

Calculations executed while retrieving the data from the database can significant reduce the runtime of an ABAP
program. Especially when the calculations can be parallelized. Due to the execution of code in application server.
Using SQL and all of its possibilities is one example of this. But this has limitations. A SQL statement always has one
result set and the calculation must be done in one single step.
If you have complex calculations which you want to execute on the database you need other possibilities. In those
cases and many more, database procedures come into the game. And the vehicle of choice to implement database
procedures as an ABAP geek are AMDPs.

Why to use them, why not use open SQL in ABAP side?

If the functionality offered by the open features (open SQL in ABAP) is not sufficient to cover your needs, you have to
switch to Native SQL (like AMDP).This is especially true for SAP HANA, that offers analytical features not covered in
standard SQL, as e.g. calculation views. If your ABAP programs should run on HANA only (or if you want to offer
special implementations for HANA and alternative implementations for other databases), database procedures written
in SQLScript offer a convenient access to the capabilities of HANA. In order to facilitate this Native access to HANA,
in 7.40, SP05 the concept of ABAP Managed Database Procedures (AMDP) was introduced, that allows you to code
SQLScript in special methods of normal ABAP classes and the runtime environment does the rest for you. (But
please note that a single SQL statement does not become faster if you code it in an AMDP, how should it? As long as
you can stay open, stay open. There is no drawback in performance if you can express the logics in single
statements or in CDS views. You use AMDP to avoid unnecessary data transfers between database and
application server when using several statements or when you need access to functionality not covered by
SQL).

Other details
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

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 an intermediate variable or parameter

As we use SQLScript in AMDP, Procedures, Triggers and other HANA artifacts we should
now see that why SQLScript is needed.

Why Do We Need SQLScript?


The main goal of SQLScript is to allow the execution of data intensive calculations inside SAP HANA.
There are two reasons why this is required to achieve the best performance:

Moving calculations to the database layer eliminates the need to transfer large amounts of data from the
database to the application

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.
If applications fetch data as sets of rows for processing on application level they will not benefit from these
features

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

Reference links:
http://scn.sap.com/docs/DOC-51612
http://sapinsider.wispubs.com/Assets/Articles/2014/October/SPI-where-ABAP-meets-SAP-HANA
http://saphanatutorial.com/sap-hana-sqlscript/
http://scn.sap.com/community/abap/hana/blog/2014/09/26/code-push-down-for-hana-from-abap-starts-withopen-sql

S-ar putea să vă placă și