Professional Documents
Culture Documents
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
SAP YARD
TUTORIALS
CODE SNIPPETS
HELP FORUM
SAP QUIZ
74
Shares
Enteremail
Subscribe
SEARCH
http://www.sapyard.com/abaponsaphanapartvii/
HA400
Follow@sapyard
1/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
SAPYard
656likes
Liked
Youand2otherfriendslikethis
74
Shares
Abapinho
7MostPopular&FeaturedArticles
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.
Fiori App - An
Zero
Introduction from an
ABAPer
SAP HANA at Ground
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.
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).
NOVEMBER 5, 2014
NOVEMBER 3, 2014
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
http://www.sapyard.com/abaponsaphanapartvii/
7/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
74
Shares
8/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
Our schema name was SYSTEM. So, out SQL looks like below.
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
The tables that are created will be available in the respective Schema.
74
Shares
11/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
74
Shares
http://www.sapyard.com/abaponsaphanapartvii/
12/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
74
Shares
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
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
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
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 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)
http://www.sapyard.com/abaponsaphanapartvii/
21/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
74
Shares
http://www.sapyard.com/abaponsaphanapartvii/
22/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
74
Shares
http://www.sapyard.com/abaponsaphanapartvii/
23/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
74
Shares
Click on nish
http://www.sapyard.com/abaponsaphanapartvii/
24/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
74
Shares
25/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
**---------------------------------------------------------------------*
**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.
27/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
Output
74
Shares
http://www.sapyard.com/abaponsaphanapartvii/
28/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
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
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
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"
Very interesting.
Shares
32/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
not recommended.
Shares
http://www.sapyard.com/abaponsaphanapartvii/
33/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
34/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
74
Shares
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
37/38
10/30/2016
ABAPonSAPHANA.PartVII.SQLScriptandSAPHANAStoredProcedureSAPYard
Enteryourcommenthere...
74
Shares
http://www.sapyard.com/abaponsaphanapartvii/
38/38