D-Code Presentation - Building ABAP Applications Using Code Pushdown
D-Code Presentation - Building ABAP Applications Using Code Pushdown
Public
Disclaimer
This presentation outlines our general product direction and should not be relied on in making a
purchase decision. This presentation is not subject to your license agreement or any other agreement
with SAP. SAP has no obligation to pursue any course of business outlined in this presentation or to
develop or release any functionality mentioned in this presentation. This presentation and SAP's
strategy and possible future developments are subject to change and may be changed by SAP at any
time for any reason without notice. This document is provided without a warranty of any kind, either
express or implied, including but not limited to, the implied warranties of merchantability, fitness for a
particular purpose, or non-infringement. SAP assumes no responsibility for errors or omissions in this
document, except if such damages were caused by SAP intentionally or grossly negligent.
&&
Database
Common Semantics for
Abstraction
SQL
Layer
&&
More than
the subset
of all SQL like syntax
databases
© 2014 SAP SE or an SAP affiliate company. All rights reserved. Public 5
What is missing in Open SQL ?
No Expressions
&&
Limited Join types
&& No UNIONS, …
Expressions
© 2014 SAP SE or an SAP affiliate company. All rights reserved. 7
Host Variables and Literals
DATA: lv_user TYPE c LENGTH 10. • Host Variables and Literals can be
used in the projection list.
SELECT node_key,
@sy-datum, • Host Variables have to be escaped
@lv_user AS username, with an @.
'X' AS value
• Use Case:
FROM snwd_so
INTO @ls_workarea. Set reasonably default values and
ENDSELECT. thus transfer logic from the
application server to the database.
Be consistent !
SELECT @sy-datum,
so_id, Case-Expression illustrated by an
CASE lifecycle_status example.
WHEN 'N' THEN 'New'
WHEN 'P' THEN
CASE billing_status
WHEN 'P' THEN 'Paid'
ELSE 'Pending'
END
ELSE 'Undefined'
END FROM snwd_so
INTO TABLE @my_table.
SELECT so_id,
COALESCE( partner~company_name, 'N/A' )
FROM snwd_so AS so
LEFT OUTER JOIN snwd_bpa AS partner
ON so~buyer_guid = partner~node_key
INTO TABLE @so1.
Expressions
ABAP Class: ZCL_DEV263_SQL_EXAMPLES
Types of Arithmetic Expressions
Integral Arithmetic
||
Expressions
Decimal
||
Arithmetic
Expressions
Floating Point
Expressions
Integral Arithmetic
Expressions
Decimal Arithmetic
Expressions
Works with all packed numbers with decimals, mixed with Integer
and packed numbers without decimals.
+, -, *, ABS, FLOOR, CEIL
Floating Point
Expressions
Works only with FLOAT columns / host variables, you can not mix.
+, -, *, /, ABS, CAST
SELECT
CASE address_type • Spaces are trimmed away from
WHEN '01' columns and host variables,
THEN postal_code && '->' && ' ' && city except if you use an ABAP
constant which contains exactly
WHEN '02'
one space.
THEN city && ',' && postal_code
END
FROM snwd_ad
INTO TABLE @my_table.
SELECT … FROM
( snwd_so AS so1
LEFT OUTER JOIN snwd_bpa AS p1 • Joins can be enclosed in brackets
ON so1~buyer_guid = p1~node_key • Arbitrary nesting of joins
AND so1~lifecycle_status = 'N')
INNER JOIN
( snwd_so AS so2
LEFT OUTER JOIN snwd_bpa AS p2
ON so2~buyer_guid = p2~node_key
AND so2~lifecycle_status = 'X')
ON so1~node_key = so2~node_key
INTO TABLE @so1.
= 50
= 50
© 2014 SAP SE or an SAP affiliate company. All rights reserved. Public 22
Demo && Exercise 1
Arithmetic Expressions, Joins
Demo ABAP Class: ZCL_DEV263_SQL_EXAMPLES
Let’s take a “View” Visit DEV 202 Core Data Services – Next Generation
Data Definition and Access on SAP HANA
HANA XS
Java
…
ABAP
Where we started:
Limited functionality:
• No outer Joins
• No complex Joins
SE11 View • No inline comments
Definition • No unions
• No View on View
• ….
© 2014 SAP SE or an SAP affiliate company. All rights reserved. Public 26
CDS Entities / CDS Views
not saved
Define Ddl Source: save, write to
@AbapCatalog.sqlViewName: R3TR DDLS
'V_DDTEST_SDDL_SO‚ transport order
/* Demo View */
// on Sales Order table
define view saved
e_ddtest_sddl_so
as select from snwd_so
{ node_key,
so_id, … activate and generate
}
active
REPORT ZDEMODDLS.
export
DB
@AbapCatalog.sqlViewName: 'V01'
define view z_view_01 as • Select *: select all columns
select * from swnd_so
@AbapCatalog.sqlViewName: 'V02'
define view z_view_02 as • Comma separated list of names,
select gross_amount, net_amount as net optional alias names with keyword
from snwd_so
AS
@AbapCatalog.sqlViewName: 'V03' • Alternative Syntax, select list after
define view z_view_03 as from clause enclosed in curly braces
select from snwd_so
{ gross_amount, {….}
net_amount as net }
@AbapCatalog.sqlViewName: 'V04'
define view z_view_04 as • Literal Values
select gross_amount as gross,
'Amount Values' as descr, Only C-Sequence Literals
2147483647 as value (Max length 1333 )
from snwd_so and signed integer Literals (4-Byte)
@AbapCatalog.sqlViewName: 'V05'
define view z_view_05 ( gross, descr, value )
as select gross_amount, • List of names as part of the view
'Amount Values', signature
2147483647
from snwd_so
@AbapCatalog.sqlViewName: 'V06'
define view z_view_06 as
• View Entity z_view_06 defined on
select gross_amount, net_amount table SNWD_SO
from snwd_so
@AbapCatalog.sqlViewName: 'V07'
define view z_view_07 as • View Entity z_view_07 defined on
select gross_amount as gross, View Entity z_view_06
net_amount as net
from z_view_06
@AbapCatalog.sqlViewName: 'V10'
define view z_view_10 as • CASE can be nested
select from qlast_sddl_so
{ • Generally, expressions can be
so_id,
buyer_guid,
nested
case lifecycle_status
• But only certain types of
when 'N' then 'New'
when 'P' then expressions
case billing_status allowed in certain positions
when 'P' then 'Payed'
else 'Open'
end
when 'C' then 'Closed'
else 'Canceled'
end as status_txt
}
@AbapCatalog.sqlViewName: 'VA01'
define view z_viewa_01 as String functions:
select from qlast_sddl_bpa
{ • LPAD(arg1, targetlen, arg2)
lpad( bp_id, 13,'0' )
as bp_role_id, • SUBSTRING(arg, startpos,
email_address
} targetlen)
@AbapCatalog.sqlViewName: 'VA01'
define view z_viewa_01 as Arithmetic functions:
select from qlast_sddl_so
{ • CEIL(arg)
so_id as id,
ceil( gross_amount ) • MOD(arg1, arg2)
as gross_amount_rounded_up
}
• Supported operands:
@AbapCatalog.sqlViewName: 'V10'
define view z_view_10 as Literal, column, path expression,
select from snwd_so build-in function, arithmetic
{ expression
currency_code,
gross_amount as original_amount, • Supported types in abap
cast( gross_amount as abap.fltp) +
(cast( -gross_amount as abap.fltp) * 0.03) namespace:
as reduced_amount,
cast( gross_amount as abap.fltp) * 0.03 char( len ), clnt, cuky( len ), curr(
as savings len, decimals ), dats, dec( len,
} decimals ), fltp, int1, int2, int4,
lang, numc( len ), quan( len,
decimals ), tims, unit( len )
• No nesting of CAST expressions
© 2014 SAP SE or an SAP affiliate company. All rights reserved. Public 36
CDS: Arithmetic expressions
@AbapCatalog.sqlViewName: 'V11'
define view z_viewa_11 as • Supported operators: +, - , * and unary -
select from qlast_sddl_so
{ • Complex expressions and
so_id, bracketing of sub expressions possible
buyer_guid,
net_amount + tax_amount
as gross_amount,
cast(net_amount as abap.fltp) * 0.8
as discount,
-tax_amount
as negative_tax
}
Write your own SQLScript procedures and access them from ABAP
Take advantage of the comfort offert by the ABAP Language, its IDE
and lifecycle management
sql->execute_ddl(
`CREATE PROCEDURE myproc (IN p_val1 char(10)) AS BEGIN `
&& `SELECT val2 FROM mytab WHERE val1 = :p_val1 ; END ` ).
sql->execute_procedure( proc_name = 'myproc' ).
Yes, but after the first 100 lines of plain SQLScript source code you might
want something else …
and let HANA SQLScript source code benefit from the existing
ABAP development tools and lifecycle management
interfaces if_amdp_marker_hdb.
All parameters are passed as value
methods my_first_dbproc
importing value(im_param1) type type1 default 1234
exporting value(ex_param2) type type2
changing value(ch_param3) type type3.
Default values for importing parameters
endclass.
ADT recognizes this method as AMDP method and highlights the background (if configured).
Hovering over the red icon or looking at “Problems” gives more details.
Database tables and AMDP methods have to be declared in the “using” clause and
objects declared in the “using” clause have to be referenced in the SQLScript body.
Referenced objects from the Data Dictionary & AMDP methods must
be listed in the USING clause
ABAP methods: part of the ABAP load once they are generated
Like any method call, AMDP method calls may fail. Typical errors are:
• Invalid parameters at runtime
• Syntax errors in SQLScript after changes in used objects
• Errors during (re-)creation of database procedures
Execute (F8)
DBPROC_3 Try a negative value and execute (F8)
AMDP
• Technical requirements
• Syntax check
Products
Address
Sales Order
Business
Items
Sales Order Partner /
Header Customer
Objects outside SAP<SID> are not under the control of AMDP and
therefore not part of the USING clause. They can be referenced, but
need to be available at runtime.
Only the last category needs the HANA in the development system!
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an
SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE
(or an SAP affiliate company) in Germany and other countries. Please see http://global12.sap.com/corporate-en/legal/copyright/index.epx for additional trademark
information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP SE or its
affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE or
SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing
herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or
release any functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future
developments, products, and/or platform directions and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for
any reason without notice. The information in this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-
looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are cautioned not to place
undue reliance on these forward-looking statements, which speak only as of their dates, and they should not be relied upon in making purchasing decisions.