ZS4HCDS Complete PDF
ZS4HCDS Complete PDF
Welcome
to the
Day 1
Unit 1 Introduction – Technical Concepts, ADT Exercise 01 Exercise 02
Lunch Break
Unit 3 Core Data Services: SQL Features Exercise 05 Exercise 06 Exercise 07 Exercise 08
Day 2
Unit 4 Advanced Concepts in CDS Exercise 09 Exercise 10 Exercise 11
Lunch Break
Day 3
Unit 6 Virtual Data Model (VDM) Exercise 14
Lunch Break
A7 Miscellaneous
Partitioning
64bit address space –
4 TB in current servers No Aggregate Tables
Dramatic decline in
price/performance
+ Insert Only on Delta
+ ++
Past: Now:
Still to be considered:
Data transfer via network Application Server Data transfer via network
CPU
Core
CPU Cache
CPU waiting for data to be
loaded from memory into cache
Main Memory
Performance bottleneck in the
past: Disk I/O
Disk
Two Challenges
1. Optimize loading data into the CPU cache
Introduce columnar data storage
Use compression for database tables
Logical Table
Compressed
Order Country Product Sales Dictionary column
456 France corn 1000 1 Belgium 1 3
457 Italy wheat 900 2 Denmark 2 4
3 France 3 5
458 Spain rice 600
4 Italy 4 4
459 Italy rice 800 5 Spain 5 2
460 Denmark corn 500 6 2
5 entries
461 Denmark rice 600 7 1
3 bits to encode
462 Belgium rice 600 8 4
… …
463 Italy rice 1100
Where was
… … … … order 460?
Full column scans are usually fast enough – far fewer non-unique indexes required
Only if table contains 100 000s of rows consider a non-unique index comprising a single column only
Leads to an “inverted index” in SAP HANA
Create in exceptional
cases only!
Logical Table
Compressed Inverted
Order Country Product Sales Dictionary column index
456 France corn 1000 1 Belgium 1 3 1 7
457 Italy wheat 900 2 Denmark 2 4 2 5,6
3 France 3 5 3 1
458 Spain rice 600
4 Italy 4 4 4 2,4,8
459 Italy rice 800 5 Spain 5 2 5 3
460 Denmark corn 500 6 2 Which orders
5 entries
461 Denmark rice 600 7 1 in Italy?
3 bits to encode
462 Belgium rice 600 8 4
… …
463 Italy rice 1100
Where was
… … … … order 460?
Classical Approach
Calculations
l Application Layer
Data Layer
Calculations
New Approach
ABAP
applications using SAP HANA
ABAP development guidelines Guidelines
“Storage type” of ABAP tables can be set with SAP ABAP Dictionary
NetWeaver ABAP 7.4. Table
Time: 10 min
ABAP Platform
ABAP for HANA Group: https://jam4.sapjam.com/groups/Fu55Xg4QjvITMyNjFr5dIT
ABAP for HANA on SCN: http://scn.sap.com/community/abap-for-hana
SAP ABAP Development Tools are Eclipse-based; tools based on existing Eclipse frameworks
Common development environment for SAP HANA and ABAP (ADT) going forward
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 29
ABAP Development Tools for SAP NetWeaver – Architecture
ABAP Project
Connection to ABAP system using a Connection to
particular user ABAP System
Access any ABAP repository object
Add frequently used ABAP packages to ABAP Class
Favorite Packages for fast access
Function Pools
ABAP Interface
ABAP
Programs
Debug perspective
Opens when code runs and hits
breakpoint
Step over, into, resume …
as usual
Display variables & tables
Time: 10 min
ABAP Platform
ABAP for HANA Group: https://jam4.sapjam.com/groups/Fu55Xg4QjvITMyNjFr5dIT
See e.g. https://jam4.sapjam.com/wiki/show/gX0f6OS0B0ob4pbzC5mWxl for how you can easily install
ADT and SAP HANA Studio within the SAP network.
ABAP for HANA on SCN: http://scn.sap.com/community/abap-for-hana
Real World
Data Model
ABAP Dictionary
Relational
Database
Departure City
Departure Airport
Arrival Airport
Destination City
H A A
BC_PLANFLI T R R BC_CITAIRP T
Flight Schedule City Airport
Assignment
H
BC_SFLIGHT T BC_CUSTOM T BC_COUNTER T BC_TRAVLAG T
Flight Flight Sales Office Travel Agency
Customer
H
BC_BOOKING T R CR CR
Flight Booking
BC_CARRIER T SCARR
Airline
MANDT CARRID CARRNAME CURRCODE URL
H
BC_PLANFLI T SPFLI
Flight Schedule
MANDT CARRID CONNID AIRPFROM AIRPTO DEPTIME . . .
H
BC_SFLIGHT T SFLIGHT
Flight
MANDT CARRID CONNID FLDATE SEATSMAX SEATSOCC ...
H
BC_BOOKING T SBOOK
Flight Booking
MANDT CARRID CONNID FLDATE BOOKID CUSTOMID COUNTER . . .
Transparent Table
Field
described
by
Data Element
points to
Domain
Classic Data-Centric
Applications Applications
UI Rendering UI Tier
UI & Client Side
Application Logic
UI Application Logic
Data-Centric Logic
SAP HANA
Relational Database
Database Database
Data-To-Code:
Intensive
computations <code>
in APPLICATION
layer
Code-To-Data:
Intensive
computations
in DATABASE
layer
Conceptual Level
Task: Get the id, name and the respective zip code of the home address for all
employees in org-unit ’Development’
Implementation Level
Conceptual Level
Issue: Due to the complexity of SQL, developers are using code instead of SQL
Implementation Level
Code: SELECT * FROM Employee INTO TABLE it_empl WHERE orgunit = 4711. “ I know 4711 is the
LOOP AT it_empl. “ id of the dev unit
WRITE it_empl-id.
WRITE it_empl-name.
SELECT * FROM Addresse INTO TABLE it_addrs WHERE id = it_empl-id.
LOOP AT it_addrs.
IF it_addrs-type = ‘HOMEADDR’.
WRITE it_addrs-zipcode.
ENDIF.
ENDLOOP.
ENDLOOP.
Conceptual Level
Task: Get the id, name and the respective zip code of the home address for all
employees in org-unit 4711
Implementation level
ABAP
CORE DATA SERVICES
</>
Common data model Capture business intend Improved programming model
Semantically rich Reduced complexity For all application domains
Declarative Extending SQL Rich set of build-in functions
Close to conceptual thinking Code pushdown capabilities
The Core Data Services (CDS) are a collection of domain-specific languages and services for defining and
consuming semantically rich data models.
DDL QL DCL
Data Definition Language Query Language Data Control Language
Model and retrieve data on a Consume CDS entities via Define authorizations for CDS
semantic level higher than SQL Open SQL in ABAP views
Extends native SQL means for Fully transparent SQL extensions Modelled and declarative
increased productivity approach
Integrates with classic
authorization concepts
Lifecycle Management
support
CDS ABAP
Proven and consistent ABAP
Lifecycle Management and
extensibility
(S)QL Engine
Highly reusable and extensible CDS
artifacts
Core Data Standard ABAP HANA view deployed during CDS view activation
Services View Transport (CTS)
Only CDS View definition is transported
deploy Only ABAP Development Tools for
SAP HANA
not supported
@AbapCatalog.sqlViewName: 'WDECDS_CONN3ANN'
@ClientDependent: true
@AbapCatalog.compiler.CompareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Flight Connection with ABAP Annotations'
Buffering-specific
@AbapCatalog.Buffering.type: #GENERIC
annotation
CDS View entity @AbapCatalog.Buffering.numberOfKeyFields: 1
@AbapCatalog.Buffering.status: #ACTIVE
Alternative Syntax
@AbapCatalog.sqlViewName:'S4HCDS_SEL_V03'
select list after from clause define view s4hcds_sel_v3 as
Output:
enclosed in curly braces {….} select from sflight
{
fldate as Flightdate,
connid as FlightNumber
}
Duplicates can occur when a key column is not included in the projection list
@AbapCatalog.sqlViewName:'S4HCDS_SEL_V06A' Output:
define view s4hcds_sel_v6a as select from spfli
{
cityfrom
}
The keyword DISTINCT ensures that the result table contains no duplicates:
Output:
@AbapCatalog.sqlViewName:'S4HCDS_SEL_V06B'
define view s4hcds_sel_v6b as select distinct from spfli
{
cityfrom
}
Keywords: Keywords must be all uppercase, all lowercase, or in lowercase with an uppercase initial letter.
Mixed uppercase and lowercase is not allowed.
Names: Names are not case-sensitive. A name can have a maximum of 30 characters.
Literals: Number literals must always be specified in full and a decimal point (.) used as a decimal separator if
necessary. Character literals are enclosed in single quotations marks (').
Comments: Two forward slashes (//) introduce a comment, which continues until the end of the line.
Comments within lines or that span multiple lines are enclosed by the characters /* and */.
Protected Words: Certain keywords are protected and cannot be used as self-defined names.
@AbapCatalog.sqlViewName:'S4HCDS_BOOK'
define view s4hcds_Booking as select from sbook
{
key carrid,
key connid,
fldate,
bookid,
class
}
Open SQL
Create or Tools:
Modify ABAP source editors (SE38, SE24, ADT)
Trace Tools (SQLM, ST05)
REPORT Y_CDS_CONSUMPTION_EXAMPLE.
cl_demo_output=>display_data( lt_result ).
Two ways to get the generated CREATE SQL statement in the database for the CDS view
1. Right Click on the CDS source editor in Eclipse and select “Show SQL CREATE Statement”
2. Open the generated database view in SE11 and select Menu -> Extras -> CREATE Statement
Example:
@AbapCatalog.sqlViewName:'S4HCDS_SEL_V09'
CREATE VIEW "S4HCDS_SEL_V09" AS SELECT
define view s4hcds_sel_v9 as select from
scarr as c "C"."MANDT" AS "MANDT",
{ "C"."CARRNAME" AS "CARRIER",
c.carrname as Carrier, "C"."CARRID" AS "ID"
c.carrid as ID FROM "SCARR" "C"
}
@AbapCatalog.sqlViewName:'S4HCDS_SEL_V09'
define view s4hcds_sel_v9 as select from scarr as c
{
c.carrname as Carrier,
c.carrid as ID
}
Time: 15 min
Reusable and unified view model for all use cases Business
Logic
Efficient development
CDS
BI-Tools OData
Search
ABAP Annotations:
Evaluated by the ABAP Core Data Services framework, namely the ABAP runtime environment itself
Component Annotations:
Evaluated by frameworks of other SAP software components (e.g., ODATA, UI and Analytics)
Defines the client handling when Open SQL is used to access a CDS entity
EndUserText.label:
Defines a human-readable text that is displayed besides input fields or as column headers.
EndUserText.quickInfo:
Defines a human-readable text that provides additional information compared to the label text. The
quickInfo element is used for accessibility hints or the mouse over function.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 100
Example
@AbapCatalog.sqlViewName: ‘S4HCDS_CONN3ANN‘
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.Buffering.type: #GENERIC
@AbapCatalog.Buffering.numberOfKeyFields: 1
@AbapCatalog.Buffering.status: #ACTIVE
@ClientDependent: true
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 101
Take Away Annotations
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 102
Exercise 04: Make the CDS view cross-client
Time: 15 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 103
Unit 3 – Core Data Services: SQL Features
Unit 3 – Core Data Services: SQL Features
Lesson 1 : Expressions and Built-In Functions
CDS Built-in Function Overview
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 109
Arithmetic Expressions
Supported operators
@AbapCatalog.sqlViewName: 'S4HCDS_SEL_VD12'
+, - , * and unary - define view s4hcds_sel_v12 as select from sbook
{
forcurkey,
Complex expressions forcuram as Amount,
bracketing of sub expressions possible cast( forcuram as abap.fltp )
+ ( cast ( -forcuram as abap.fltp ) * 0.03 ) as
reduced_amount,
cast( forcuram as abap.fltp )* 0.03 as savings
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 110
CASE Expressions
Simple CASE Expression
The projection list can contain columns that are based on a case differentiation
These columns can be named explicitly
Example: The output is list of columns from table SBUSPART resulting TYPE as customer or Travel Agency
based on the TypeCode.
@AbapCatalog.sqlViewName: 'S4HCDS_SEL_VD10'
Supported expressions after define view s4hcds_sel_v10 as select from sbuspart
CASE: columns | built-in functions | {
arithm. expr. | path expr. | parameters buspartnum as ID,
contact,
WHEN: columns | literals | CASE | path expr.
contphono,
THEN: everything but built-in functions case buspatyp
ELSE: everything but built-in functions when 'FC' then 'Customer'
ELSE when 'TA' then 'Travel Agency'
else 'NA'
is optional
end as Type
Resulting column type }
derived from expressions after THEN and ELSE
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 111
CASE Expressions
Searched CASE Expression
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 112
Nested CASE Expression
Example
@AbapCatalog.sqlViewName:‘S4HCDS_SEL_VD11'
Based on the flight details give priority as follows: define view s4hcds_sel_v11 as select from spfli
{
Carrid= AA => Priority 1
carrid,
Carrid= LH and connid =400 => Priority 2 connid,
case carrid
Carrid= LH and connid=except 400 => Priority 3 when 'AA' then 'Prio1'
when 'LH' then
Carrid = others => Priority Unknown
case connid
when '0400' then 'Prio2'
else 'Prio3'
end
else 'Unknown'
end as Priority
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 113
CAST Expression
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 114
Predefined Functions
COALESCE Function
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 115
Predefined Functions
SQL Functions
String functions:
@AbapCatalog.sqlViewName: 'S4HCDS_SEL_VD14'
• CONCAT(arg1, arg2)
define view s4hcds_sel_v14 as select from sbook
• LENGTH(arg) {
• LPAD/RPAD(arg, len, src) lpad ( connid, 13, '0' ) as conn_id, carrid,
ceil ( loccuram ) as amount_rounded_up
• REPLACE(arg1, arg2, arg3) }
• SUBSTRING(arg, pos, len)
Numeric functions:
• ABS(arg), CEIL(arg), FLOOR(arg)
• DIV(arg1, arg2), DIVISION(arg1, arg2, dec)
• MOD(arg1, arg2), ROUND(arg, pos)
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 116
Predefined Functions
Special Functions
@AbapCatalog.sqlViewName: 'S4HCDS_FUNC_D1'
@ClientDependent: true
define view S4hcds_Func_Demo as select from sbook
{
CONCAT( carrid, connid ) as flightno,
fldate, bookid,
CONCAT( CONCAT( SUBSTRING(order_date,5,2), '-'),
SUBSTRING(order_date,1,4) ) as ordermonth,
case smoker
when 'X' then cast(loccuram as abap.fltp)* 1.03
else cast(loccuram as abap.fltp) * 0.98
end as adjusted_amount,
currency_conversion(
amount => loccuram,
source_currency => loccurkey,
target_currency => cast('EUR' as abap.cuky(5)),
exchange_rate_date => order_date ) as euro_amount
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 118
Exercise 05: Enhance the CDS view with Expressions
Time: 15 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 120
Unit 3 – Core Data Services: SQL Features
Aggregate Functions
MAX
MIN
AVG
SUM
COUNT
Can be used as elements with alternate name using AS in the projection list
Require a GROUP BY clause when aggregate functions are used along with other elements in the projection
list
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 124
Aggregate Functions
COUNT
You can calculate the number of rows in the result set @AbapCatalog.sqlViewName:'S4HCDS_SEL_VD16'
using COUNT . define view s4hcds_sel_v16 as
Rows containing only NULL values are included. select from sbook
{
How many Records for booked flights with carrid: LH and count( * ) as booked_flights
}
connid : 0400
where carrid = 'LH' and connid = '0400'
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 125
Aggregate Functions
MIN, MAX, SUM
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 126
Aggregate Expressions
Group By Clause
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 127
Aggregate Expressions
Having Condition
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 128
DEMO
Aggregation
@AbapCatalog.sqlViewName:‘S4HCDS_CUSTAGGR'
@ClientDependent: true
@EndUserText.label: 'Customer With Aggregation Of Miles'
define view s4hcds_Customer_Aggregation
as select from scustom as c
inner join sbook as b on c.id = b.customid
inner join s4hcds_Connection5_Functions as f on b.carrid = f.carrid
and b.connid = f.connid
{
key c.id as id,
c.name,
c.street,
c.city,
c.country,
sum(f.miles) as miles
}
group by c.id, c.name, c.street, c.city, c.country
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 129
Exercise 06: CDS view with Aggregate Expressions
Time: 15 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 130
Unit 3 – Core Data Services: SQL Features
For read access to multiple database tables / views the following options are available:
Combination of several tables (JOIN)
o INNER JOIN vs. OUTER JOIN
Combination of results from several sub-queries (UNION)
o UNION ALL vs. UNION
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 134
INNER JOIN
One row of the left table and one row of the right table are always joined to a common result row - provided that
the JOIN condition is fulfilled.
JOIN Condition: L.X = R.Y
L … X … … R … Y … …
… 1 … … … 3 … …
… 2 … … … 4 … …
… 3 … … … 5 … …
… 4 … … … 6 … …
… 5 … … … 7 … …
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 135
OUTER JOIN
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 136
LEFT OUTER JOIN
One row of a table and one row of another table are always connected to a common result row - provided that
the JOIN condition is fulfilled.
In addition, rows of the left table without matching row in the right table are copied to the query result. The
missing values (from the right table) are filled with NULL values.
… 1 … …
R … Y … …
… 2 … …
… 3 … …
… 3 … …
… 4 … …
… 4 … …
… 5 … …
… 5 … …
… 6 … …
… 7 … …
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 137
RIGHT OUTER JOIN
One row of a table and one row of another table are always connected to a common result row - provided that
the JOIN condition is fulfilled.
In addition, rows of the right table without matching row in the left table are copied to the query result. The
missing values (from the left table) are filled with NULL values.
L … X … …
… 1 … …
R … Y … …
… 2 … …
… 3 … …
… 3 … …
… 4 … …
… 4 … …
… 5 … …
… 5 … …
… 6 … …
NULL NULL NULL NULL … 7 … …
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 138
FULL OUTER JOIN
One row of a table and one row of another table are always connected to a common result row - provided that
the JOIN condition is fulfilled.
In addition, rows of both tables without matching records are copied to the query result. The missing
values (from the other table) are filled with NULL values.
… 1 … …
R … Y … …
… 2 … …
… 3 … …
… 3 … …
… 4 … …
… 4 … …
… 5 … …
… 5 … …
… 6 … …
NULL NULL NULL NULL … 7 … …
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 139
Supported joins in CDS views
Inner Join: Output list of customer and Left Outer Join: Output list of all customer
booking details for booking id = 2406 details with booking id = 2406.
@AbapCatalog.sqlViewName:'S4HCDS_JOIN_V01' @AbapCatalog.sqlViewName: ‘S4HCDS_LJOIN_01’
define view s4hcds_join_v1 as define view s4hcds_ljoin_demo1 as
select from sbook as b select from scustom as c
inner join spfli as p on p.carrid = b.carrid left outer join sbook as b on c.id = b.customid
and p.connid = b.connid {
inner join scustom as c on c.id = b.customid c.name as Customer_Name,
{ c.city as Customer_city
b.customid, c.name, }
b.fldate, p.cityfrom, p.cityto where b.bookid = '00002406'
}
where b.bookid = '00002406'
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 140
Complex Joins – Example CDS view
@AbapCatalog.sqlViewName: 's4hcds_conn2join'
@ClientDependent: true
define view s4hcds_Connection2_Join
as select from spfli as c
inner join scarr as a on c.carrid = a.carrid
inner join sairport as af on c.airpfrom = af.id
inner join sairport as at on c.airpto = at.id
{
key c.carrid,
key c.connid,
a.carrname,
a.currcode as currency,
c.cityfrom, c.cityto, c.airpfrom,
af.name as airpfrom_name,
c.airpto,
at.name as airpto_name,
c.fltime, c.distance, c.distid
} where c.fltype <> 'X' //exclude charter flights
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 141
CDS Views
UNION [ALL] , UNION
• You can combine the result tables of multiple queries using UNION [ALL].
The individual results tables must have the same number of columns.
The corresponding result columns must have compatible data types.
If no name list specified, the column names of the result sets must match
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 142
DEMO
Left Outer Join
@AbapCatalog.sqlViewName: 'S4HCDS_AGCYREV'
define view s4hcds_agency_with_Revenue as
select from stravelag as a
left outer join s4hcds_booking5_Functions as b on a.agencynum = b.agencynum
{
key a.agencynum as id,
a. name,
a. street,
a. city,
a. country,
sum(b.amount) as amount,
b.currency
}
group by a.agencynum, a.name, a.street, a.city, a.country, b.currency
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 143
Exercise 07: CDS view with Inner Join
Time: 10 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 144
Exercise 08: CDS view with Left Outer Join
Time: 10 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 145
Unit 4 – Advanced Concepts in CDS
Unit 4 – Advanced Concepts in CDS
Lesson 1 – Associations
CDS Associations – The Concept
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 151
Association Types
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 152
Using Exposed Associations In CDS Views
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 153
Consuming Associations In Open SQL
Support for path expressions introduced in Open define view S4hcds_Assoc_Demo2 as select from spfli
SQL with ABAP 7.5 association[1..1] to scarr as _scarr
on $projection.carrid = _scarr.carrid
To allow consuming associations in CDS entities
{
Simple path expressions supported, cityfrom, cityto,
without filter expressions spfli.carrid,
Association name prefixed with backslash \ // Exposed association:
_scarr
Supported in all clauses, e.g. field list, }
where, order by, grouping, having …
SELECT FROM S4hcds_Assoc_Demo2
FIELDS cityfrom, cityto,
\_scarr-carrid as carrid,
\_scarr-carrname as carrname,
\_scarr-currcode as currcode
WHERE \_scarr-currcode IN ( ‘USD', ‘EUR' )
ORDER BY \_scarr-currcode INTO TABLE
@data(lt_customer).
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 154
Filtered Associations
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 156
CDS Associations: Advantages
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 157
Exercise 9: CDS View with Association
Time: 10 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 158
Lesson 1: Associations
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 159
Unit 4 – Advanced Concepts in CDS
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 162
Environment Annotation
#SYSTEM_LANGUAGE sy-langu
#USER sy-uname
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 163
Consumption of CDS view with Parameter in Open SQL
Open SQL
SELECT * from S4hcds_Para_Demo5( p_carrid = 'LH' ) into table @data(lt_flight).
NOTE
If the CDS entity is used as a data source of a SELECT statement in Open SQL, this assignment has the
following consequences:
– No explicit actual parameter can be assigned to an input parameter to which the system field sy-mandt was
assigned using #CLIENT. Open SQL always passes (implicitly) the value of sy-mandt
– An explicit actual parameter does not need to be be assigned to an input parameter assigned a different
system field using #SYSTEM_.... If no explicit actual parameter is specified, Open SQL passes the nominal
value of the assigned system field implicitly.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 164
Session Variables
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 165
Exercise 10: CDS View with Input Parameters
Time: 15 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 166
Unit 4 – Advanced Concepts in CDS
Lesson 3 – Extensibility
CDS Views - Extensions
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 170
$extension – Include the base table extensions
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 171
Core Data Services: View Definition
View-on-View Concept
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 172
Data modeling with views
Association
Basic View Basic View
B1 B2
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 173
Hierarchy of views and extension support
Basic View
B1
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 174
Exercise 11: Extend CDS Views
Time: 10 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 175
Unit 4 – Advanced Concepts in CDS
Lesson 4: Data Control Language (DCL)
Do Authorization Checks Conflict With Code-to-Data?
Classic AUTHORITY-CHECKS on
SELECT FROM S4HCDS_FlightBooking_NoDCL
Instance Level FIELDS carrid, connid, SUM( loccuram ), currcode,
Filter DB result using checks in ABAP? \_customer-postcode, \_customer-city,
Benefit of Code-to-Data approach partly lost \_customer-street
Each access to the data has to be checked WHERE custtype = 'B' AND \_customer-country = 'US'
explicitly GROUP BY carrid, connid, currcode, \customer-postcode, …
INTO TABLE @lt_customer.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 179
Data Control Language Overview
Authorization CDS
Check View
<Code> <Code>
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 180
Usage of Declarative DCL Authorizations – Example Scenario
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 181
CDS DCL: Declare Authorizations And Push Checks To Database
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 182
Literal And Aspect Conditions
Literal conditions
– Allows declaring completely new authorizations @EndUserText.label: 'Auto assigned mapping role for …'
define role <role name> {
– Can be combined with aspect conditions
grant select
on S4HCDS_FlightBooking
where
Aspect conditions – for aspect PFCG country = 'US'
Allows reusing existing authorizations based on
or ( carrid ) = aspect pfcg_auth (
authorization objects and PFCG roles
S_CARRID, -- Authorization object
Parameters: CARRID, -- Matched auth. object field
– LHS: list of view fields to be matched against ACTVT = '03' –- Fixed auth.object field
authorization object fields );
– RHS: classical authorization object and list of }
authorization object fields
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 183
Most Important Annotations For Access Control Objects
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 184
Runtime Behavior
During runtime the SELECT statement for a CDS view will automatically be enhanced with the authorization filter.
DCL DDL
Authorization Object ABAP Data Base CDS View
Interface
View fields
User Profile
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 185
Important Notes About Access Controls
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 186
Naming Conventions and Guidelines for DCL Documents
Naming Conventions
The DCL source name shall be identical to the CDS DDL source name.
The DCL source description shall start with Auto assigned mapping role for
and continue with the name of the CDS view name (Camel Case).
The name of the role inside the DCL source shall be identical to the
CDS view name (Camel Case).
The EndUserText.label shall start with Auto assigned mapping role for
and continue with the name of the CDS view name (Camel Case).
Additional Guidelines
The DCL document has to include the annotation @MappingRole: true.
Only one mapping role definition per DCL source document is allowed.
Other aspects than pfcg_auth shall not be used.
Only one mapping role per CDS view is allowed.
A DCL source document shall always include the mapping
for one CDS view exclusively.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 187
Avoiding Risk of Privilege Escalation
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 188
Testing for DCL
Transaction SACM
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 189
Testing for DCL
Result in Transaction SACM
Used authorizations
of the user
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 190
Demo
Access Control
using CDS DCL
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 195
CDS OData Exposure - Architecture
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 196
SAP Gateway - OData
Consumption of ABAP Artifacts & Implementations
ABAP
OData service can be easily bound to an
SAPUI5 control
Implementation using Open SQL and
AMDP in the generated Classes
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 197
OData
Demo example
@OData.publish: true @AbapCatalog.sqlViewName: 'CDS_VIEW_SAMPLE_EXP'
@OData.publish: true
This annotation is added to the CDS view definition in define view s4hcds_odata_demo as
order to generate all artifacts that are required for select from sbook
OData service exposure.
{ key sbook.carrid,
key sbook.connid,
sbook.fldate,
sbook.loccuram,
sbook.loccurkey
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 198
Lesson 5: OData Exposure
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 199
Unit 5 – New Features in Open SQL
Database SQL-like
abstraction layer syntax
Open SQL
Common NOT the subset of
semantics SQL, common to all
for SQL databases
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 204
What is Open SQL? Why Enhance It?
Open SQL is the only DB abstraction layer that defines a common semantic for all SAP supported databases
Limitations in ABAP < 7.4 SP05 Minimize the limitations
SQL-92 Standard
Standardized Open SQL
(≥ ABAP 7.5)
Open SQL
(before ABAP 7.4)
Support more standard SQL features in Open SQL – for SAP HANA and other database platforms
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 205
What‘s New in Open SQL in ABAP 7.4?
ON conditions extended:
– No field of the right table required in ON condition Table 1 Table 2 Table 3 Table 4
– No longer limited to Equi-Joins
– Fields of the right table usable in WHERE clause of LEFT OUTER JOIN
– Implicit client handling
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 207
New in Open SQL in ABAP 7.5: FROM First, FIELD, INTO Last
INTO clause at the end SELECT carrid, connid, fldate, bookid, customid
For consistency with UNION syntax FROM sbook
Additions such as UP TO … ROWS after INTO WHERE customid = @lv_customer
INTO TABLE @lt_bookings UP TO 10 ROWS.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 208
New in Open SQL in ABAP 7.5: UNION / UNION ALL
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 209
Usage of CDS Association using Path Expressions
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 210
New Features in Open SQL
ABAP expressions
ABAP expressions are set into @( )
SELECT FROM sbook
ABAP expressions are allowed at all input FIELDS carrid, connid, fldate, bookid,
positions customid
ABAP expressions are evaluated before the WHERE customid =
Open SQL statement is executed @( lo_helper->get_customer_id( 'SAP AG' ) )
INTO TABLE @DATA(lt_booking)
UP TO @( lo_helper->get_max_row_count( ) ) ROWS.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 211
New Features in Open SQL
(Partially) dynamic ON clauses
Part conditions can be dynamic like in the
WHERE resp. HAVING clause SELECT s~carrid, s~carrname, p~connid
FROM scarr AS s LEFT OUTER JOIN spfli AS p ON
(dynamic_condition) AND p~cityfrom = p_cityfrom
INTO TABLE @data(lt_result).
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 212
Global Temporary Tables (GTT)
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 213
New Features in Open SQL
INSERT performed in Bulk on Database
INSERT FROM SELECT copies the result set of a INSERT sbook_temp
SELECT statement into the target table FROM ( SELECT FROM sbook
Result set is not transferred to the application FIELDS carrid, connid, fldate, bookid,
server customid, custtype, smoker,
Execution is done completely in the database class, loccuram, loccurkey,
order_date
Can be used to fill global temporary tables
WHERE ( cancelled <> 'X‘
OR cancelled IS NULL )
AND customid = @lv_customer
).
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 214
Further Information
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 215
Exercise 12: New Features in Open SQL
Time: 15 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 216
Exercise 13: Global Temporary Tables
Time: 15 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 217
Unit 6 – Virtual Data Model (VDM)
Lesson 1: VDM Motivation and Architecture
Unit 6 – Virtual Data Model (VDM)
Lesson 1: VDM Motivation and Architecture
What is the Virtual Data Model (VDM)?
VDM is a semantical model of the suite application data, technically expressed in the
language of ABAP CDS views. It is stable, extensible and available for reuse.
SalesOrder Customer
What is this??
VDM
80 000 Tables
(technical, cryptic, unrelated)
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 223
VDM Motivation and Architecture
Harmonized Consumption
Analytics
Fiori apps
OData and openSQL interfaces
openSQL
Unique Semantic Model (VDM)
SalesOrder Customer
Views and fields in business terminology
Explicit relations
VDM
Semantically enriched
SalesOrderItem Material Ready to use
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 224
S/4HANA Runtime Architecture
Overview
VDM
Offers common data and
metadata access for
transactional, analytical,
search and other use
cases
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 225
CDS – The Technical Foundation of VDM
“Virtual”
– refers to the fact that the VDM semantic model
may deviate from the historically grown persistent model of
database tables to make it simpler and easier to
understand
CDS Characteristics
SQL based
Associations express view relations
Annotations define additional metadata
ABAP(any DB) & HANA natively
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 226
CDS VDM Use Cases
The usage of ABAP CDS views following the VDM guidelines is mandatory for the following use cases:
• Any analytical content (e.g. queries, cubes etc. exposed via generic analytical tools like Lumira,
Design Studio)
• New transactional or analytical FIORI applications (following the S4HANA target architecture)
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 227
Example: Virtual Data Model in OData and Fiori UI
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 228
Unit 6 – Virtual Data Model (VDM)
Lesson 2: VDM Layering
S/4HANA CDS-based Virtual Data Model (VDM)
View Types and Layers
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 232
VDM Annotations
@VDM.viewType
Admissible Values: #BASIC, #COMPOSITE, #CONSUMPTION, #EXTENSION
All CDS views shall be annotated explicitly with a VDM view type.
//Example:
@VDM.viewType: #BASIC
define view I_BillOfMaterial as select...
@VDM.private
Admissible Values: #blank (=true), true or false
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 233
Data Category Annotations
@Analytics.dataCategory and @ObjectModel.dataCategory
Business documents, configuration and master data including keys and attributes as
@Analytics.dataCategory: #DIMENSION,
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 234
Annotations to Interface views
Basic views
Consumption views
@VDM.viewType set to #CONSUMPTION
Interface views
Composite views
Composite views
@VDM.viewType set to #COMPOSITE
@Analytics.dataCategory with values #CUBE,
#DIMENSION, #FACT, #TEXT, #HIERARCHY
@VDM.businessObject (to be decided)
Basic views
Database tables
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 235
Annotations to Interface views
Composite and Consumption views
Consumption views
@VDM.viewType set to #CONSUMPTION
Interface views
Composite views
Composite views
@VDM.viewType set to #COMPOSITE
@Analytics.dataCategory with values #CUBE,
#DIMENSION, #FACT, #TEXT, #HIERARCHY
@VDM.businessObject (to be decided)
Basic views
Database tables
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 236
VDM CDS View Layering
Naming Conventions
VDM View Type Private CDS Name Prefix SQL Name Prefix Global Field Name Checks
#CONSUMPTION C_ C X
#CONSUMPTION X P_ P
#COMPOSITE I_ I X
#COMPOSITE X P_ P
#BASIC I_ I X
#BASIC X P_ P
#EXTENSION E_ E X
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 237
Naming Rules for Fields
Field Label
Field Name
• New fieldnames are created according to the Naming Rules for Fields following the described process.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 238
Exercise 14: Virtual Data Model
Time: 10 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 239
Lesson 2: VDM Layering
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 240
Unit 6 – Virtual Data Model (VDM)
Lesson 3: Authorization for VDM
Lesson 3: Authorization for VDM
Learning Objectives
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 245
Basic Principles
Access to data via the Virtual Data Model (VDM) with Core Data Services (CDS) in Suite is always controlled by a combination
of:
• Start authorization check of the consumption domain (e.g. Analytics, ODATA etc.)
Instance based authorizations are derived dynamically during runtime from the user’s PFCG authorizations as single point of
truth.
• Keep the mapping between CDS view attributes and ABAP authorization objects out of code in a DCL.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 246
Start authorization (functional access restriction)
All consumption domains (analytical query, OData service, search, transactional) have to be protected by an explicit start
authorization:
• For generic consumption domains like analytics or OData service the start authorization will be provided by the particular
framework.
It shall never be possible for an end-user to access any CDS view or database table directly with a tool (e.g. a generic data
browser) bypassing the start authorization check.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 247
Instance based authorization – Generic Consumption
ALL CDS views which are allowed as data sources for generic consumption domains (Analytics, ODATA) have be to protected
by a CDS DCL:
• All non-private CDS views enabled as data source for consumption via Analytical Engine (annotation
@Analytics.DataCategory: #DIMENSION, #CUBE or #FACT)
• All non-private CDS views enabled for Odata 1-to-1 exposure (annotation @OData.publish: true).
A CDS view has to include all authorization relevant attributes for defining the DCL in its projection list or in an associated view.
In other words: If a view is not protected by a DCL the annotations @OData.publish: true or @Analytics.DataCategory:
#DIMENSION, #CUBE or #FACT shall not be used.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 248
Instance based authorization – Exceptions
• Hierarchy node views (@Analytics.dataCategory: #HIERARCHY), analytical queries (@Analytics.query: true) and extension
include views (@VDM.viewType: #EXTENSION)
• Views for generic consumption where an instance based access differentiation per user in not required from business
constraints. Example are views defining a list of allowed code values (e.g. unites of measure or list of allowed status codes).
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 249
Annotation @AccessControl.authorizationCheck 1/2
• If the annotation is not used at all in the DDL document a warning will occur when activating the CDS view in ABAP
development tools if no DCL role exists.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 250
Annotation @AccessControl.authorizationCheck 2/2
All CDS views have to be ‘classified’ if a DCL is required in SAP delivery, addable by customer or not allowed at all with the
annotation @AccessControl.authorizationCheck
• @AccessControl.authorizationCheck: #CHECK shall be used for CDS views requiring protection by a DCL role according the
authorization guideline and text views delivered with a DCL role.
• @AccessControl.authorizationCheck: #NOT_REQUIRED shall be used for VDM private views, text views delivered without a
DCL role and generically consumable views which do not require an instance based differentiation per user.
• @AccessControl.authorizationCheck: #NOT_ALLOWED shall be used for hierarchy node views, analytical queries and
extension include views.
A warning message will be shown during activation of the CDS view for:
• CDS Views without the annotation @AccessControl.authorizationCheck if no DCL role exists.
• CDS Views with the annotation @AccessControl.authorizationCheck: #CHECK if no DCL role exits.
• CDS Views with an association to a dictionary view.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 251
Instance based authorization – Coded Consumption
A coded consumption of a CDS view includes any ABAP code with a SELECT statement on the CDS View or any OData Service
consumption besides 1-to-1 exposure.
Recommended: Consumption of a CDS view with a DCL will automatically use the modelled instance based authorization.
Architecture Guideline S/4 HANA [OMP-IAM-8]
Break out: Consumption of a CDS view without a DCL requires to implement a sufficient instance based authorization check like
accessing a table or the SQL view of a CDS view directly.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 252
VDM Authorization Summary
Consumption views
Analytics Search Data retrieval for transactional Application-specific views
start authorization start authorization applications start authorization
start authorization
Instance based authorization check by modeled DCL mapping role for all CDS views*
besides Analytical Queries (annotation @Analytics.query: true)
Interface views
Composite views
Instance based authorization check by modeled DCL mapping role Private views
for all CDS views* besides the hierarchy node views (annotation
@Analytics.dataCategory: #HIERARCHY and text views No authorization check
@Analytics.dataCategory: #TEXT
Basic views
Instance based authorization check by modeled DCL mapping role Private views
for all CDS views* besides the hierarchy node views (annotation
No authorization check
@Analytics.dataCategory: #HIERARCHY and text views
@Analytics.dataCategory: #TEXT
*With the exception where an instance based access differentiation per user in not required from business constraints.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 253
Example: All Authorization Relevant Attributes Included in the
Projection List
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 254
Example: Delegation of Instance Based Checks to Associated Views
Important: Don’t use DCL with path expression for
performance critical CDS views.
A required instance based authorization check can be delegated to an associated view by using in the constrain condition
attributes of the associated view via path notation if the view itself does not contain in the projection list all authorization relevant
attributes.
@MappingRole: true
define role I_SalesOrderItem {
grant select on I_SalesOrderItem
where (_SalesOrder.SalesOrderType) =
aspect pfcg_auth (v_vbak_aat,
auart,
actvt = '03' )
and (_SalesOrder.Division,
_SalesOrder.SalesOrganization,
_SalesOrder.DistributionChannel) =
aspect pfcg_auth ( v_vbak_vko,
spart,
vkorg,
vtweg,
actvt = '03' );
}
Typical use case is sub nodes of a BO sharing the instance based restriction defined for the root node
where the sub nodes themselves do not contain the authorization relevant attributes.
Important:
1. Only path expressions using an association of cardinality to 1 and a CDS View as target data source shall be used in the
conditions of a DCL mapping role.
2. A path expression in a DCL mapping role using an association with a dictionary table or dictionary view as target data source
is not allowed.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 255
Delegation of Instance Based Checks with Parameters
Delegation of instance based checks to associated views with parameters require to pass in the constrain condition with path
notation an actual value for the parameter.
• Literals
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 256
Delegation of Instance Based Checks with Parameters
Literal as Actual Value
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 257
Delegation of Instance Based Checks with Parameters
Forwarding Parameters
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 258
Lesson 3: Authorization for VDM
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 259
Unit 6 – Virtual Data Model (VDM)
Lesson 4: VDM ATC Checks
VDM CDS Development Guideline
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 262
VDM CDS ATC Checks
All VDM ATC checks are based on the metadata captured in the source file of the CDS views.
They are restricted to the CDS views using the view annotations @VDM...
Additionally CDS view names and DDLS file names beginning with the reserved VDM prefixes 'I_', 'E_', 'P_' or 'C_' are
included in the check scope.
The ATC checks are executed on active CDS views only.
In order to reasonably execute the checks, the annotations @VDM.viewType and @VDM.private have to be set
More details can be found here:
https://wiki.wdf.sap.corp/wiki/display/SuiteCDS/VDM+CDS+ATC+Checks
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 263
Lesson 4: VDM ATC Checks
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 264
Unit 6 – Virtual Data Model (VDM)
Lesson 5: SFLIGHT VDM Example
Focus of this Example
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 266
Example based on SFLIGHT
Flight by
Airport
Query
Flight by Flight
Airport
Airport Connection
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 267
Example based on SFLIGHT
D. ZU##_C_AVAILFLIGHTSQ Available
C. ZU##_C_AvailFlightsQ Flights
S. ZU##_CAVFLIGHTQ Query D. ZU##_I_FLIGHTCONNECTION D. ZU##_I_AIRPORT
C. ZU##_I_FlightConnection C. ZU##_I_Airport
S. ZU##_IFCONN S. ZU##_IAIRPORT
D. ZU##_I_FLIGHTBYAIRPORT
Flight
Flight by 0..1 Airport
C. ZU##_I_FlightByAirport Connection carrid
Airport SAIRPORT
S. ZU##_IFLIGHTA SPFLI airpfrom
airpto
DDL Source
CDS View Name
SQL View Name
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 268
Step by Step Creation of #BASIC Views
Step-by-step guide to create your first CDS views I_Airline and I_AirlineText.
Naming conventions for source, CDS view name, SQL view name
Association
© 2016 between the views
SAP SE or an SAP affiliate company. All rights reserved. Internal 269
Airline
@AbapCatalog.sqlViewName: ' S4HCDS_IAIRLINE' -- S4HCDS_ + I + AIRLINE; uppercase
@AccessControl.authorizationCheck: #NOT_REQUIRED -- authorization check via DCL not required
@Analytics.dataCategory: #DIMENSION
-- view is available as dimension view for analytics with analytics engine
@Analytics.dataExtraction.enabled: true
-- this view is a good candidate for extraction of data for a data warehouse
@EndUserText.label: 'Airline' -- label of the view for an end user, can be translated
@ObjectModel.representativeKey: 'Airline'
-- the (most significant) key field, anchor of foreign key associations pointing here
@VDM.viewType: #BASIC -- basic interface view of VDM (virtual data model)
define view S4hcds_I_Airline -- S4hcds_+ I_ + Airline; private prefix + VDM prefix + global term for core entity
-- name should be kept identical with DDL name
as select from scarr -- data source, here a table
association [0..1] to S4hcds_I_Airlinetext as _Text on $projection.Airline = _Text.Airline
-- naming convention for associations: _xyz
-- $projection recommended: can use aliases, avoids name clashes
-- use cardinality [0..*] for language-dependent texts
{
@ObjectModel.text.association: '_Text'-- indicate association to view with (language-dependent) texts
key scarr.carrid as Airline, -- control-space proposes field name from global field name catalog
@Semantics.currencyCode: true -- column semantics: this is a currency code
scarr.currcode as AirlineLocalCurrency,
@Semantics.url -- column is a URL; enables consumers to render it properly
scarr.url as AirlineURI,
_Text -- expose the association to related text view, naming convention _Text
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 270
Airline Name
{
key carrid as Airline,
// @Semantics.language -- usually, texts are language dependent
// key spras as Language, -- with a language column as additional key field
@Semantics.text -- indicate the "text" field in the view; is used as text for representative key field
@EndUserText.label: 'Airline Name‘
-- choose a better enduser label for the column than in DDIC data element defined
carrname as AirlineName
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 271
Airport
@AbapCatalog.sqlViewName: 'S4HCDS_IAIRPORT'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled: true
@EndUserText.label: 'Airport'
@ObjectModel.representativeKey: 'Airport'
@VDM.viewType: #BASIC
{
@ObjectModel.text.element: [ 'AirportName' ]
key sairport.id as Airport,
@Semantics.text
sairport.name as AirportName,
sairport.time_zone as AirportTimeZone
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 272
Aircraft Type
@AbapCatalog.sqlViewName: 'S4HCDS_IAIRCRFTT'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled: true
@EndUserText.label: 'Aircraft Type'
@ObjectModel.representativeKey: 'AircraftType'
@VDM.viewType: #BASIC
{
key planetype as AircraftType,
producer as AircraftManufacturer
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 273
Master and Transactional Data as #BASIC Views
Views I_FlightConnection and I_Flight as examples of #BASIC VDM views for master and
transactional data.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 274
Flight Connections (1)
@AbapCatalog.sqlViewName: 'S4HCDS_IFCONN'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled: true
@EndUserText.label: 'Flight Connection'
@ObjectModel.representativeKey: 'FlightConnection'
-- the (most significant) key field, anchor of foreign key associations pointing here
@VDM.viewType: #BASIC
[..]
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 275
Flight Connections (2)
[..]{
@ObjectModel.foreignKey.association: '_Airline'
key carrid as Airline,
key connid as FlightConnection,
countryfr as CountryFrom, -- here a foreign key association to the country view should be added
cityfrom as CityFrom,
@ObjectModel.foreignKey.association: '_AirportFrom'
airpfrom as AirportFrom,
countryto as CountryTo,
cityto as CityTo,
@ObjectModel.foreignKey.association: '_AirportTo'
airpto as AirportTo,
fltime as FlightDurationInMinutes, -- could be made into a measure as well
deptime as DepartureTime,
arrtime as ArrivalTime,
period as ArrivalDateShiftInDays,
@Semantics.quantity.unitOfMeasure: 'DistanceUnit'
@DefaultAggregation: #SUM -- declares column "Distance" as a measure for analytics
distance as Distance,
@Semantics.unitOfMeasure
distid as DistanceUnit,
_Airline,
_AirportFrom,
_AirportTo
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 276
Flight (1)
@AbapCatalog.sqlViewName: 'S4HCDS_IFLIGHT'
@AccessControl.authorizationCheck: #CHECK
@Analytics.dataCategory: #CUBE -- conceptually this view has data category #FACT
-- but it can only be tested as a #CUBE in the analytics environment
@Analytics.dataExtraction.enabled: true
@EndUserText.label: 'Flight'
@VDM.viewType: #BASIC
{
@ObjectModel.foreignKey.association: '_Airline'
key carrid as Airline,
@ObjectModel.foreignKey.association: '_FlightConnection'
key connid as FlightConnection,
key fldate as FlightDate,
[..]
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 277
Flight (2)
[..]
@Semantics.amount.currencyCode: 'Currency'
@DefaultAggregation: #MIN
price as FlightPrice,
@Semantics.currencyCode
currency as Currency,
@ObjectModel.foreignKey.association: '_AircraftType'
planetype as AircraftType,
@DefaultAggregation: #SUM
seatsmax as MaximumNumberOfSeats,
@DefaultAggregation: #SUM
seatsocc as NumberOfOccupiedSeats,
@Semantics.amount.currencyCode: 'Currency'
@DefaultAggregation: #SUM -- a measure is identified by a default aggregation different from #NONE
paymentsum as CurrentBookingsTotalAmount,
_Airline,
_FlightConnection,
_AircraftType
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 278
#COMPOSITE View
View I_FlightByAirport as example of a #COMPOSITE VDM view that is used as basis for analytics
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 279
Flight (by Airport) (1)
@AbapCatalog.sqlViewName: 'S4HCDS_IFLIGHTA'
@AccessControl.authorizationCheck: #CHECK
@Analytics.dataCategory: #CUBE
@EndUserText.label: 'Flight (by Airport)'
@VDM.viewType: #COMPOSITE
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 280
Flight (by Airport) (2)
[..]
@DefaultAggregation: #SUM
MaximumNumberOfSeats,
@DefaultAggregation: #SUM
NumberOfOccupiedSeats,
@Semantics.amount.currencyCode: 'Currency'
@DefaultAggregation: #MIN
FlightPrice,
@Semantics.amount.currencyCode: 'Currency'
@DefaultAggregation: #SUM
CurrentBookingsTotalAmount,
_Airline,
_FlightConnection,
_FlightConnection._AirportFrom, -- exposure of associations via an association avoids redefinition of the associations
_FlightConnection._AirportTo,
_AircraftType
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 281
Introduction: #CONSUMPTION View
Filter definition
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 282
Query Available Flights (1)
@AbapCatalog.sqlViewName: 'S4HCDS_CFLIGHTAQ'
@Analytics.query: true
@EndUserText.label: 'Available Flights'
//@OData.publish: true
@VDM.viewType: #CONSUMPTION
[..]
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 283
Query Available Flights (2)
[..]
@AnalyticsDetails.query.axis: #ROWS
FlightConnection,
AircraftType,
Currency,
MaximumNumberOfSeats,
NumberOfOccupiedSeats,
@EndUserText.label: 'Available Seats'
@DefaultAggregation: #FORMULA
@AnalyticsDetails.query.axis: #COLUMNS
MaximumNumberOfSeats - NumberOfOccupiedSeats as NumberOfAvailableSeats,
@AnalyticsDetails.query.axis: #COLUMNS
FlightPrice
}
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 284
Unit 7 – HANA Native Code Push Down
Unit 7 – HANA Native Code Push Down
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 288
Stored Procedures – Recap
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 289
Using Stored Procedures in ABAP < 7.40
in p_in1, lr_stmt->execute_procedure(
inout p_inout1 ) `dbproc` ).
ENDEXEC.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 290
ABAP-Managed Database Procedures
Methods of global classes marked with tag interface, available since ABAP 7.4 SP05
AMDP classes and AMDP methods “Top-Down” Lifecycle
Easy to consume in ABAP – as simple method call
AS ABAP
lr_customer->classify( ABAP Standard
EXPORTING in_date = in_date
Managed DB ABAP
in_sel = in_sel
IMPORTING out_itms = out_itms ). Procedure Transport
deploy
AMDP methods are fully managed on the ABAP server
SAP HANA
– Source code editing with ABAP Editor (in ADT)
– Static syntax check and syntax coloring for SQLScript code Stored
Procedure
– Procedure created on first AMDP call
– Detailed analysis of runtime errors in ST22
– Transport analog to regular ABAP classes ABAP Managed Database Procedures
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 291
AMDPs: Integration of Database Procedures Into ABAP
Standard ABAP class methods are used as containers for the implementation of AMDPs
CLASS CL_AMDP_SAMPLE DEFINITION.
PUBLIC SECTION.
INTERFACES IF_AMDP_MARKER_HDB.
...
PRIVATE SECTION.
METHODS execute IMPORTING VALUE(it_param) TYPE type1
EXPORTING VALUE(et_param) TYPE type2.
ENDCLASS.
CLASS CL_AMDP_SAMPLE IMPLEMENTATION.
...
METHOD execute BY DATABASE PROCEDURE …. Method container
-- SQLScript code for an AMDP
ENDMETHOD.
ENDCLASS.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 292
AMDPs: Prerequisites in Class Definition
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 293
Implementation of AMDP Methods
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 294
AMDP Method – SQLScript Example
METHOD classify_by_id
BY DATABASE PROCEDURE FOR HDB
LANGUAGE SQLSCRIPT OPTIONS READ-ONLY
USING SCUSTOM SBOOK.
-- declare local scalar variables
declare lc_upper_threshold constant int := 300;
declare lc_lower_threshold constant int := 10;
-- translate list of customer ids into id, name ,#of flights …
lt_customers = select c.id, c.name, count( s.bookid ) … from scustom …
where mandt = :iv_client
and c.id in ( select id from :it_customer_id )
group by c.id, c.name;
-- calculate return table
et_classification = select id, name,
case when flight_count > :lc_upper_threshold then 1 …
from :lt_customers …
ENDMETHOD.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 295
AMDP Methods – Syntax Error Handling
Summary of errors
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 296
Calling AMDP Methods
...
METHOD process.
me->execute(
EXPORTING it_param = it_param
IMPORTING et_param = et_param
).
ENDMETHOD.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 297
ABAP Managed Database Procedures
Exception Handling
<ERROR_NAME> CX_<ERROR_NAME>
"consumption
TRY.
To-Dos for AMDP Developers/Consumers: <method_call>
– Add RAISING clause to the AMDP method definition
– Enclose the AMDP call in a CATCH cx_amdp_execution_failed INTO DATA(lx).
TRY… CATCH block "do some meaningful error handling
ENDTRY.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 298
Debugging ABAP-managed Database Procedures (with ABAP 7.5)
With ABAP 7.5, AMDPs can be debugged using the ABAP perspective “as usual”, provided:
The Debug perspective is installed properly
The AMDP has been executed before - AMDPs are created on the DB on demand!
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 299
Debugging ABAP-managed Database Procedures (with ABAP 7.5)
Execute program calling the AMDP Debug view opens – with limited features
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 300
Enhancements of AMDP Methods: AMDP BAdIs
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 301
AMDP BAdIs: Use In AMDP Code
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 302
Exercise 15: Implement and Call An AMDP
Time: 20 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 303
Exercise 16: Debug An ABAP-Managed Database Procedure
Time: 10 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 304
Lesson 1: ABAP-Managed Database Procedures
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 305
Unit 7 – HANA Native Code Push Down
Required: Some scenarios require selective measure (“Breakout Scenario” for HANA-only applications)
• Highest performance requirements e.g. with complex calculations
• Use of database / analytical engine specific functions required
• Open SQL and CDS views do not yet offer functionality to solve the problem
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 308
What do CDS Table Functions do?
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 309
Necessary parts for CDS Table Functions
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 310
CDS Table Functions Implemented via AMDP
ABAP/DDIC
ABAP CDS AMDP
Table functions as
„Plain“ CDS- „Breakout“
native HANA
View CDS-View
SQLScript
generates generates
HANA SQL
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 311
Key features of Table functions
• They can be consumed by Open SQL and ABAP CDS like other DDIC artifacts (i.e. DB tables,
classical DDIC views, CDS views ...)
• The SQLScript implementation is handled by the AMDP framework (lifecycle, tool support,
extensibility etc.)
• DDL source can be activated before the implementing AMDP method exists
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 312
Definition of a Table Function
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 313
Implementation of a Table Function (1)
PUBLIC SECTION.
Marker interface
INTERFACES:
if_amdp_marker_hdb.
Method name and link to CDS view
for signature inheritance CLASS-METHODS:
get_flights FOR TABLE FUNCTION
S4HCDS_FlightTableFunction.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 314
Implementation of a Table Function (2)
Implementation is done
in a special tagged method
METHOD get_flights BY DATABASE FUNCTION
FOR HDB
Table functions are read-only LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
Used ABAP managed objects
USING sflights.
ENDMETHOD.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 315
Usage of a Table Function
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 316
Client Handling - Definition
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 317
Client Handling - Implementation
USING sflights.
return select
mandt as clnt
Usage of client input parameter to select connid as ConnectionID,
the correct values from the database fldate as FlightDate
from sflights
where fldate <= :p_FlightDate and
; mandt = :clnt_in
ENDMETHOD.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 318
Lesson 2: CDS Table Functions
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 329
Exercise 17: Implement CDS Table Function
Time: 20 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 330
Further References
Development Guidelines
https://wiki.wdf.sap.corp/wiki/display/fioritech/Development+Guideline+Portal
SAP UI5
http://scn.sap.com/community/developer-center/front-end
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 331
Further References
Gateway
Customer course GW100.
HANA SQL(Script)
ZHA150 SQL Basics for HANA, Unit 10.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 332
You made it! – Thank you!
Contact Information:
Panneer Selvam
SAP Development University
[email protected] or SAP Dev Uni
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 338
String Expressions and String Templates
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 339
Inline Declarations and Constructor Expressions
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 340
Table Expressions
Basic syntax:
READ TABLE <table> INDEX 1 Overview Table LT_OVERVIEW
<table>[ 1 ] PARAM VALUE
READ TABLE <table> WITH KEY … ET_TOP “SCHEMA"."ET_TOP_529…"
<table>[ param = 'ET_TOP' ] ET_BOTTOM "SCHEMA"."ET_BOTTOM_529…"
For more options see documentation
lo_result = lo_sql->execute_query(
|SELECT * FROM { lt_overview[ param = 'ET_TOP' ]-value }
| ).
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 341
Exercise 18: Use Expressions and Inline Data Declarations
Time: 25 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 342
Appendix
Appendix Lesson 2 – Introduction to SAP HANA Studio
SAP HANA Studio – An Eclipse-based Development Environment
Editors, Toolbars …
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 347
Most Relevant Perspective For ABAP Developers: Modeler
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 348
The Systems View
System
Schema
Table
Double-click to
open definition
Right-click to
see data
Information
Models
Users &
Roles
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 349
Connecting to an SAP HANA Database
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 350
Table Definitions
Display SQL
CREATE TABLE
statement
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 351
SAP HANA Content – Packages, Models, Delivery Units
Create packages
under node Content
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 352
Exercise A2: Log on to the SAP HANA Studio
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 353
Appendix
Appendix Lesson 3 – Guided Performance Analysis
Transition ABAP Code in ABAP for SAP HANA
Best Practice
1. Detect
Execute Performance measurements
Analyze and prioritize Detect
2. Optimize
Use new features to optimize existing code
3. Innovate Optimize
Use new features, resources and possibilities
to enhance your business
Innovate
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 357
Guided Performance Optimization – Detect
3 Prioritized Worklist
Combines the static and runtime check
results DEV QAS PRD
Tool: SWLT
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 358
New ABAP SQL Monitor
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 359
The New ABAP SQL Monitor - Architecture
Work Process
SQL Monitor Transaction
Runtime
Async.
Database Interface Monitor Batch
Data Job
Application SQLM
Tables Tables
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 360
Switching the SQL Monitor On and Viewing SQL Monitor Data
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 361
Exporting and Importing SQL Monitor Snapshots
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 362
Demo
SQL Monitor
Which business
What ABAP code could
processes should be
be optimized?
optimized?
The SQL Performance Worklist (SWLT) allows you to correlate SQL runtime
data with ABAP code analysis to plan optimizations.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 364
SQL Performance Tuning Worklist – Usage
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 365
Demo
SQL Performance Worklist
Time: 15 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 367
In-depth Analysis of Performance Issues
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 368
Exercise A4: Improve Performance Using Joins
Time: 10 min
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 372
Lesson A3 – Guided Performance Analysis
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 373
Appendix
Appendix Lesson 4 – VDM Analytical Perspective
Lesson A4: VDM Analytical Perspective
Learning Objectives
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 375
SAP S/4HANA Analytics Architecture
Key-User/Business-User Defined
Fiori UIs SAP BI Tools (Design Studio …) 3rd Party UI/Client Content
Open CDS-based
Views Consumption Views
1 defined by roadmap and depending on deployment option 2 CDS = Core Data Services
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 376
Analytics Vision for SAP S/4HANA
Hybrid, embedded Stand-alone
User Analytical and transactional scenarios using tightly Analytics use cases using BI-tools and analytical apps
Experience embedded Analytics controls for…
Operational/
Simple List Pixel-perfect … transactional
reporting Planning
Multi-
Simple Pixel-perfect KPIs/ In-place
dimensional
List / Chart reporting Dashboards MS Office Multi-
reporting KPIs/ Decision support
dimensional
Dashboards Apps
report
… Rule-based
MS Office Simulation decision
Planning
Application automation and
Application
exception
handling
Consistent Analytical
Personalization, Sharing/Collaboration, Pivoting, Filtering, Office integration, Insight-to-Action,
Features, independent of
Navigation, Role-based access, Printing, …
“embedded” or “stand-alone”
Virtual Data Specific Models (Analytical Queries, Search Models, …) Customer Extensions
Model Virtual Data Model
Customer
For Search, operational and analytical processing Extensions
SAP HANA Platform
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 377
Analytical View Model
@Analytics.dataCategory: #DIMENSION
@ObjectModel.representativeKey: …
I_SalesOrganization
@ObjectModel.text.association: …
Dimension / characteristic key SalesOrganization
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 378
Foreign Key and Text Associations, Representative Key
DIMENSION TEXT
I_Country I_CountryText
rk Country rk Country
@ CountryName
CUBE
I_BillingXYZ
…
Country
Region
DIMENSION TEXT
I_Region I_RegionText
Country Country
rk Region rk Region
@ RegionName
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 379
Analytical CDS Views
Relationships
DB Table
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 380
Analytical Query
Schematic Model
Analytical Query:
Query View Hierarchy View
@Analytics.query
Hierarchy Directory Association
Analytical Network:
Data Source: Foreign Key
@ObjectModel.foreignKey/text/hierarchy.association
Association
@Analytics.dataCategory: #CUBE/DIMENSION
@DefaultAggregation Any View
(optional)
Database Table
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 381
Important Annotations
@Analytics.query
Admissible Values: blank (=true), true, false
Only analytical query views shall be annotated. They all reside in the consumption layer.
Query views shall not carry an analytical data category.
//Example:
@Analytics.query:true
define view C_BillOfMaterialQuery as select...
@Analytics.dataCategory
Admissible Values: #FACT, #DIMENSION, #CUBE, #AGGREGATIONLEVEL
The VDM reuses the analytical data categories for distinguishing texts and hierarchies from core entities.
//Example:
@Analytics:{
dataCategory:#DIMENSION , dataExtraction.enabled:true }
define view C_BillOfMaterial as select...
@ObjectModel.dataCategory
Admissible Values: #TEXT, #HIERARCHY
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 382
Analytical CDS Views
Important Annotations
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 383
CDS Views and Relations
Example: Very simple SFLIGHT model
4 7 2 3
9 6 5
1
: View
: refers to (select from, join, or association)
to)All rights reserved.
© 2016 SAP SE or an SAP affiliate company. Internal 384
CDS Views and Relations
Analytical Perspective: Data Category, Query; Semantics
@Analytics.dataCategory, ~.query
@Semantics (e.g. amount ) 8
4 7 2 3
9 6 5
4 7 2 3
4 7 2 3
9 6
Analytical View
Analytical Query
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 388
CDS Metadata required to establish (transient) ODPs
Data Category
DIMENSION: Master Data (or Business Documents) (incl. associations to attributes and texts)
TEXT: Text View (containing 1 or more language-dependent texts)
HIERARCHY: Hierarchy Nodes (contains the key of the hierarchy directory)
FACT: Transaction Data (incl. at least one measure)
CUBE: Transaction Data, incl. associations to all elements with master data
(“star schema”), and incl. all dimensions and all fields relevant for grouping (“navigation
attributes”).
(typically a CUBE is based on a single view of category FACT
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 389
Check Analytical Query
Query Monitor (Transaction RSRT) (1)
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 390
Check Analytical Query
Query Monitor (Transaction RSRT) (2)
Shall be used to test the correctness of query views (Annotation: @Analytics.query: true) and views used in these query views.
Can also be used to test Analytical Views (CUBE or FACT) via a default query.
For query enter the ID of your query: "2C" + <sql view name of the query>.
Example:
CDS view name: ZTKC_FlightQuery
SQL view name: ZTKCFLIGHTQUERY
ID of (transient provider for) query: 2CZTKCFLIGHTQUERY
For Query Display choose: "HTML" to get an html-based UI for the query
As a result you get a view of your as specified in your CDS views You can now change the query execution like adding
additional fields, removing fields, choose display attributes, set filters,...
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 391
Check Analytical Query
Query Monitor (TA: RSRT) (3)
Hints:
If a query view is currently executed in rsrt but changed and activated in parallel the changes might not taken in the current rsrt
session. So, if you change a view which you are currently using in rsrt you need to restart the transaction
If a query view doesn't work but is correct (as checked by the check report mentioned below) this might be a caching issue. Try
to regenerate the query via Environment --> Generate Queries.
Some features (adding display attributes, choosing key or text for display) are hidden in the extended menu. Use the right
mouse-click at the name of the relevant field and choose "Extended Menu"
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 392
Lesson A4: VDM Analytical Perspective
Summary
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 393
Appendix
Appendix Lesson 5 – CDS Unit Testing
Why do we need Testing for “Code Pushdown”-Scenarios ?
Complexity of S/4 CDS Model (1)
Graph Representation of a Data Model using the Association as Edges
[1] on 2015-09-18
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 397
Why do we need Testing for “Code Pushdown”-Scenarios ?
Complexity of S/4 CDS Model (2)
TOP Views (with most “basis objects”) TOP Views (with most tables)
Entity # Basis Objects Entity #Tables
VFCLM_BAM_DDL_BSM_MD5 5.114 VFCLM_BAM_DDL_BSM_MD5 4.598
C_PURORDREFPURCONITM 3.055 VFCLM_BAM_DDL_BSM_MD4 2.298
P_ASSOCPURORDITMPURCONITM 3.054 VFCLM_BAM_DDL_BSM_MD3 2.298
C_PURGINFORECORDFS 3.008 C_PURORDREFPURCONITM 1.619
VFCLM_BAM_DDL_BSM_MD4 2.555 P_ASSOCPURORDITMPURCONITM 1.619
VFCLM_BAM_DDL_BSM_MD3 2.553 C_PURGINFORECORDFS 1.600
C_PURCHASINGCATEGORYFS 1.603 C_PURCHASINGCATEGORYFS 838
C_PURORDBYSUPPLIERINVOICE 1.569 C_PURORDBYSUPPLIERINVOICE 827
C_CONTRACTITEMFS 1.534 C_CONTRACTITEMFS 813
C_PURREQUISITIONITEMFS 1.527 C_PURREQUISITIONITEMFS 811
C_PURREQUISITIONFS 1.519 I_SUPPLIERCONTACTCARD 807
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 398
Why do we need Testing for “Code Pushdown”-Scenarios ?
Complexity of S/4 CDS Model (3)
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 399
Why do we need Testing for “Code Pushdown”-Scenarios ?
Here is the Answer…
Potential Answers
Use Debugging
SQL doesn’t offer debugging “by definition”
Use (Unit) Testing
the only “technically feasible” option to ensure the above qualities!
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 400
Unit Testing
Unit testing is a software methodology to test portions of code, to ensure they are fit for the intended
purpose. These portions of code can be described as smallest testable element of an application.
In Object Oriented programming a method or a class can be considered as unit. With code pushdown
a CDS view or a database procedure can be considered as unit.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 401
Dependencies
The portion of code that shall be tested is also called Code Under Test (CUT). Typically the CUT
invokes other code or relies on data sources like a database table. Such dependencies are also called
Depended-on Component (DOC).
The dependency to database table content can prevent a successful unit test execution in case the
assumed content is not available however.
In order to achieve stable unit tests it is required to isolate the CUT from any test hindering DOC.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 402
Test Doubles
A common practice is to replace a DOC with test unfriendly behavior by a substitute with test friendly
behavior. Such a substitute is also called Test Double.
(Original)
Unit test Code Under Depended On
Test Component
establishes
Test Double
no longer
required
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 403
Appendix
Appendix Lesson 6 – Fiori Programming Model
Fiori Technology
HANA
Data Data
Replication Replication
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 406
Fiori Programming Model – Open, flexible and standardized
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 408
Simple list reporting
ALV-like applications
Fiori User Interface UI runtime
Find:
GET ../SalesOrder?
$filter=
R $select=
$orderby=
search=
$top= 50
HTTP / OData
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 409
Fiori Building Blocks: Smart Controls and Smart Templates
Annotation Driven Fiori UIs
What means Annotations describe semantics related to data (examples see next slide).
? Smart? Smartness of Controls and Templates is based on the understanding of
these semantics. Annotations are evaluated in the Client Controller logic.
Development steps
Choose Template Select annotated Run fully functional
OData Service. standard Fiori Application
Templates incorporate Annotations are derived from No front end coding required.
latest Fiori design and CDS for reuse, productivity Extension via additional
UX. and consistency. Annotations or own Templates.
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 410
Demo
Fiori & OData
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 412
Appendix
Appendix Lesson 7 – Miscellaneous
Open SQL Vs ABAP CDS
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 414
Core Data Services: HANA & ABAP
?
• Same Semantic on all DBs • HANA only (HANA specific features
• Initial Focus on View building available)
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 415
ABAP CDS vs HANA CDS
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Internal 416