100% found this document useful (2 votes)
373 views

CDS View Questions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
373 views

CDS View Questions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

SAP

Abap
CDS
Ques ons
Sonu Jangir Abap Developer

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


What is a CDS view in SAP?
A CDS (Core Data Services) view is a structured representa on of database
tables, helping in efficient data modelling and processing in SAP HANA. CDS
views allow defining complex logic, associa ons, and annota ons, making data
retrieval faster and more op mized in an SAP environment.
Explana on
CDS views are used to enhance data modelling capabili es in SAP HANA by
integra ng the database layer and applica on layer, promo ng seamless data
access.
How do CDS views differ from tradi onal SAP views?
CDS views differ from tradi onal views by enabling advanced data modelling
capabili es, suppor ng annota ons, associa ons, and seman c defini ons.
They offer much more func onality than database views and are op mized for
SAP HANA.
Explana on
Unlike tradi onal SAP views, CDS views take full advantage of SAP HANA’s in-
memory capabili es, providing faster performance and addi onal modelling
op ons.
What is the role of annota ons in CDS views?
Annota ons in CDS views provide metadata that defines behaviour, visibility,
and proper es of the CDS view. They influence how the view is processed,
displayed, and consumed by applica ons or systems.
Explana on
Annota ons are a powerful feature of CDS views, allowing for a customizable
and highly adaptable data model by specifying different metadata se ngs.
What are the advantages of using CDS views?
CDS views offer numerous advantages, including improved performance,
seman c capabili es, reusable logic, and be er integra on with the SAP HANA
database. They help op mize queries and simplify complex data retrieval
processes.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


Explana on
By leveraging the capabili es of SAP HANA, CDS views provide a more efficient
and streamlined approach to data access and processing.
Can CDS views be used for transac onal applica ons?
Yes, CDS views can be used for transac onal applica ons when combined with
OData services. They are o en used to expose data in a way that applica ons
can access, manipulate, and process.
Explana on
CDS views act as a bridge between database tables and applica on services,
providing structured data for both analy cal and transac onal purposes.
What are the types of CDS views in SAP?
There are two main types of CDS views: Basic and Composite. Basic views
define the structure of individual tables, while Composite views combine
mul ple Basic views for more complex data modelling.
Explana on
The dis nc on between Basic and Composite CDS views allows developers to
break down and manage their data models effec vely.
What is the difference between ABAP CDS views and HANA CDS views?
ABAP CDS views are managed and executed within the ABAP layer of SAP,
whereas HANA CDS views are executed directly on the HANA database layer.
ABAP CDS views support integra on with ABAP frameworks, while HANA CDS
views are more database-centric.
Explana on
ABAP CDS views are ideal for ABAP-based applica ons, whereas HANA CDS
views are op mized for database-side processing in SAP HANA.
How can associa ons be defined in CDS views?
Associa ons in CDS views define rela onships between different en es or
tables. They are similar to joins but are more flexible, providing naviga on
paths between en es without requiring immediate data fetching.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


Explana on
Associa ons enable dynamic data access in CDS views by allowing deferred
joins, enhancing query flexibility and performance.
Can you create joins in CDS views?
Yes, CDS views support inner and outer joins between tables or views. The joins
help combine data from different sources into a unified view for easier data
access and analysis.
Explana on
Joins in CDS views allow developers to combine data from mul ple tables
efficiently, streamlining data retrieval processes.
What is the purpose of the @AbapCatalog.sqlViewName annota on in CDS?
The @AbapCatalog.sqlViewName annota on is used to define the name of the
SQL view that corresponds to the CDS view. This name is used for the view in
the underlying database.
Explana on
This annota on ensures that a database representa on of the CDS view exists,
allowing SQL-based access to the CDS view.
How do you create a CDS view?
To create a CDS view, you use the DEFINE VIEW statement in the ABAP
development environment. Specify the base tables, select fields, and include
necessary annota ons and associa ons.
Explana on
Crea ng a CDS view involves defining its structure, rela onships, and any
required annota ons to guide its behaviour within the SAP environment.
What is the difference between JOIN and ASSOCIATION in CDS views?
While both JOIN and ASSOCIATION connect two tables or views, JOIN retrieves
data immediately, while ASSOCIATION defines rela onships that are evaluated
only when needed.
Explana on
Associa ons provide deferred data retrieval, unlike joins, which fetch the
related data at the me of query execu on.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


What is a virtual data model (VDM) in SAP?
A Virtual Data Model (VDM) is a layered data architecture built using CDS
views. It provides reusable and standardized data models for both transac onal
and analy cal purposes.
Explana on
VDMs enhance data reuse and integra on across different SAP systems by
standardizing data access through CDS views.
What are some best prac ces when crea ng CDS views?
Best prac ces include using proper naming conven ons, leveraging
annota ons effec vely, avoiding complex joins, and focusing on performance
op miza on for SAP HANA.
Explana on
Following best prac ces ensures that CDS views are efficient, maintainable, and
scalable within the SAP landscape.
How do you filter data in a CDS view?
Data in a CDS view can be filtered using the WHERE clause in the view
defini on or by defining parameters and annota ons to control data access
dynamically.
Explana on
Filtering data at the view level op mizes data retrieval and ensures that only
relevant data is processed and displayed.
What is a CDS table func on?
A CDS table func on is used to define a func on that returns a table as output.
It allows for more dynamic data retrieval by enabling procedural logic in data
access.
Explana on
CDS table func ons expand the flexibility of CDS views by allowing the
integra on of custom logic into the data retrieval process.
What is the purpose of the @OData.publish: true annota on?

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


The @OData.publish: true annota on is used to expose the CDS view as an
OData service. This allows external applica ons to consume the data via OData
protocols.
Explana on
This annota on enables seamless integra on of CDS views with external
applica ons through OData services.
How can you debug a CDS view?
CDS views can be debugged by tracing the SQL statements generated from the
view or using debugging tools available in the ABAP development environment
to analyse the data flow.
Explana on
Debugging tools provide insights into how the CDS view behaves during
execu on, allowing developers to iden fy and resolve issues.
What is a CDS metadata extension?
A CDS metadata extension allows developers to enhance an exis ng CDS view
by adding custom annota ons without modifying the original view defini on. It
provides a way to extend func onality.
Explana on
Metadata extensions promote the reuse of exis ng CDS views by allowing
addi onal annota ons without altering the base view.
What is a consump on CDS view?
A consump on CDS view is the top-level CDS view that is usually consumed by
applica ons or reports. It pulls data from other CDS views and prepares it for
use in a specific context.
Explana on
Consump on views are designed to provide data in a format that is ready for
applica on consump on, op mizing the end-user experience.
What are the benefits of using CDS views over ABAP queries?
CDS views provide be er performance, more flexibility, and advanced modeling
capabili es compared to ABAP queries. They are op mized for SAP HANA and
offer more powerful data retrieval mechanisms.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


Explana on
By u lizing CDS views, developers can take full advantage of SAP HANA’s in-
memory capabili es for faster and more efficient data processing.
What is a CDS role?
A CDS role is an access control mechanism used to define which users or roles
have permissions to access specific CDS views. It ensures secure data access
based on predefined rules.
Explana on
CDS roles provide fine-grained access control to ensure that sensi ve data is
protected according to user roles and permissions.
How do you handle performance op miza on in CDS views?
Performance op miza on in CDS views involves minimizing complex joins,
leveraging indexes, using efficient filtering, and reducing data sets through
aggrega on and pagina on techniques.
Explana on
Performance op miza on ensures that CDS views operate efficiently, even
when dealing with large data sets or complex queries.
What is a CDS view hierarchy?
A CDS view hierarchy defines a structured rela onship between mul ple views,
usually for organiza onal or repor ng
purposes. It allows for the representa on of hierarchical data.
Explana on
Hierarchical views make it easier to manage and report on data in structured
formats, such as organiza onal or geographical hierarchies.
Can you use aggrega on in CDS views?
Yes, CDS views support aggrega on func ons like SUM, COUNT, and AVG,
which allow data to be summarized and grouped for analy cal purposes.
Explana on
Aggrega on in CDS views helps in producing meaningful summaries of data,
o en for repor ng and analy cal purposes.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


What is the DISTINCT clause in CDS views?
The DISTINCT clause in CDS views is used to remove duplicate records from the
result set, ensuring that only unique data is retrieved and displayed.
Explana on
Using DISTINCT ensures that the data returned from the CDS view is unique,
avoiding duplica on in the result set.
What are CDS views annota ons used for security?
Annota ons like @AccessControl.authoriza onCheck are used in CDS views to
define security rules, ensuring that only authorized users can access specific
data.
Explana on
Security annota ons allow developers to enforce access control within CDS
views, protec ng sensi ve data from unauthorized access.
How do you handle associa ons in CDS views?
Associa ons in CDS views define rela onships between en es. They can be
used to dynamically retrieve data by naviga ng from one en ty to another
based on predefined associa ons.
Explana on
Associa ons are a key feature in CDS views, enabling flexible naviga on
between related en es for efficient data retrieval.
What is a CDS view proxy object?
A CDS view proxy object is an ABAP object that represents a CDS view in an
ABAP program. It allows the program to interact with the view and consume its
data.
Explana on
CDS view proxies provide a bridge between CDS views and ABAP programs,
enabling seamless data access.
Can you create a view on a view in CDS?
Yes, CDS views can be created on top of other CDS views, allowing for layered
data models. This promotes reusability and simplifies complex data modeling.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


Explana on
Crea ng views on top of exis ng views allows for more complex and layered
data models, improving modularity and reuse.
What are core data services (CDS) used for in SAP S/4HANA?
In SAP S/4HANA, CDS views are used to enhance data modelling and repor ng
capabili es, enabling real- me access to transac onal and analy cal data.
Explana on
CDS views provide a powerful data modelling framework for S/4HANA,
promo ng real- me data access and processing.
What is an analy c CDS view?
An analy c CDS view is designed for repor ng and analysis purposes, o en
used to expose data for SAP BW or SAP Analy cs Cloud. It includes aggrega on
and filtering capabili es.
Explana on
Analy c views are tailored for business intelligence purposes, providing
structured data for repor ng and analysis.
What is SAP HANA CDS view?
Core Data Services (CDS) as the name suggests, is a service directly by HANA
core. To present CDS in a very understandable manner, CDS is a view of one or
mul ple tables and can be enriched with metadata which makes it even more
useful than just a pile of dumb data. Just to men on some pointers which will
help to understand why CDS framework is more useful:
 CDS ar facts are present and execute on database(HANA or other) layer.
This strategy is called code push down where Applica on layer logic can
be easily moved to Database layer for execu on. This has many
performance advantages if used carefully.
 Can be assigned to authoriza on object and visibility can be easily
controlled
 CDS view can be easily consumed by oData service
 Can provide seman c informa on to each field which is par cularly
helpful when informa on is to be displayed on browser

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


 CDS can be buffered just like a transparent table
 Can be enabled for Search
 CDS can be used to define Data Hierarchy and rela onships which is
par cularly helpful is naviga on and drill downs
HANA is in memory database and performance capabili es can be leveraged
only when calcula ons are done in-memory. If the business logic is fully wri en
on the applica on layer and this defeats the purpose of in-memory
computa on. New HANA ar facts like CDS, AMDP(ABAP Managed Database
Procedure), CTE(Common Table Expressions) etc. fully complement code push
down and are designed for performance op miza on.
.
.
.
Which three TADIR objects/ar facts are created on ac va on of a ABAP HANA
CDS?
The ar facts created during CDS crea on are:
1. DDLS(Data Defini on Language Source) – We enter DDLS name along
with package name and Descrip on
2. VIEW(A structure which can be seen in SE11) – is men oned with
annota on @AbapCatalog.sqlViewName. Just press Control and Click on
View name and it leads to SE11 structure
3. STOB(Structured Object) – is men oned with ‘define view’ or ‘extend
view’ syntax.
How many types of ABAP HANA CDS views are there?
CDS view is evolving and new features are added with almost every technical
release.
1. CDS view
1. Basic CDS view
2. CDS View with Join

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


3. CDS View with Associa on
4. CDS View with Parameters
5. Extended CDS view
6. CDS View on View
Table Func on
7. Normal Table Func on
8. Table Func on with Parameters
Abstract En ty
9. Normal Abstract En ty
10.Abstract En ty with Parameters
What is Associa on and Path expression in ABAP HANA CDS?
Associa on
Associa on is different than join in that sense that associa on defines how two
en es are connected to each other. It is some mes understood as
“Conceptual Thinking” also because its nature of linking en es rather than
joining them directly. The join may be the next step once the associa on is
defined.

Cardinality
In database design, the cardinality or fundamental principle of one data aspect
with respect to another is a cri cal feature. The rela onship of one to the other
must be precise and exact between each other in order to explain how each
aspect links together.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


In the rela onal model, tables can be related as any of “one-to-many”, “many-
to-many” “one-to-zero-or-one”, etc.. This is said to be the cardinality of a given
table in rela on to another.
In terms of SAP:
 A [1..1] B means that for every row of A, there is a unique row in B and
vice versa
 A[0..1] B or just A [1] B means that B may have a record for which there
no source informa on in A.
 A [0..*] B means that B may have many records for which there no
source informa on in A.
Path Expressions
Path expressions iden fy an object by describing how to navigate to it to
objects via steps/route. For example, the path
expression Object.Employee.Address.ZipCode can refer to Zip Code of par cular
Employee’s address. Of course, this rela onship should be established
beforehand using associa on/cardinality to use this kind of Path to access
par cular informa on.
Can ABAP HANA CDS view have a tabular parameter (as of ABAP 7.52)?
No, CDS view takes only scalar parameters ( ll ABAP release 7.52)
What are the best prac ces which developers should keep in mind while
using ABAP Core Data Services (CDS)?
SAP ABAP HANA Core Data Services(CDS) are founda on of new ABAP. It uses
code push down technique and data virtualiza on for data fetching from much
faster HANA database.
Some of best prac ces are as below:
1. Use latest innova ons in CDS a er ABAP 7.50. They help to reduce ABAP
code logic and condi ons on applica on layer. CDS executes at Database
layer hence makes the applica on faster.
2. Publishes oData services on the fly

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


3. CDS can be consumed directly by Fiori reports effortlessly. This feature
should be used as and when required instead of providing conven onal
repor ng solu ons to customers(e.g. ALV).
4. Analy cs out of box
How ABAP CDS controls Access with DCL(Data Control Language)?
SAP ABAP HANA Core Data Services(CDS) uses syntax Define Role for access
condi on. This role management arrangement can further u lizes PFCG based
role access. Example:
@MappingRole: True
define role Test_CDS_Role {
grant select on Test_CDS_pfcg
where (bukrs) =
aspect pfcg_auth (p_bukrs, bukrs, actvt='03'
and land1 = 'DE'; }

And CDS view is as follows:


@AbapCatalog.sqlViewName: 'Test_CDS_01'
@AccessControl.authoriza onCheck: #CHECK
define view Test_CDS_pfcg
as select from t001{ key bukrs,
land1 };
Which annota on in SAP ABAP CDS View is used to define underlying ABAP
Data Dic onary(DDIC) structure?
ABAP Core Data Services uses syntax @AbapCatalog.sqlViewName to define
underlying ABAP Data Dic onary(DDIC) structure. Example:

@AbapCatalog.sqlViewName: 'DEMO_VIEW_ANNOT'

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


@AccessControl.authoriza onCheck: #NOT_REQUIRED
@ClientDependent: false
define view...
In above example, view DEMO_VIEW_ANNOT can be checked in ABAP
dic onary Transac on SE11 however it can’t be edited there. To edit a CDS
view, developer needs to use ADT(ABAP Development Tools for Eclipse).
Detailed tutorial on how to install & use ADT is HERE.
Another example:
@AbapCatalog.sqlViewName: 'Test_CDS_01'
@AccessControl.authoriza onCheck: #CHECK
@EndUserText.label: 'Demo View with Annota ons'

define view Test_CDS_pfcg


as select from t001{ key bukrs,
land1 };
@EndUserText.label is used to define short text of underlying ABAP Data
Dic onary(DDIC) structure.

Which between ABAP CDS en ty and CDS view should be used to query CDS
in ABAP program?
@AbapCatalog.sqlViewName: 'TEST_CDS_01'
@AccessControl.authoriza onCheck: #CHECK
@EndUserText.label: 'Demo View with Annota ons'

define view TEST_CDS_PFCG


as select from t001{ key bukrs,
land1 };

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


e.g. in above code, TEST_CDS_PFCG should be used for querying or
TEST_CDS_01?
If ABAP Core Data Services(CDS) needs to be consumed in SELECT statement,
always CDS En ty(here TEST_CDS_PFCG) should be used.
.
.
.
ABAP CDS syntax rules:
1. Maximum length of CDS en ty name?
2. Can Slash (/) be used to name an ABAP CDS en ty?
3. Is “.15” a valid literal in CDS defini on?
4. How to make comments in CDS code?
Can you write “Select” or “selecT” to SELECT a data in CDS defini on?
1. 30 Characters
2. Yes, Slash can be used to start name of CDS also
3. No, .15 is not a valid literal. Alterna vely 0.15 can be used
4. There are 3 ways to make comment in CDS code:
 Two slashes //
 Two hyphens —
 /* ……….. */
5. “Select” is correct however “selecT” is a syntax error

What is Cyclical Dependency in ABAP CDS?


There are primarily two types of dependencies in ABAP CDS viz. Technical and
Seman cal. A CDS can be created by calling/joining/associa ng another CDS

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


and this results in chain of dependencies. However, when dependencies point
to same CDS where it started, results in a Cyclical Dependency. e.g.
CDS View 2:
@AbapCatalog.sqlViewName: 'VIEW1'
define view TEST_VIEW1 as
select from
TEST_VIEW2
{ ...some Selec on... }
CDS View 2:
@AbapCatalog.sqlViewName: 'VIEW2'
define view TEST_VIEW2 as
select from
TEST_VIEW1
{ ...some Selec on... }

Cyclical dependencies can cause syntax error in CDS code. Normally they are
not reported un l CDS view is ac vated.
How to create oData service from a CDS?
A special annota on oData.Publish is used to create oData service from within
CDS view and that is also out of box. e.g.
@AbapCatalog.sqlViewName: 'VIEW1'
oData.Publish: True
define view TEST_VIEW1 as
select from
TEST_VIEW2
{ ...some Selec on... }

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


Once CDS is ac vated, oData service is published which can be further
registered in Transac on /IWFND/MAINT_SERVICE.
How to debug CDS view?
It is not possible to debug CDS view. If a CDS is using Table func on, then of
course underlying AMDP can be debugged.
CDS view is a by design is Database ar fact which can be created, modified and
accessed using ADT with Eclipse. CDS prac cally achieves Code Push Down for
AS ABAP.
.
.
.
How to find CDS views?
There are many ways to find CDS views:
1. With ADT: Type Ctrl(or CMD) + Shi + A >> Use search string with
wildcard “*” >> In the end write “type: ddls”
2. In Transac on SE16: Open Table TADIR >> OBJECT = DDLS >> OBJ_NAME
= <CDS name you are looking for with “*”>
3. In Transac on SE80: Take dropdown for “Development Object” >> Type
CDS name with wildcard “*” >> Sugges ons will automa cally come for
exis ng CDS names
.
.
.
What happens to underlying SE11 view(defined with
@AbapCatalog.sqlViewName) corresponding to CDS when a CDS view is
extended?
SE11 SQL view gets new fields under “APPEND” corresponding to new fields in
CDS extension. Size and name of new fields are in accordance with their
defini on in extended CDS.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


CDS view is a service directly by HANA core
 CDS ar facts are present and execute on database(HANA or other) layer.
This is called code push down where Applica on layer logic can be easily
moved to Database layer for execu on. This has many performance
advantages if used carefully.
 Can be assigned to authoriza on object and visibility can be easily
controlled
 CDS view can be easily consumed by oData service
 Can provide seman c informa on to each field which is par cularly
helpful when informa on is to be displayed on browser
 CDS can be buffered just like a transparent table
 Can be enabled for Search
 CDS can be used to define Data Hierarchy and rela onships which is
par cularly helpful is naviga on and drill downs
 Authoriza on objects: Authoriza on objects are generated based on the
CDS view defini on, which are used to control access to the CDS view.
 The GROUP BY clause is typically used in conjunc on with aggregate
func ons, such as SUM, AVG, COUNT, and MAX, to calculate summary
informa on about the grouped data.
Types of CDS views
1.
 CDS view
1. Basic CDS view
2. CDS View with Join
3. CDS View with Associa on
4. CDS View with Parameters
5. Extended CDS view
6. CDS View on View

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


 Table Func on
1. Normal Table Func on
2. Table Func on with Parameters
 Abstract En ty
1. Normal Abstract En ty
2. Abstract En ty with Parameters
2. Cardinality
 A [1..1] B means that for every row of A, there is a unique row in B and
vice versa
 A[0..1] B or just A [1] B means that B may have a record for which there
no source informa on in A.
 A [0..*] B means that B may have many records for which there no
source informa on in A.
Table Func on
Table func on a CDS Data Defini on Language(DDL) which uses syntax DEFINE
TABLE FUNCTION

4. system variables
 $session. Client is run me SAP client which is equivalent to sy-mandt in
AS ABAP

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


 $session.system_date is current system date and works same as sy-
datum in AS ABAP
 $session.system_language works very similar to sy-langu in AS ABAP
 $session.user is essen ally same as sy-uname in AS ABAP
5. @AbapCatalog.sqlViewName created corresponding DDIC structure
6. Max length of CDS – 30
How to create OData service from a CDS?
OData. Publish: True
8. It is not possible to debug CDS view. If a CDS is using Table func on, then of
course underlying AMDP can be debugged.
Path Expressions
Path expressions are used to navigate through associa ons in CDS views. In CDS
views, associa ons are defined between en es using the associa on keyword.
Path expressions use the associa on name and the cardinality symbols to
navigate through the associa ons
Limita ons of CDS
 Data Volume: ABAP CDS Views may not be the best choice for large data
volumes.
 SQL-based limita ons: ABAP CDS is based on SQL and as such, it has
some limita ons that are inherent to SQL.
Access control
One way to implement access control in ABAP CDS is to use the
“AUTHORIZATION CHECK” statement in the view defini on
Another way to implement access control in ABAP CDS is to use the ABAP
Authoriza on Object concept.
Annota ons
Annota ons in SAP ABAP CDS (Core Data Services) are a special type of
comment that can be added to CDS view defini ons to provide addi onal
metadata and informa on about the view

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


 Seman c informa on: Annota ons can be used to provide addi onal
informa on about the meaning of data fields in the view
 UI informa on: Annota ons can be used to provide informa on that can
be used to enhance the user interface of applica ons that use the view.
 Naviga on informa on: Annota ons can be used to specify rela onships
between CDS en es, which can be used to enable naviga on between
en es.
 @ObjectModel.rela on” annota on can be used to specify a rela onship
between two en es in the view, such as a one-to-one or one-to-many
rela onship.
SAP List Viewer with Integrated Data Access (ALV with IDA) – ABAP on HANA
provides ALV with IDA, which is an enhanced version of the standard ALV grid
control.
ABAP Managed Database Procedures (AMDP) – ABAP on HANA provides AMDP,
which is a programming model used to define and execute database
procedures directly within the ABAP applica on server. AMDP allows
developers to define database procedures using ABAP syntax, and it provides
advanced data access and processing capabili es, including support for CDS
views and Open SQL.
Best Prac ces
 Use Meaningful Names
 Define Rela onships Carefully:
 annota ons
 Op mize Query Performance: using Explain
 Test
DCL
Data Control Language (DCL) is used in ABAP CDS to define and enforce access
control rules for database objects.
 GRANT: Grants access to a specific object or opera on to a specific user
or role.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


 REVOKE: Revokes access to a specific object or opera on from a specific
user or role.
 DEFINE: Defines a new role or user group for access control purposes.
 SET PARAMETER: Sets system-wide parameters related to access control,
such as the maximum number of connec ons allowed per user.
Extending CDS views
CDS View extension works by using the “EXTEND VIEW” keyword, which allows
developers to create a new CDS view that references an exis ng view and adds
or modifies its fields and proper es.
Conversions
“@Consump on.valueMapping” annota on to specify the conversion factor for
the unit or currency. For example, to convert a quan ty field from “KG” to “G”,
use the following annota on:
@Consump on.valueMapping: 'KG:1, G:0.001'
To convert a currency field, use the following annota on:
@Consump on.valueMapping: 'EUR:1, USD:1.2'
String in CDS
 CONCAT: This func on is used to concatenate two or more strings.
Example: CONCAT('Hello', 'World') returns ‘HelloWorld’
 SUBSTRING: This func on is used to extract a substring from a string.
Example: SUBSTRING('HelloWorld', 6, 5) returns ‘World’
 LENGTH: This func on is used to determine the length of a string.
Example: LENGTH('HelloWorld') returns 10
The aggregate func ons “SUM”, “AVG”, “MIN”, “MAX”, and “COUNT” are used
in the SELECT clause to perform mathema cal calcula ons
CDS Test Double Framework
The CDS Test Double Framework allows developers to create test doubles for
CDS views that are used in the code being tested. This is useful when the CDS
view is not yet available, or when the real data would be too difficult or me-
consuming to set up for tes ng

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


@AbapCatalog.sqlViewName: 'ZVW_FLIGHTS'
@AccessControl.authoriza onCheck: #CHECK
define view ZFlights as select from sflight {
carrid,
connid,
fldate,
price
}
@AbapCatalog.sqlViewName: 'ZVW_FLIGHTS_D'
@AccessControl.authoriza onCheck: #NOT_REQUIRED
define view ZFlights_D as select from zfwk_test_dbl_view_provider-
>provide_view( 'ZVW_FLIGHTS' ) {
carrid,
connid,
fldate,
price
}

In this example, a new CDS view “ZFlights_D” is defined as the test double for
the original view “ZFlights”. The data for the test double is provided by the
“zfwk_test_dbl_view_provider” class using the “provide_view” method.
ABAP CDS Hierarchical Tes ng.
To perform ABAP CDS Hierarchical Tes ng, developers can use the ABAP Unit
Tes ng framework, which provides a comprehensive set of tools and features
to automate and simplify the tes ng process.
Types of views

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


In ABAP CDS (Core Data Services), there are three types of views: Basic,
Composite (Associa on), and Consump on views.
 Basic Views: A Basic view is the simplest type of ABAP CDS view, which is
based on a single database table.
 A Composite view is an ABAP CDS view that is based on mul ple
database tables, which are joined together through associa ons
 Consump on Views: A Consump on view is an ABAP CDS view that is
based on exis ng Basic or Composite views
CDS in OData
Using ABAP Annota on: In this approach, developers can annotate their CDS
views with OData-specific annota ons that define the metadata required to
expose the CDS view as an OData service. These annota ons provide
informa on such as the en ty set name, the key fields, and the naviga on
proper es
You can use the annota on modeler to add annota ons such as
@OData.publish, @OData.key, and @OData.naviga onProperty.
Create a Data Service: Use the SAP Gateway Service Builder to create a new
data service that will expose the CDS view as an OData service. In the Service
Builder, you can define the en ty set name, the key fields, and the naviga on
proper es based on the annota ons defined in the CDS view.
Fiori with CDS
 Define CDS Views: Define the required CDS views to fetch the data from
the database. Use ABAP Development Tools in Eclipse to create CDS
views.
 Define OData Service: Define the OData service for the CDS views using
the annota ons and annota ons files.
 Define Fiori Elements: Define the Fiori Elements applica on using the
annota ons in the annota ons file.
 Configure Launchpad: Configure the SAP Fiori Launchpad to add the new
Fiori Elements applica on.

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


 Test the Applica on: Test the Fiori applica on by launching it from the
Launchpad.
 Enhance the Applica on: Enhance the Fiori applica on by adding new
func onality using SAPUI5 controls and libraries.
 Deploy the Applica on: Deploy the Fiori applica on to the SAP Fiori
Launchpad to make it available to the users.
 Monitor the Applica on: Monitor the Fiori applica on using SAP Fiori
Launchpad administra on tools and resolve any issues that arise.
virtual element in CDS
a virtual element is a field that does not have a corresponding column in the
database but is computed dynamically when the en ty is read. Virtual
elements allow you to add fields to your data model without adding them to
the underlying data store.
@ObjectModel.virtualElement : true
Root view
The root view specifies the primary en ty to be used in queries and forms the
basis of the RESTful service that is automa cally generated
Define view and define en ty
DEFINE VIEW is used to define a view, which is a database object that provides
a virtual representa on of data from one or more underlying database tables.
Views are used to present data to users or applica ons in a more meaningful
way by joining or aggrega ng data from different tables. Views are read-only,
and changes made to the view data do not affect the underlying tables.
On the other hand, DEFINE ENTITY is used to define an en ty, which is a
database object that represents a specific table or view. En es are used to
define the structure of a table or view, including its fields, keys, and
rela onships with other tables or views. En es can be used to create or
modify tables, views, or other database objects.
Composi on in CDS
Composi on with cardinality is a feature in ABAP CDS (Core Data Services) that
allows you to define rela onships between two or more en es. The use of

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248


composi on with cardinality in ABAP CDS is to specify how en es are related
and how they can be navigated.
In ABAP CDS (Core Data Services), an associa on to parent is a type of
rela onship that allows you to define a hierarchical structure between two
en es. Specifically, it is a rela onship between a child en ty and a parent
en ty, where the child en ty references the parent en ty through a foreign
key.
en ty Employee {
key ID : Integer;
...
department : Associa on to Department;
}
en ty Department {
key ID : Integer;
...
employees : Composi on of many Employee on employees. Department =
$self;
}

Documents Prepared By Sonu Jangir Sap Abap +91 9729751248

You might also like