100% found this document useful (4 votes)
3K views50 pages

ABAP CDS Hands On Practical Training

Raju Shrestha is an SAP ABAP consultant who has experience in various industries. He was trained at IBM where he held roles like application programmer, system engineer, and team lead. Shrestha founded the technical knowledge sharing site ZAPYard.com and coaches soccer in his free time. He has a special interest in SAP HANA, OData, and SAPUI5/Fiori.

Uploaded by

Ryan Marzan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
3K views50 pages

ABAP CDS Hands On Practical Training

Raju Shrestha is an SAP ABAP consultant who has experience in various industries. He was trained at IBM where he held roles like application programmer, system engineer, and team lead. Shrestha founded the technical knowledge sharing site ZAPYard.com and coaches soccer in his free time. He has a special interest in SAP HANA, OData, and SAPUI5/Fiori.

Uploaded by

Ryan Marzan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Meettitle

Click to edit Master your Instructor


style
Raju Shrestha
SAP ABAP Consultant (SAP S/4HANA Certified) who has helped clients in
Automation, Heavy Machinery, Pharma, and Energy Industries.
Groomed and Trained by the Big Blue i.e. IBM, where he served in
different capacities viz Application Programmer, System Engineer, Team
Lead and Advisory System Associate.

Founder of popular SAP Technical Knowledge sharing site


www.ZAPYard.com and Soccer coach at YMCA.

Part of the Innovation Team who developed Automation Tools and


Products. Official trainer at IBM’s Learning and Knowledge (L&K)
Department.

He is an enthusiast in SAP HANA, OData and SAP Netweaver Gateway


with special interest in SAPUI5 and Fiori.
Click to edit Master title style

Core Data Services for S/4HANA ABAP


(Practical Deep Dive Training on ABAP CDS)
Click to edit Master title style
Course Goals
CDS View - Concepts
• CDS – Introduction, How to define CDS View?
• CDS definition & SQL example
• Good to know facts about CDS
• CDS – Advantages & Limitations
• Major Consumers of CDS
• Classifying CDS Views & VDM – Virtual Data Modeling

CDS View - Hands on Exercises


• Create Simple CDS View
• Create CDS View with Join
• Create CDS View with Associations
• Create CDS View with Parameters
• How does the CDS Transport Look?

CDS View - Hands on Exercises


• How to Consume CDS from ABAP Programs?
• How to Expose CDS as OData Service?
• How to Maintain & Activate CDS Based OData Service?
• How to Test CDS Based OData Service with and without Parameters?
Click to edit Master title style

CDS View Concepts


Click to edit Master
CDS title style
- Introduction
• An enhancement of SQL standard, Used for defining semantically rich data models and user defined types in DB

• One data model for HANA and ABAP Layer – Once concept for all (HANA CDS (.hdbdd for native HANA) and ABAP CDS)

• CDS is DB independent (no need to worry about underlying DB SQL statements) – Not HANA proprietary

• Ease of life cycle management of CDS (unlike View Proxy for HANA View viz Attribute, Analytical, Calculation Views)

• CDS can be used by Application outside of SAP domain - SAP claims traditional database view is just a linkage of one or
more tables, whereas CDS view is a full-fledged data model, which, in addition to having extra features that SE11- defined
views do not, can be used even by applications outside of the SAP domain.

• A CDS view is a big/powerful SELECT statement on steroids (though it can only return one result (a row or table of data))

• When the DDL object is generated in the ABAP system, an equivalent database view is generated within SAP HANA (or
whatever database system uses), called a CDS view
Click to editCDS
Master title style (continued…)
– Introduction
What is Enhanced in CDS View?
• Data Definition Language (DDL) – Define new artifacts like new table view table type using CDS syntax – no need to worry
about SQLScript of underlying DB.

• Data Query Language (DQL) – enhanced READ performance

• Expression Language – Aggregation on fly, write formula in CDS View, complex CASE statements etc
Click to edit Master
How to title
Definestyle
CDS View?
@AbapCatalog.sqlViewName: 'ZTM_FNS_SQL'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK CDS Data Definition
@EndUserText.label: 'CDS View to OData'
@OData.publish: true
Activation
define view ZTM_FNS as select from marc as m
{
key m.matnr as material,
CDS SQL View CDS Entity /
key m.werks as plant,
(ZTM_FNS_SQL) Actual CDS View
m.mmsta as status
} [max 16 char] (ZTM_FNS)

Please note: CDS View can only be created using ADT


Click to edit
CDSMaster title style
Definition & SQL Example
Click to edit to
Good Master
Knowtitle style
Facts About CDS Views
• At least one annotation is needed to define the CDS SQL View Name i.e. @AbapCatalog.sqlViewName: 'ZTM_FNS_SQL’

• Others are optional annotations

• An annotation is a line of code that starts with an @ sign. After the @ sign is a term that describes the nature of the
annotation (e.g. the term AbapCatalog represents header settings for the view, AccessControl is for Authorization)

• Form subroutine starts with FORM while a method starts with METHOD. In the same way the CDS view starts with the
words define view, as in the following: define view ZTM_FNS

• Do not need to put the client (MANDT) into the SELECT statement of CDS Views as the regular SELECT statement in ABAP;
the runtime system handles this, just like we have been doing for normal transparent tables or SE11 views.

• If we need to explicitly pass MANDT to the CDS View for passing it further to SQL procedures (AMDP), we have to add an
annotation to inherit this ability from the underlying table (provided it has a MANDT field) as follows:
@ClientHandling.type:#INHERITED
Click to edit Master
CDStitle style
– Advantages
• HANA CDS (.hdbdd for native HANA) and ABAP CDS – One data model for HANA and ABAP
• CDS is database independent (no need to worry about underlying DB SQL statements)
• Ease of life cycle management of CDS (unlike HANA View viz Attribute, Analytical, Calculation Views)
• Code Push Down to DB
• Supports Outer Join
• Can handle complex expressions
• Analytical Adoption (can build UI App using Annotations and without code)
• Odata Support (@Odata.expose: true)
• Table Types can be created out of CDS View (not in Traditional View)
• Built in functions (eg UNION)
• Can pass parameters
Click to edit Master
CDS title style
– Limitations

• Cannot debug CDS View

• Sometimes we may have to use tables and columns (type mismatch) of 2 tables which are not supported by CDS ***

• The best example of above limitation is - Not a standard way to handle SELECT-OPTIONS ***

*** Solution – CDS Table Function; invoke AMDP from CDS in 7.5 NW to handle SELECT-OPTIONS
Click to editCommon
Master title style
Consumers of CDS

S/4HANA Embedded Analytics Fiori - Analytical App


Standard Query Browser Aggregation @UI

CDS View

Analytical Tools BOPF – Transactional Apps


@Analytics Insert, Update, Delete
Consumers of CDS @ObjectModel
Click to edit Master title style
Classification of CDS View

Service Quality
Data Class Size Category
Click to edit Master
Classifying title style
a CDS View – i) Data Class
• Good idea to classify CDS views to help the database do the best job it can

• Several caches on the SAP HANA database, annotation with dataClass helps

@ObjectModel.usageType.dataClass:'CUSTOMIZING'

• How??
Data Class helps the database choose the correct cache and thus speed up processing

• Different Data Class for CDS Views:


TRANSACTIONAL (e.g. VBAP, VBRK, LIPS, MSEG)
MASTER (as in master data—e.g. KNA1, LFA1, MARA)
ORGANIZATIONAL (e.g., tables in the organizational part of the IMG – e.g. T001, T001W)
CUSTOMIZING (other IMG tables—e.g. TVAK (SD Type), T161 (PO Type))
META (data about data; I can’t imagine you would use this one)
MIXED (if you’re doing a join on master and transactional data)
ClickClassifying
to edit Master titleView
a CDS style– ii) Size Category

• Next annotation for classification is @ObjectModel.usageType.sizeCategory : 'XL'

• Exactly like in SE11


S = less than 1,000 M = less than 100,000
L = less than 10,000,000 XL = less than 100,000,000 XXL = greater than 100,000,000
Click to edit Master
Classifying a CDStitle style
View – iii) Service Quality
• Another classification annotations is @ObjectModel.usageType.serviceQuality : 'A'
• This is a guide to how long a query is likely to take and what sort of applications will be using (consuming) the CDS view
• A: business logic/high-volume transactions (1–2 ms)
B: business logic/normal transactions (2–5 ms)
C: retrieve a single object to show in the UI (10–20 ms)
D: analytics (<500 ms)
X: push down really complex logic to the SAP HANA database (varies)
• Developers might not be able to know exactly .. In such cases the best guess is the only option
Click to edit Master title style
VDM – Virtual Data Modeling

• VDM views are understandable from a nontechnical business perspective

• A part of the VDM views are supposed to be reused

• VDM implemented by CDS is the model for S/4HANA

• VDM views are executed directly by the SAP HANA database and benefit from its manifold capabilities and speed

• VDM views are used for the development of all new SAP standard apps in SAP S/4HANA

• VDM is built in layers of views, each having their own specific tasks
Click to edit Master title style
VDM – Virtual Data Modeling
Click to edit Master title style
VDM – Virtual Data Modeling
Click to edit Master title style
VDM – Virtual Data Modeling

• Master Data/Dimension • Dimension + Fact • Analytical Tools


• Text join • ZMM_CO_ • Fiori Elements
• ZMM_I_ • ZMM_I_ (Smart Filter, OVP, ALP)
• @VDM.viewType: #BASIC • @VDM.viewType: • S/4 Embedded Analytics are
#CUBE the consumers
• @VDM.viewType: • ZMM_C_
#COMPOSITE • @VDM.viewType:
#CONSUMPTION
Click to edit
VDM Master titleData
– Virtual styleModel Examples
Click to edit Master title style

CDS View - Hands on Exercises


Click to edit Master title CDS
Define style View

• No need for an INTO clause in a CDS view definition


Click to edit Master title CDS
Define style View

Video Exercise in HANA Studio


Click to edit Master title
Define style
View with Join

Left Outer Joins

Right Outer Joins

Inner Joins

Cross Joins
Click to edit Master title
Define style
View with Join
Click to edit Master title
Define style
View with Join

Video Exercise in HANA Studio


Click to edit Master- title
Exercise Definestyle
View with Join
Create a CDS VIEW
using tables SNWD_SO
LEFT OUTER JOIN
SNWD_SO_I
ON SNWD_SO-NODE_KEY = SNWD_SO_I-PARENT_KEY
and fetch the fields
node_key,
so_id,
created_by,
created_at,
note_guid,
buyer_guid,
currency_code,
gross_amount,
net_amount

WHERE SNWD_SO-BILLING_STATUS = ‘P’


Click to edit Master
Define CDStitle
Viewstyle
with Parameters

Normal Data Dictionary View


Click to edit Master
Define CDStitle
Viewstyle
with Parameters

Normal Data Dictionary View Hard Coded WHERE


Click to edit Master
Define CDStitle
Viewstyle
with Parameters

• To get around the need for hard- coded WHERE conditions use CDS Views with parameters

• From SP 8 in 7.4 & in 7.5, CDS views can be defined with parameters that are passed in via the ABAP program at runtime

• Can have a mixture of parameters & normal WHERE clauses (hard- coded WHERE condition in the ABAP SQL statement )

• CDS views cannot handle SELECT-OPTIONS properly (AMDP way around)


Click to edit Master
Define CDStitle
Viewstyle
with Parameters

Video Exercise in HANA Studio


Click to edit Master
Define CDStitle
Viewstyle
with Association

• SAP recommends to use Associations instead of Joins because they’re closer to “conceptual thinking”

• Association is not a join as such; it’s just metadata about a possible join connection, which is stored in the data dictionary

• The actual join is created when the association is used in a path expression (called/triggered)

• SAP recommends to use CamelCase for all names inside a CDS view

• Start the association name with an underscore to differentiate them from standard fields in a CDS view
Click to edit Master title
Cardinality style Association
in CDS
Click to editTypes
Master
of title style
Associations in CDS

Exposed Associations Ad-Hoc Associations


Click to editTypes
Master
of title style
Associations in CDS

Exposed Associations Ad-Hoc Associations


ClickWhat
to edit
canMaster titleas
be Used style
Association Targets?

• CDS Views

• CDS Table Functions

• SQL Views

• Database Tables
Click
Howto to
edit
UseMaster
CDS title style
Associations in ABAP Code?
Click to edit Master
Define CDStitle
Viewstyle
with Association

Video Exercise in HANA Studio


Click to edit
HowMaster
doestitle
CDS style
transport look?

• Check the Object type DDLS is created for CDS View (unlike VIEW for SE11 View)
• CDS Definition resides in ABAP layer so when a CDS View is created or changed, it initiates CREATE operation in the
database linked to ABAP layer
• When CDS is moved to Quality/Prod, no need to worry about updating DB (unlike Models and their proxies)
Click to edit
HowMaster
doestitle
CDS style
transport look?

Video Exercise in HANA Studio


Click to edit aMaster
Reading title style
CDS View from an ABAP Program

• In ABAP program is it recommended to refer to the CDS view entity, not the SE11 sqlViewName
• The code completion works for CDS view names just as for database tables and standard views.
• Normal ABAP SQL syntax works for CDS queries in ABAP Programs
Click to edit aMaster
Reading title style
CDS View from an ABAP Program

Video Exercise in HANA Studio


How toto
Click Create
edit OData
MasterService by Pushing from CDS View?
title style

- Annotation @Odata.expose: true


- Maintain the Service
- Test the OData Service
CDS Based
Click to edit Master OData Service
title style

- Annotation @Odata.expose: true


- Maintain the Service - /IWFND/MAINT_SERVICE
- Test Normal CDS Based OData Service
- Test OData Service based out of CDS View with Parameters
How to
Click to Create OData title
edit Master Service by Pushing from CDS View?
style

Video Exercise in HANA Studio


Course
Click to Summary
edit Master title style

• Introduction to CDS
• Create Simple/Complex CDS View
• Consume CDS View in ABAP
• Understand Virtual Data Model
• Create OData Service using CDS Annotation
• Test and Consume the OData Service
What Next?
Click to edit Master title style
• Deep Dive into AMDP
• Learn SQL Script
• Learn SAPUI5 Development
• Learn How to Create and Extend SAP Fiori Apps
What Next?
Click to edit Master title style
• https://www.youtube.com/watch?v=GlWM7yxJyJ0&list=PLcxqFaocb9WLtn
q-rpXbRy5hnKECxr95G&index=14
Disclaimer
Click to edit Master title style
MICHAEL MANAGEMENT CORPORATION (MMC) AND THE MMC LOGO ARE REGISTERED OR UNREGISTERED TRADE AND/OR
SERVICE MARKS OF MMC AND ARE PROTECTED BY US AND INTERNATIONAL COPYRIGHT LAWS. ALL OTHER NAMES, BRANDS,
LOGOS, ETC. ARE REGISTERED TRADE OR SERVICE MARKS OF THEIR RESPECTIVE OWNERS. MMC IS NOT AFFILIATED WITH SAP
SE. SAP®, THE SAP® LOGO, PRODUCT NAMES, SAP® SCREEN SHOTS © SAP SE.

You might also like