0% found this document useful (0 votes)
35 views37 pages

CDS View in Sap Hana

The document provides an overview of Core Data Services (CDS) in S/4HANA, detailing its purpose, architecture, and the process of creating CDS views using various types of joins. It explains the significance of CDS views in defining virtual data models and outlines how to extend existing views and use associations for efficient data access. Additionally, it includes examples of custom CDS views and their implementation in ABAP Development Tools.

Uploaded by

yuwonoandrie54
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
0% found this document useful (0 votes)
35 views37 pages

CDS View in Sap Hana

The document provides an overview of Core Data Services (CDS) in S/4HANA, detailing its purpose, architecture, and the process of creating CDS views using various types of joins. It explains the significance of CDS views in defining virtual data models and outlines how to extend existing views and use associations for efficient data access. Additionally, it includes examples of custom CDS views and their implementation in ABAP Development Tools.

Uploaded by

yuwonoandrie54
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/ 37

CDS VIEWS IN S/4HANA

Modern ABAP = Smart CDS modeling + efficient data virtualization

Modern Techniques for Efficient Data Access and Virtualization.

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.

Used in: Eclipse / ABAP Development Tools (ADT).

CDS View – The Product


A CDS (Core Data Services) View is a way to define a virtual data model on top of existing
database tables or other CDS views. It helps present only the required fields and joins data
logically for application use.

What it is: A specific object or artifact created using CDS.

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.

Used in: Building VDMs (Virtual Data Models) in S/4HANA.

Written using

• Define view or

• Define view entity

Suryakant Pandey
Note:
CDS views and SQL views share the same name space. So, make sure to give them
different names to avoid conflicts.

CDS View Building Architecture

Suryakant Pandey
CDS ARCHITECTURE:
1)DDL EDITOR: Is A Text-Based Editor Used to Develop DDL Source Object. It Is an Abap
Development Tool.

2)DDL SOURCE(ZCDS_SALES_10): It is a repository development object which defines


CDS view entity (zcds_sales_10).

3)CDS VIEW ENTITY: Is a used to represent data of more than one database tables.

4)SQL VIEW (ZCDS_SALES_10_V): It is a technical representation of CDS view entity that


means it is the definition or structure representation of CDS view entity.

ABAP CDS Views using Joins:


CDS Views supports 4 types of Joins:

1)Inner Join.

2)Left Outer Join.

3)Right Out 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.

--> Cross join is also called as Full Outer join.

Suryakant Pandey
1.INNER JOIN
@AbapCatalog.sqlViewName: 'ZCDS_INNER_VIEW'

@AbapCatalog.compiler.compareFilter: true

@AbapCatalog.preserveKey: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'CDE VIEW WITH INNER JOIN'

@Metadata.ignorePropagatedAnnotations: true

define view ZCDS_INNER_JOIN

as select from vbak as H

inner join vbap as I on H.vbeln = I.vbeln

H.vbeln as Vbeln, // vbak : sales Document :Header data

H.erdat as Erdat,

H.ernam as Ernam,

H.vbtyp as Vbtyp,

H.auart as Auart,

H.vkorg as Vkorg,

H.spart as Spart,

coalesce(I.posnr, 'No Items') as Items,

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

@EndUserText.label: 'CDS VIEW WITH LEFT OUTER JOIN'

@Metadata.ignorePropagatedAnnotations: true

define view ZCDS_WITH_LEFT_JOIN

as select from vbak as h

left outer join vbap as i on h.vbeln = i.vbeln

h.vbeln as Vbeln, // vbak : sales Document: Header data

h.erdat as Erdat,

h.ernam as Ernam,

h.vbtyp as Vbtyp,

h.auart as Auart,

h.vkorg as Vkorg,

h.spart as Spart,

coalesce(i.posnr, 'No Items') as Items,

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

@EndUserText.label: 'CDS VIEW WITH RIGHT OUTER JOIN'

@Metadata.ignorePropagatedAnnotations: true

define view ZCDS_WITH_RIGHT_JOIN

as select from vbep as SCH

right outer join vbap as ITM on SCH.vbeln = ITM.vbeln

and SCH.posnr = ITM.posnr

SCH.vbele as Vbeln,

coalesce( SCH.posnr, 'NO Schedule items' ) as Schedule_items,

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

@EndUserText.label: 'CDS VIEW WITH LEFT CROSS JOIN'

@Metadata.ignorePropagatedAnnotations: true

define view ZCDS_WITH_CROSS_JOIN

as select from vbak as h

cross join v_konv_cds as con // conditions

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

2) ZCDS_MATERIAL_DATA01 >> MARA AND MAKT

3) ZCDS_CUSTOMER_DATA >> KNA1 AND KNB1

4) ZCDS_BILLING_DATA >> VBRK AND VBRP

5) USE STANDARD CDS VIEW >> I_ADDRESS

Suryakant Pandey
ZSALES_DATA01
@AbapCatalog.sqlViewName: 'ZSALES_SQL '

@AbapCatalog.compiler.compareFilter: true

@AbapCatalog.preserveKey: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'CDS VIEW FOR SALES DATA'

@Metadata.ignorePropagatedAnnotations: true

define view ZSALES_DATA01

as select from vbak as H

left outer join vbap as I on H.vbeln = I.vbeln

H.vbeln as Vbeln, // vbak : sales Document :Header data

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,

coalesce(I.posnr, 'No Items') as Items,

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

@EndUserText.label: 'CDS VIEW FOR MATERIAL DATA'

@Metadata.ignorePropagatedAnnotations: true

define view ZCDS_MATERIAL_DATA01

as select from mara as M

left outer join makt as X on M.matnr = X.matnr

and X.spras = 'EN'

key M.matnr as matnr,

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.sqlViewName: 'ZCDS_CUST_SQL '

@AbapCatalog.compiler.compareFilter: true

@AbapCatalog.preserveKey: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'CDS VIEW FOR CUSTOMER DATA'

@Metadata.ignorePropagatedAnnotations: true

define view ZCDS_CUSTOMER_DATA

as select from kna1 as K

left outer join knb1 as B on K.kunnr = B.kunnr

key K.kunnr as KUNNR,

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

@EndUserText.label: 'CDS VIEW FOR BILLING DATA'

@Metadata.ignorePropagatedAnnotations: true

define view ZCDS_BILLING_DATA

as select from vbrk as B

left outer join vbrp as P on B.vbeln = P.vbeln

key B.vbeln as VBELN,

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

@EndUserText.label: 'CDS VIEW WITH MULTIPLE VIEW'

@Metadata.ignorePropagatedAnnotations: true

define view ZCDS_FINAL

as select from ZSALES_DATA01 as v

left outer join ZCDS_MATERIAL_DATA01 as m on v.Matnr = m.matnr

left outer join ZCDS_CUSTOMER_DATA as c on v.kunnr = c.KUNNR

left outer join I_Address as I on c.ADRNR = I.AddressID

left outer join ZCDS_BILLING_DATA as b on v.Vbeln = b.AUBEL

// vnak and vbap

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,

// mara and makt

m.ersda,

m.mtart,

m.mbrsh,

m.matkl,

m.maktx,

// kna1 and knb1

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.

->Cardinality is defined only for the target(associated) table/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.

Cardinality Min. records of Max. records of


Associated Target Associated Target
1 0 1
0..1 0 1
1..1 1 1
1.. * 1 Unlimited
0.. * 0 Unlimited
Not specified 0 1

Suryakant Pandey
Extend CDS View:
@AbapCatalog.sqlViewAppendName: 'ZEXTEND_SQL'

@EndUserText.label: 'ZCDS VIEW USING EXTEND VIEW'

extend view ZCDS_CUSTOMER_DATA with ZEXTEND_VIEW

K.ernam,

K.erdat,

K.regio,

B.eikto // Our account number at customer

OUTPUT

Suryakant Pandey
ASSOCIATION
@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'CDS VIEW WITH ASSOCIATION 1*1'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

define view entity ZCDS_ASSO_02 // ASSOCIATION

as select from ekko as E

association [1..*] to ekpo as _ITM on E.ebeln = _ITM.ebeln

association [1..1] to lfa1 as _VND on E.lifnr = _VND.lifnr

association [1..*] to bseg as _ACT on E.ebeln = _ACT.ebeln

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

_ACT -> BSEG

_ITM ->EKPO

_VND ->LFA1

Suryakant Pandey
EXPOSE ASSOCIATION
@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'CDS VIEW WITH ASSCIATION'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

define view entity ZCDS_ASSO // Association

as select from vbak as H

association [1..*] to vbap as _I on H.vbeln = _I.vbeln

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

@EndUserText.label: 'CDS VIEW WITH ADHOC ASSOCIATION'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

define view entity ZCDS_ADHOC_ASSO // AD-HOC ASSOCIATION

as select from vbak as H

association [1..*] to vbap as _ITM on H.vbeln = _ITM.vbeln

key H.vbeln,

H.audat,

H.vbtyp,

H.auart,

H.vkorg,

H.vtweg,

H.spart,

_ITM.matnr,

_ITM.posnr,

_ITM.charg

Suryakant Pandey
OUTPUT

Here, Directly Getting


Matnr, Posnr & Charg

This Is Called Ad-hoc.

🚀 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy