CDS View in Sap Hana
CDS View in Sap Hana
Suryakant Pandey
CDS (Core Data Services) – The Framework
Is one of the code pushdown techniques which helps to develop the data intense
calculation directly onto database.
What it is: CDS is a technology provided by SAP to define data models directly in the
database using enhanced SQL.
Purpose: Helps build structured, meaningful data models that are easy to access and
understand.
Think of it as: The foundation or toolbox for creating CDS views of your data.
Purpose: To create a logical view on top of database tables or other views, with business
logic included.
Think of it as: A recipe that tells SAP how to gather and present the data.
Written using
• Define view or
Suryakant Pandey
Note:
CDS views and SQL views share the same name space. So, make sure to give them
different names to avoid conflicts.
Suryakant Pandey
CDS ARCHITECTURE:
1)DDL EDITOR: Is A Text-Based Editor Used to Develop DDL Source Object. It Is an Abap
Development Tool.
3)CDS VIEW ENTITY: Is a used to represent data of more than one database tables.
1)Inner Join.
4)Cross Join.
Note: ‘For all Entries ‘is not used and supported in CDS Views.
1)CDS View with Inner Join: It Joins 2 or more database tables based on common
fields (foreign key relationship) and fetches only matched records of both the database
tables.
2)CDS View with Left Outer Join: It Joins 2 or more database tables based on
common fields (foreign key relationship) and fetches matched records of both the
database tables and also unmatched records of left database table.
3) CDS View with Right Outer Join: It Joins 2 or more database tables based on
common fields (foreign key relationship) and fetches matched records of both the
database tables and also unmatched records of right database table.
4) CDS View with Cross Join: All the entries on the left side are combined with all
the entries of the right side the number of rows of the left side is multiplied by the number
of rows on the right side.
Suryakant Pandey
1.INNER JOIN
@AbapCatalog.sqlViewName: 'ZCDS_INNER_VIEW'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
H.erdat as Erdat,
H.ernam as Ernam,
H.vbtyp as Vbtyp,
H.auart as Auart,
H.vkorg as Vkorg,
H.spart as Spart,
I.posnr as Posnr,
I.matnr as Matnr,
I.netpr as Netpr,
I.waerk as Waerks,
I.kwmeng as Kwmeng,
I.meins as Meins,
I.netwr as Netwr
Suryakant Pandey
OUTPUT
Suryakant Pandey
2.LEFT OUTER JOIN
@AbapCatalog.sqlViewName: 'ZCDS_LEFT_SQL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
h.erdat as Erdat,
h.ernam as Ernam,
h.vbtyp as Vbtyp,
h.auart as Auart,
h.vkorg as Vkorg,
h.spart as Spart,
i.posnr as Posnr,
i.matnr as Matnr,
i.netpr as Netpr,
i.waerk as Waerks,
i.kwmeng as Kwmeng,
i.meins as Meins,
i.netwr as Netwr
Suryakant Pandey
OUTPUT
Suryakant Pandey
3)RIGHT OUT JOIN
@AbapCatalog.sqlViewName: 'ZCDS_RIGHT_SQL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
SCH.vbele as Vbeln,
SCH.posnr as Posnr,
SCH.etenr as Etenr,
SCH.bmeng as Bmeng,
SCH.vrkme as Vrkme,
ITM.matnr as Matnr,
ITM.netpr as netpr,
ITM.waerk as weark,
ITM.kwmeng as Kwmeng,
ITM.netwr as netwr
Suryakant Pandey
OUTPUT
Suryakant Pandey
4)CROSS JOIN
@AbapCatalog.sqlViewName: 'ZCDS_SQL_CRO_JO'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
h.vbeln,
h.vbtyp,
h.auart,
h.vkorg,
h.vtweg,
h.spart,
con.knumv,
con.kposn,
con.kschl,
con.kwert
Suryakant Pandey
OUTPUT
Suryakant Pandey
Create Custom CDS Views as follows:
1) ZSALES_DATA01 >> VBAK AND VBAP
Suryakant Pandey
ZSALES_DATA01
@AbapCatalog.sqlViewName: 'ZSALES_SQL '
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
H.erdat as Erdat,
H.ernam as Ernam,
H.vbtyp as Vbtyp,
H.kunnr as kunnr,
H.auart as Auart,
H.vkorg as Vkorg,
H.spart as Spart,
I.posnr as Posnr,
I.matnr as Matnr,
I.netpr as Netpr,
I.waerk as Waerks,
I.kwmeng as Kwmeng,
I.meins as Meins,
Suryakant Pandey
I.netwr as Netwr
OUTPUT
Suryakant Pandey
ZCDS_MATERIAL_DATA01
@AbapCatalog.sqlViewName: 'ZCDS_MAT_SQL '
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
M.ersda as ersda,
M.mtart as mtart,
M.mbrsh as mbrsh,
M.matkl as matkl,
M.meins as meins,
X.maktx as maktx
Suryakant Pandey
OUTPUT
Suryakant Pandey
ZCDS_CUSTOMER_DATA
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
K.land1 as LAND1,
K.name1 as NAME1,
K.ort01 as ORT01,
K.adrnr as ADRNR,
B.bukrs as BUKRS,
B.pernr as PERNR,
B.akont as AKONT
Suryakant Pandey
OUTPUT
Suryakant Pandey
ZCDS_BILLING_DATA
@AbapCatalog.sqlViewName: 'ZCDS_BILL_SQL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
B.fkart as FKART,
B.fkdat as FKDAT,
B.knumv as KNUMV,
B.belnr as BELNR,
B.inco1 as INCO1,
P.charg as CHARG,
P.fkimg as FKIMG,
P.matnr as MATNR,
P.vrkme as VRKME,
P.netwr as NETWR,
P.waerk as WAERK,
P.aubel as AUBEL
Suryakant Pandey
OUTPUT
Suryakant Pandey
Consume Multiple CDS View in a Single CDS View:
Now Create CDS Views consuming above CDS Views.
ZCDS_FINAL
@AbapCatalog.sqlViewName: 'ZCDS_FINAL_SQL '
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
v.Vbeln,
v.Erdat,
v.Ernam,
v.Vbtyp,
v.Auart,
v.Vkorg,
v.Spart,
v.Items,
v.Posnr,
v.Matnr,
v.Netpr,
v.Waerks,
Suryakant Pandey
v.Kwmeng,
v.Meins,
v.Netwr,
m.ersda,
m.mtart,
m.mbrsh,
m.matkl,
m.maktx,
c.KUNNR,
c.LAND1,
c.NAME1,
c.ORT01,
c.BUKRS,
c.PERNR,
c.AKONT,
// i_address
I.AddressID,
I.POBox,
I.FullName,
I.CityName,
I.PostalCode,
I.StreetName,
I.HouseNumber,
I.Region,
I.County,
Suryakant Pandey
// billing
b.FKART,
b.FKDAT,
b.KNUMV,
b.BELNR,
b.INCO1,
b.CHARG,
b.FKIMG,
//b.MATNR,
b.VRKME,
//b.NETWR,
b.WAERK
Suryakant Pandey
Suryakant Pandey
OUTPUT
Suryakant Pandey
Extend CDS View: Is used to add extra fields to an existing CDC view. you can add extra
fields to both standard and custom CDS View.
Association: Are kind of joins which gets the data of multiple database tables of an
application but it joins on demand.
Types of Association:
1)Exposed Association.
2)Ad-hoc Association.
3)Filter Association.
1)Exposed Association: In this Association, the associated target fields are not
explicitly displayed onto screen unless user demands for it.
2)Ad-hoc Association: It is similar to joins where your target entity fields are
explicitly populated onto the screen as associated target fields are explicitly provided in
the projection list.
Note: CDS Views with Associations are used in light weight applications such as Fiori and
UI5.So to increase the performance of it we take the help of associations which joins DB
tables on demand but not before hand.
->Cardinality is the relationship between the source and associated table or cds view.
Note: If you don’t provide ‘key’ in field list of view the you will get wrong output or result.
->The relationship between source and target entities is a concept of association and the
relationship between them is achieved by cardinality.
Suryakant Pandey
Extend CDS View:
@AbapCatalog.sqlViewAppendName: 'ZEXTEND_SQL'
K.ernam,
K.erdat,
K.regio,
OUTPUT
Suryakant Pandey
ASSOCIATION
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
key E.ebeln,
E.bsart,
E.bstyp,
E.ekorg,
E.ekgrp,
E.lifnr,
_ITM,
_VND,
_ACT
Suryakant Pandey
OUTPUT
LIST OF ASSOCIATIONS
Suryakant Pandey
ASSOCIATED DATA
_ITM ->EKPO
_VND ->LFA1
Suryakant Pandey
EXPOSE ASSOCIATION
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
key H.vbeln,
H.audat,
H.vbtyp,
H.auart,
H.vkorg,
H.vtweg,
H.spart,
_I
Suryakant Pandey
OUTPUT
LIST OF ASSOCIATIONS
Suryakant Pandey
ASSOCIATED DATA
Suryakant Pandey
AD-HOC ASSOCIATION
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
key H.vbeln,
H.audat,
H.vbtyp,
H.auart,
H.vkorg,
H.vtweg,
H.spart,
_ITM.matnr,
_ITM.posnr,
_ITM.charg
Suryakant Pandey
OUTPUT
🚀 Pro Tip:
Use CDS views to shift heavy data logic to the DB layer for faster performance
in S/4HANA. Prefer DEFINE VIEW ENTITY for modern CDS modeling—it's
optimized and future-proof.
Suryakant Pandey
THANK YOU FOR READING
Suryakant Pandey