SQL Scripting & AMDP
SQL Scripting & AMDP
2.if there is complex requirement, the decomposition of the requirement is not possible
3.There is no possibility to write the any control flow logic, Orchestration logic inside of view
4.SQL queries always return one result, changing of results are not possible or possible to some extent.
5.Not possible to handle any impressive logic. (Complex looping, Sorting, Searching etc.)
SQL Scripting: -
The purpose is to give procedural capabilities to SQL. It allows developers to write data intensive
logic inside of core DB. This is one of the techniques to achieve the code-to-data paradigm.
Types of statements:
a.The HANA system comes out of the parallelization when the logic Is written in the
imperative logic.
--Q1
--Q2
Lt_sales = select * from snwd_so where product_id in ( select prod_id from :lt_product);
--Q3
Lt_pruchase = select * from snwd_po where product_id in ( select prod_id from :lt_products);
--Q4
1. Split the code where the logic which can be processed in parallel move-in to the separate
container.
2. Put all the imperative logic at the end of container.
Funda fox:
3. when we use a variable in SQL script, we have to put a colon before that (:).when you are assigning
E.g :
Declare x integer;
Declare y integer;
Y = :x;
E.g x :=5;
BINARY: VARBINARY
a. Scalar
What is containers?
Ans: Container is nothing but block of SQL Script code. There are three type of container blocks
End;
E.g.: do (IN x integer => ? , IN y integer => ? ,OUT z integer => ?) begin
z := x + y;
select z from dummy;
end;
Disadvantages of Anonymous SQL Block:-
a.Cannot be used for the productive purpose
b.Bad Maintenance
c.Every time system run’s, it compiles it.
b. Stored Procedure: It is anonymous block which is pre-compiled and stored in DB
permanently. It can be reused by other containers. It can also accept IN, OUT, INOUT
parameters.
DELETE:
Syntax:
Syntax :
Syntax:
declare n integer = 0;
declare exit handler for sql_error_code 10001
select ::sql_error_message from dummy;
if x = 0 then
signal sql_error_code 10001 set message_text = 'Enter the value greater than 1';
end if;
if n > 0 then
declare i integer = 0;
for i in 1..x do
n = :n + 1;
insert into Employee values ( n, 'Employee ' || n);
end for;
else
declare y integer = 0;
create table Employee( EmployeeId integer , EmployeeName Varchar(100), primary
key(employeeId));
for y in 1..x do
end if;
end;
Table Types :
Table Type is a template of a table structure which can hold data( multiptle records) @runtime like
internal table.
Array: -
Syntax: -
Question:
Ans: No.
Array example :-
create procedure arrayDemo (in idx integer, out ret integer)
LANGUAGE SQLSCRIPT
AS
BEGIN
ret = :tableOfTwo[:idx];
--NO
END;
create procedure calculateTable (in num integer, out ret table(num integer))
LANGUAGE SQLSCRIPT
AS
BEGIN
declare i integer := 1;
for i in 1..10 do
calc[:i] = :i * :num;
end for;
--NO
END;
Cursor:
Cursors are used to fetch data from DB tables , they are actually a named query. Whenever a cursor
Is created, it is assigned /bound to a query. It is possible to also pass parameters to the query.
It is one of the containers used to define reusable code in SQL Script. Functions always return
One value.
area decimal as
begin
end;
Use case: return the list of all the customers from snwd_bpa
Example:
begin
return select bp_id, company_name, currency_code from sapabap1.snwd_bpa where bp_role = '1';
end;
**Note UDF can be called only using the select query. We cannot call the UDF using CALL Statement
Procedures Functions
Procedures are called by call statements Functions are always called by SQL
statemets
You can never call procedures in SQL queries They can be called also directly with
assignment operator
CircleArea = calculArea(10);//SPS 9
We have INOUT parameters in procedure Cannot have INOUT parameters
It can return multiple values Always returns one value either scalar
or table