You are on page 1of 38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

SAP YARD

YOUR BACKYARD FOR SAP TECHNICAL TIPS AND SOLUTIONS


HOME

SEE ALL POSTS

TUTORIALS

CODE SNIPPETS

KNOW THY YARD MEN

HELP FORUM

BOOKS & JOBS

SAP QUIZ
74
Shares

ABAP on SAP HANA. Part VII. SQL Script


and SAP HANA Stored Procedure
TOPICS: ABAP Development For SAP HANA

ABAP For SAP HANA

Enteremail

Subscribe

We Respect Your Privacy !

SEARCH

ABAP Programming For SAP HANA


Consumption Of HANA Stored Procedure In ABAP
SQL Script SAP HANA Stored Procedure

http://www.sapyard.com/abaponsaphanapartvii/

HA400
Follow@sapyard

1/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

SAPYard
656likes

Liked

Youand2otherfriendslikethis

74
Shares

POSTED BY: SAP YARD

AUGUST 29, 2016

Introduction to SQL Script and SAP HANA Stored Procedure


In the previous post(New Age SQL for ABAP), we explored the modern SQL
which helps to push the code to the database and helps us with performance
improvement. Also, the new age SQL is concise and allows us to do kinds of
stuff which were never possible in ABAP earlier. In this article, we would
check SQL Script and basic about Stored Procedures.
SQL Script De nition?
SAP HANA SQL document says: SQL Script is a collection of extensions to the
Structured Query Language (SQL).
Google/Wiki says: An SQL script is a set of SQL commands saved as a le in
SQL Scripts. An SQL script can contain one or more SQL statements or PL/SQL
blocks. You can use SQL Scripts to create, edit, view, run and delete script les.

SAP ABAP LINKS

Abapinho

7MostPopular&FeaturedArticles

SAP HANA from Space


Level
Lazy and Smart ABAPers

DELETING rows of the internal


table within the LOOP. Is it a

http://www.sapyard.com/abaponsaphanapartvii/

2/38

10/30/2016

74
Shares

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

SAP further simpli es, SQL Script is and extension to ANSI Standard SQL. It is
an interface for applications to access SAP HANA database. SQL Script is the
language which can be used for the creation of stored procedures in HANA.

Taboo? A big NO NO?

It can have Declarative and Orchestration Logic.


SELECT queries and Calculation Engine(CE) functions follow Declarative
Logic.
DDL, DML, Assignment and imperative follow Orchestration Logic.

Fiori App - An

Data transfer between database and application layer can be eliminated


using SQL Script. Calculations can be executed in the database layer using
SQL Script to obtain maximum bene t out of SAP HANA database. It
providesfast column operations, query optimization and parallel execution
(you will read these lines time and again in different language in this post).

Zero

Introduction from an
ABAPer
SAP HANA at Ground

ABAP on SAP HANA.


Part I. First Program in
ABAP HANA

Motivation?
SQL Script can be utilized to write data-intensive logic into the database
instead of writing code in the application server. Before ABAP 740, most of
the data needed for manipulation were copied from database to the
application server and all calculation, ltration and other logic were
implemented on these data. This technique is a strict No-No for
optimization and performance improvement of the ABAP code. SQL Script
helps to take maximum bene t of modern hardware and software innovation to
perform massive parallelization on multi-core CPUs.
SAP suggests, SQL Script comes into picture when HANA modeling constructs
like Analytic or Attribute views fail. Someones failure is other ones success.

Get Latitude and


Longitude of any place
using Google Map API in
SAP

NetworkedBlogs

Blog:
SAPYard
Topics:
Abap,Sap,Hana

Followourblog

Why?
Simply for Code to Data(base) shift.
http://www.sapyard.com/abaponsaphanapartvii/

3/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Data transfer between database and application layer can be eliminated using
SQL Script. Calculations can be executed in the database layer using SQL
Script to obtain maximum bene t out of SAP HANA database. It
providesfast column operations, query optimization and parallel execution
(you will read these lines time and again in different languages in this post).
What is SQL Script? Why we need SQL Script? What is the motivation
for having SQL Script?
74
Shares

Did we not answer these What, Why and What above? OK, lets start from
the beginning. The relational database model RDBMS was introduced back
in 1970s by Edger F. Codd (you might remember from college curriculum.
something ringing? or did I help you remember one of your beautiful/cute
crushes from your college days).

WEB DYNPRO ABAP TUTORIALS

DECEMBER 26, 2014

Lets Web Dynpro.


Part V

NOVEMBER 24, 2014

Lets Web Dynpro.


Part IV

NOVEMBER 11, 2014

Lets Web Dynpro.


Part III

NOVEMBER 5, 2014

Lets Web Dynpro.


Part ZZ

NOVEMBER 3, 2014

Lets Web Dynpro.


Part II

As per RDBMS, the Database must be normalized 1NF, 2NF, 3NF, BCNF and
4NF in order to have ACID properties of the data.
Google says: In computer science, ACID (Atomicity, Consistency, Isolation,
Durability) is a set of properties of database transactions. Read more about
ACID properties here.
http://www.sapyard.com/abaponsaphanapartvii/

4/38

10/30/2016

74
Shares

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

A simple example would be splitting of data into Header and Item to pass
the ACID test. In other words, data is stored in two-dimensional tables with
the foreign key relationship instead of having redundant rows and columns
in one table.
You can read more about Normalization here.
But the use of digital media has exploded in the recent past both in the
consumer world and enterprise world (in a way both are the same thing).
This has led to an exponential increase in the amount of the data being stored in
the databases. On the other hand, the expectation from users is minimum
response time, in some cases zero response time.
We can take the example of TATKAL IRCTC online train ticket booking.
There will be few Hundred Thousand if not Million users who want to book a
Tatkal ticket and expectation is there should not be any delay from the
system. 2 Hundred Thousand transactions (form ll up, validation, payment
using credit/debit card or online banking) per minute was one of the criteria for
the vendor for IRCTC quote.
For our readers who are outside India, TATKALs literal English translation
is INSTANT. You can consider TATKAL train booking as the Amazon Black
Friday Sale of iPhone 6S at 99$. The sale begins exactly at 10:00 AM on
11/24/2016 till stock last. Isnt iPhone 6S at 99$ an amazing deal? Even if

http://www.sapyard.com/abaponsaphanapartvii/

5/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

you already have iPhonse 6S, you would still try to buy it. Exactly at 10:00
AM, thousands of users try to order that phone. Most users cannot log in, the
system is hung. Some lucky who are able to log in, are not able to hit BUY
button. Few others who were successful at hitting the BUY button are still
waiting for Payment to be entered. Few lucky who have successfully entered
the Payment get the nal message, Sorry, iPhone 6S is out of stock. Please try
later.
74
Shares

HANA is able to deliver this. Absolutely no response lag time by using the
techniques which are both hardware and software innovation. Hence it is
called as Appliance and not just any Database. This is a separate topic
altogether which we have covered in SAP HANA from Space Level.
Now, if we want to use the power of fast computing of HANA Database, we
have to push all the data intensive computations from application server
(ABAP Server) to HANA Database layer. Here SQL Script plays the major part
in doing this.
Like any SQL language, SQL Script is used for querying the Database, in this
case, HANA Database. SQL Script is as per SQL 92 Standards. This is the sole
language used for writing Stored Procedures in the HANA Database.

http://www.sapyard.com/abaponsaphanapartvii/

6/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

How does it differ from SQL statements in ABAP?


i) Normal SQL returns only one result set while SQL Script can return
multiple results.
ii) Modularization is possible in SQL Script i.e. humungous intricate
business logic can be split into smaller pieces of code which are more
readable and understandable.
iii) Local variables for the transitional result can be de ned in SQL Script.
Normal SQL needs globally visible data types/views for intermediate logic.
74
Shares iv) Control statements like IF/ELSE are available in SQL Script but not in
normal SQL
SQL Script follows the Code to Data Paradigm with pushing of data intensive
computations to HANA Database. With this, it eliminates the transfer of data
from DB to the application server aka ABAP AS. This fully exploits the
capability of HANA database achieving the maximum throughput with
absolutely no response time.
SQL Script is a very powerful tool. We have always avoided using joins,
ordering by clause in ABAP SQL statements. All these are welcome in ABAP
740. We can also use query inside a query etc.

http://www.sapyard.com/abaponsaphanapartvii/

7/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

SQL statements can be broadly divided into below three categories:


Data Manipulation Language (DML) SELECT, INSERT, UPDATE
Data De nition Language (DDL) CREATE , ALTER DROP
Data Control Language (DCL) GRANT ,REVOKE
SQL Script also supports the below primitive data types:
TINYINT, SMALLINT, INTEGER, BIGINT, DECIMAL (p, s), REAL, FLOAT,
DOUBLE, VARCHAR, NVARCHAR, CLOB, NCLOB, VARBINARY, BLOB,DATE,
TIME, TIMESTAMP
Read more about primitive data types here.
Table Creation andAlteration
We can create a table byusing the GUI or by writing SQL Statement.
http://www.sapyard.com/abaponsaphanapartvii/

8/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

a) Create using SQL Statement

create column table "<Schema_name>"."ZZSTUDENT"( "ROLLNUMBER" NVARCHAR (10) not null,


"NAME" NVARCHAR (10) ,
"YEAR" NVARCHAR (4) );

Our schema name was SYSTEM. So, out SQL looks like below.

create column table "SYSTEM"."ZZSTUDENT"( "ROLLNUMBER" NVARCHAR (10) not null,


74
Shares "NAME" NVARCHAR (10) ,
"YEAR" NVARCHAR (4) );

Hopefully, you know by now that you need to be in SAP HANA Development
Perspective and choose your schema and write at the SQL Console. When you
hit execute, the table is created.
b) Create using GUI
For GUI Click on New Table and for SQL Script above Click on Open SQL
Console

http://www.sapyard.com/abaponsaphanapartvii/

9/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

Both (SQL and GUI) achieve the same function of creating the table

http://www.sapyard.com/abaponsaphanapartvii/

10/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Hit execute button

The tables that are created will be available in the respective Schema.
74
Shares

CREATE COLUMN TABLE "<SCHEMA_NAME>"."ZZENROLL"( "CODE" NVARCHAR (10) NOT NULL,


"ROLLNUMBER" NVARCHAR (10) NOT NULL,
"YEAR" NVARCHAR (4) );

CREATE COLUMN TABLE "<SCHEMA_NAME>"."ZZCOURSE"( "CODE" NVARCHAR (10) NOT NULL,


"NAME" NVARCHAR (10));

With the above statements, we have created Column tables (ZZENROLL,


ZZCOURSE), along with these, we can also create a Table Type
(LT_OUT)and Row storage tables.
http://www.sapyard.com/abaponsaphanapartvii/

11/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

CREATE TYPE "<SCHEMA_NAME>"."LT_OUT" AS TABLE ( "STUDENT_NAME" VARCHAR (10) NOT NULL,


"COURSE_CODE" VARCHAR (10),
"COURSE" VARCHAR (10));

74
Shares

Some examples of ALTER TABLE


a) Adding new eld

ALTER TABLE "<SCHEMA_NAME>"."ZZSTUDENT" ADD ("CITY" VARCHAR (10) NULL);

b) Altering/Changing eld type

ALTER TABLE "<SCHEMA_NAME>"."ZZSTUDENT" ALTER ("CITY" VARCHAR (30) NULL);

Changed type from 10 VARCHAR to 30 VARCHAR.


c) Altering Table Type

ALTER TABLE "<SCHEMA_NAME>"."ZZSTUDENT" ALTER TYPE ROW;

http://www.sapyard.com/abaponsaphanapartvii/

12/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

Insert Data into table


Data can be inserted using SQL Console. Below are some examples:

INSERT INTO "<SCHEMA_NAME>"."ZZSTUDENT" VALUES ( '10', 'SACHIN', 'MUMBAI');

INSERT INTO "<SCHEMA_NAME>"."ZZCOURSE" VALUES('100','HINDI');


INSERT INTO "<SCHEMA_NAME>"."ZZCOURSE" VALUES('200','ENGLISH');
INSERT INTO "<SCHEMA_NAME>"."ZZCOURSE" VALUES('300','MATHS');

INSERT INTO "<SCHEMA_NAME>"."ZZENROLL" VALUES ( '100', '10', '2005');


INSERT INTO "<SCHEMA_NAME>"."ZZENROLL" VALUES ( '200', '10', '2005');
INSERT INTO "<SCHEMA_NAME>"."ZZENROLL" VALUES ( '300', '10', '2005');

SQL query examples


Lets us see some of the SQL Query Examples on the above data which we
have populated.
a) Lets start with a simple query

SELECT NAME
http://www.sapyard.com/abaponsaphanapartvii/

13/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

FROM "<SCHEMA_NAME>"."ZZSTUDENT"
WHERE ROLLNUMBER = '10';

74
Shares

b) Nested Select or Select inside a Select (name of students who have enrolled
for course code 100)

SELECT NAME
FROM "<SCHEMA_NAME>"."ZZSTUDENT"
WHERE ROLLNUMBER IN (SELECT ROLLNUMBER
FROM "<SCHEMA_NAME>"."ZZENROLL"
WHERE CODE = '100');

http://www.sapyard.com/abaponsaphanapartvii/

14/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

c) A join example

SELECT A.NAME AS STUDENT_NAME,


B.CODE AS COURSE_CODE,
C.NAME AS COURSE
FROM "<SCHEMA_NAME>"."ZZSTUDENT" AS A
INNER JOIN "<SCHEMA_NAME>"."ZZENROLL" AS B
ON A.ROLLNUMBER = B.ROLLNUMBER
INNER JOIN "<SCHEMA_NAME>"."ZZCOURSE" AS C
ON B.CODE = C.CODE
74
WHERE C.CODE = '100';
Shares

These are very basic examples, only for the concept. In real time it would not be
this simple. Hope the above examples give you a hang of SQLScript. It might
be a little different for ABAPers but it is not entirely from another planet. We
http://www.sapyard.com/abaponsaphanapartvii/

15/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

have been writing Open SQL in ABAP and the above SQL Scripts are our
nearest cousins. Nothing to be scared of.
Also Read :All you wanted to know aboutCDS Views
Stored Procedure
Stored Procedure is the natural choice for the next topic as SQL Script is the
only language used for creating Stored Procedures. A procedure is a unit/block
74
Shares of related code that performs a certain task. ABAPers can relate Stored
Procedures as the subroutines or methods (not truly though). The motivation
for having the procedure is reusability.
All the advantages of SQL Scripts are there in Stored Procedures.SAP
HANA procedures help us to put data-intensive complex logic into the
database, where it can be ne tuned and optimized for performance and
return the small result set. Procedures help to control thenetwork and
processor load by not transferring large data volume from database layer to
application layer. Stored Procedures can return multiple scalar(single value),
tabular/array result which is not possible in normal SQL. Like in ABAP
programming, local variables can be declared and used in Procedures and
hence we do not need to create temporary tables to be used for storing
intermediate data as in thecase of normal SQL.
General rule
Each statement is to be completed with a semicolon ; and variable
assignment is done using colon :.
An example of Stored Procedure using SQL Console. Please note we need to
create Procedure in SAP HANA Modeler Perspective.

http://www.sapyard.com/abaponsaphanapartvii/

16/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

CREATE PROCEDURE _SYS_BIC.ZZPROCEDURE(


IN IV_CODE NVARCHAR(10),
OUT LT_OUTPUT <SCHEMA_NAME>."LT_OUTPUT")
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER AS

/********* Begin Procedure Script ************/


BEGIN
LT_OUTPUT = SELECT A.NAME AS STUDENT_NAME,
B.CODE AS COURSE_CODE,
C.NAME AS COURSE
74
FROM "<SCHEMA_NAME>"."ZZSTUDENT" AS A
Shares
INNER JOIN "<SCHEMA_NAME>"."ZZENROLL" AS B
ON A.ROLLNUMBER = B.ROLLNUMBER
INNER JOIN "<SCHEMA_NAME>"."ZZCOURSE" AS C
ON B.CODE = C.CODE
C.CODE =:IV_CODE;
END;
/********* End Procedure Script ************/

One can create Stored Procedure with the help of GUI. This is much faster
and one tends to have less number of human error.
Right click on content -> select the Procedure
http://www.sapyard.com/abaponsaphanapartvii/

17/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

Put the SQL Script (same as above) in between BEGIN and END (ideally
Output and Input Parameters should be created).
Create the output parameters: Right click on Output, Input Parameters
and declare the name and types.

http://www.sapyard.com/abaponsaphanapartvii/

18/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

Click on save and validate


http://www.sapyard.com/abaponsaphanapartvii/

19/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Click on activate

74
Shares

To test the procedure created above, we need to call the procedure in theSQL
Console. Generic syntax for calling procedure is below.

CALL PROCEDURE_NAME (values1, values2 ,......);

For our example

CALL ZZPROCEDURE(100,?)

Food for thought: Check what error we get if we just write below SQL
without ? as second parameter.

http://www.sapyard.com/abaponsaphanapartvii/

20/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

CALL ZZPROCEDURE(100)

Database Procedure Proxy


We have created a procedure in HANA Database. Till now, only the half part
is done. If we want to achieve the Code Push Down Paradigm then the next part
would be calling the procedure in SAP ECC. This is achieved using Database
Procedure Proxy.
74
Shares

Go to File -> New -> Others -> Database Procedure Proxy.

http://www.sapyard.com/abaponsaphanapartvii/

21/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

Provide the HANA Procedure name.

http://www.sapyard.com/abaponsaphanapartvii/

22/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

ZZ12MYDBPROXY is the name of the proxy. Choose the transport or save as


local.

http://www.sapyard.com/abaponsaphanapartvii/

23/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

Click on nish

Click on Activate button as shown below

http://www.sapyard.com/abaponsaphanapartvii/

24/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

74
Shares

The same Database Procedure Proxy can be displayed in SE24 at ABAP AS


level.

Calling this Database proxy is very much similar to calling a function


module/method.
http://www.sapyard.com/abaponsaphanapartvii/

25/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

CALL DATABASE PROCEDURE ZZ12MYDBPROXY


EXPORTING iv_code = p_code
IMPORTING lt_out = tb_output.

Sample program to consume the HANA Stored Procedure in ABAP and


display the output.

**---------------------------------------------------------------------*
**TYPES*
74
Shares **---------------------------------------------------------------------*
TYPES:

BEGINOFty_output,
student_nameTYPEchar10,
course_codeTYPEchar10,
courseTYPEchar10,
ENDOFty_output.

**---------------------------------------------------------------------*
**DATA*
**---------------------------------------------------------------------*
DATA:
it_outputTYPETABLEOFty_output.

**---------------------------------------------------------------------*
**SELECTIONSCREEN*
**---------------------------------------------------------------------*
SELECTION-SCREENBEGINOFBLOCKb1WITHFRAMETITLEtext-s01.
PARAMETERS:p_codeTYPEchar10.
SELECTION-SCREENENDOFBLOCKb1.

**---------------------------------------------------------------------*
**START-OF-SELECTION.*
**---------------------------------------------------------------------*
START-OF-SELECTION.
*ConsumethestoredprocedureinABAP
PERFORMcall_db_procedure.

http://www.sapyard.com/abaponsaphanapartvii/

26/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

**---------------------------------------------------------------------*
**END-OF-SELECTION.*
**---------------------------------------------------------------------*
END-OF-SELECTION.
*Displaytheoutput
PERFORMdisplay_output.

**&---------------------------------------------------------------------*
**&SUBROUTINES
**&---------------------------------------------------------------------*

74
*&---------------------------------------------------------------------*
Shares
*&FormCALL_DB_PROCEDURE
*&---------------------------------------------------------------------*
*Consumethedatabaseprocedure
*----------------------------------------------------------------------*
FORMcall_db_procedure.

*CalllingDatabaseProcedure
CALLDATABASEPROCEDUREzz12mydbproxy
EXPORTING
iv_code=p_code
IMPORTING
lt_output=it_output.

ENDFORM.

*&---------------------------------------------------------------------*
*&FormDISPLAY_OUTPUT
*&---------------------------------------------------------------------*
*DisplaytheReport
*----------------------------------------------------------------------*
FORMdisplay_output.

*Displaytheoutput
cl_demo_output=>display_data(it_output).

ENDFORM.

Let us test it.


http://www.sapyard.com/abaponsaphanapartvii/

27/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Output
74
Shares

We showed Database Proxy is one way to consume Stored Procedure in


ABAP. The other way is calling it through Native SQL. Let us extend this long
post a little longer. This is the last part, trust me.
Consumption of HANA Stored Procedure in ABAP
Two methods of consuming HANA Stored Procedure in our ABAP
programming are:

http://www.sapyard.com/abaponsaphanapartvii/

28/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

i) Calling SAP HANA Stored Procedure through Native SQL


ii) Using Database Procedure Proxy to expose HANA Procedure (already seen
above)
Both has pros and cons, but Database proxy has an upper hand over the
native SQL.
So-called Advantage of Native SQL process over Database Proxy
74
Shares

a) Easy development and lesser effort. Once we have the stored procedure
created in the HANA DB, we just need to write native SQL to access the
procedure directly.
b) No extra ABAP artifact means less maintenance. Since there is no other
ABAP artifact to be created (like Database Proxy), less maintenance in this
case
c) Native SQL Development can be done in SAP GUI as well as ADT, whereas
for DB proxy has to be done via ADT only
The advantage of Database Proxy over Native SQL process
a) Native SQL Process is a little tedious and prone to human error.
b) Full advantage of ABAP Development Tool can be taken for Database
Proxy.
c) ABAP developers would nd Database Procedure Proxy call similar to
Function Module/Method calls. Hence more comfortable.
d) In thecase of anychange in Database Procedure the code changing
process is manual. But for proxy it is semi-manual and the proxy can be
synchronized (merged/deleted).
We have just scratched the surface. We need to dig a little more deeper to
appreciate the power of SQL Script and Store Procedures. We can have a

http://www.sapyard.com/abaponsaphanapartvii/

29/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

separate post in detail on consumption of Stored Procedures in ABAP. Also,


we can check how we can debug the procedures.
If you want to get such useful articles directly to your inbox, please
SUBSCRIBE. We respect your privacy and take protecting it seriously.
If you liked this post, please hit the share buttons and like us on facebook.
74
Shares

Please add your comments and criticism below and help us improve. Please
do not hold back!!
Also, check our complete list of ABAP for SAP HANA Tutorials.
About the Author: Mohsin Ahmed Mohammed
Mohsin is a Computer Science Engineer by education and profession, with
more than 10 years of experience in SAP. Currently, he is working at
Capgemini as a Senior Technical Consultant. He loves watching movies and
his favorites in the recent past are Whiplash, Bajirao Mastani. He is very
fond of long drives. Not only does he experiment with ABAP, HANA, OData
etc at work but also experiments at his kitchen with new and crazy recipes.
Find more about him on LinkedIn.

39

Isn't it Fair to Share??


Related Posts:

http://www.sapyard.com/abaponsaphanapartvii/

30/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Related Posts:

74
Shares

Previous post

Next post

7 COMMENTS

http://www.sapyard.com/abaponsaphanapartvii/

31/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

ON "ABAP ON SAP HANA. PART VII. SQL SCRIPT AND SAP HANA STORED PROCEDURE"

szwec | August 30, 2016 at 11:53 am | Reply


Hello
74

Very interesting.

Shares

As an expert in ABAP I do not appreciate this demo. Not due to a bad


quality, I is an excellent demo.
My concern is about SAP concepts: from the begining there was a will
from SAP to be fulle independant of DATABASE. By the way an ABAP
coding could to any database. Thanks a lot to OPENSQL.
With stored procedures I have the feeling to come back 40 years ago:
all stored procedures impact the consistency of the database, they
have an impact on it. How to maintain them? How to make changes
easily?
I may recommend stored procedures when tables are out of SAP data
dictionnary. When it is a work to be done by a schedule jobs. Not for a
requirement asked by endusers on SAP data. What about
authorizations?
Interesting but the focus of this kind of need has to be more accurate.
Best regards
Yann SZWEC
French SAP author in ABAP
http://www.sapyard.com/abaponsaphanapartvii/

32/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

SAP Yard | August 30, 2016 at 2:20 pm | Reply


Dear Yann We are really honoured to see the
comment from an expert like you. Thank you very
much for stopping by and putting your thoughts.
We completely agree with your points. Bottom Up Approach is
74

not recommended.

Shares

We just wanted to deliver the concept so that when we are in


catch-22 situation where we need to consume SAP/Partner
delivered standard procedures/tables, we know how to consume
them using DB Procedure Proxy.
Also some clients may by in SP2 ABAP 7.4 where they cannot use
AMDP. In such rare situation (though I cannot imagine why
would they be not able to upgrade above SP2), for the sake of
theory, they would be compelled to make use for procedures.
Thank you again for your insightful feedback.
For the knowledge and bene t of our Team and Readers, can you
please explain in some more details, why Stored Procedures
should not be used in this modern world.
With Regards,
Team SAPYard.

http://www.sapyard.com/abaponsaphanapartvii/

33/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Venubabu Divvi | September 13, 2016 at 3:14 pm | Reply


Dear folks,
How can we call Stored procedures from non sap to sap.
My stored procedure is created in other database, need to call that
from ABAP program.
74
Shares

How can we achieve thisplease guide me with your thoughts.


Regards,
Venubabu Divvi

SAP Yard | September 14, 2016 at 1:21 pm | Reply


Dear Venu,
To be honest, our team has not come across such requirement.
We do not have the exact answer.
The alternative which we can think is to use ADBC. ADBC
should meet your requirement. Concatenate SQL strings in a
program in ECC and connect to the non-sap system and let the
SQL execute in that system. For little more info on ADBC, please
check the below link.
http://www.sapyard.com/abap-on-sap-hana-part-viii/
We would request the experts to respond to it more accurately.
http://www.sapyard.com/abaponsaphanapartvii/

34/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Do let us know, if you have any answer.


Regards,
Team SAPYard.

SAP Yard | September 14, 2016 at 8:13 pm | Reply

74
Shares

Dear Venu Some more info for you.


Source : SAP HANA HA400 training material.
Stored procedures are not HANA speci c and can be created and
used in any database. How to call the stored procedures in ABAP
code?
Ans: Before ABAP 7.4 is: native SQL.
Using the ABAP Database Connectivity (ADBC) API for this
purpose is preferable because it supports where-used analyses,
exception handling and more. Make sure to double check the
SQL syntax.
You could decide for the top-down approach and create the
stored procedure using the ABAP stack, that is also using native
SQL in an ABAP program. Just concatenate the SQL statements
in the ABAP program and call the class SQL query/methods.
Let us know if you need more info.

http://www.sapyard.com/abaponsaphanapartvii/

35/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Regards,
Team SAPYard.
Venubabu Divvi | September 15, 2016 at 2:28 pm |
Reply
Actual requiremnet is i need to get the
latitude and longitude information by calling stored
74
Shares

procedures.
For this i have a program with google maps but compared
bingo maps google maps is 200% costly and my client is
already using bingo maps in their database to get latitude
and longitude.
So if i can call the stored procedure to the other database
(Ex: SqL Database) that will give the result with latitude
and longitude.
Please give me your support hands to achieve the above
Regards,
Venubabu Divvi
SAP Yard | September 17, 2016 at 1:18 pm |
Reply
Dear Venu You can achieve this using
native SQL or ADBC after connecting to the other
database (eg SQL Database). Assuming that your SAP
system already has link to the other database. Else

http://www.sapyard.com/abaponsaphanapartvii/

36/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

you system infrastructure team need to build this


connection to other database rst (t-code SM59).
We do not recommend to use string to de ne sql
connexion (i.e. not EXEC SQL ENDEXEC), due to
issue maintenance. Use classes instead, it will be
more professional. ADBC has some classes which can
be easily used. Just build the SQL statement to
74
Shares

SELECT data from the Map tables and pass it to


ADBC class.
We have a working code on ADBC in the next article.
Please check this link.
SAP ABAP for HANA. Part VIII ADBC : ABAP
DataBase Connectivity
All the best. Do let us know if you still have any
question.
Regards,
Team SAPYard.

Comment, Criticism, Opinion, Feedback. Please do not


hold back. Share your Thoughts!!
http://www.sapyard.com/abaponsaphanapartvii/

37/38

10/30/2016

ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard

Enteryourcommenthere...

COPYRIGHT 2016 | MH NEWSDESK LITE BY MH THEMES

74
Shares

http://www.sapyard.com/abaponsaphanapartvii/

38/38

You might also like