Templates For The CDS View
Templates For The CDS View
Table of Contents
Table of Contents 2
Overview 2
2
Overview
During the ABAP CDS View development, we spent many hours writing same
DDL source code.
Eclipse based ADT provides Data Definition Templates, to address the above
problem and reduce the time spent on ABAP CDS view development.
When you create an ABAP CDS view in ADT and follow the Data Definition
creation wizard, when you reach the step Templates, where you will find the
predefined code templates available for selection.
Eclipse ADT IDE provides 12 predefined ABAP CDS view templates. You can
view all data definition templates available in Window -> Preference section.
3
You can view the preview of Data Definition Template by selecting any of the
template.
You create additional Data Definition templates for your own use by
creating, editing and removing templates. Lets see how we can do it.
4
Create a New Template
2. On New Template dialog window. Specify the Name and the Description,
and select Data Definition (creation) as the Context.
3. Choose the Insert Variable button to add variables in the Pattern field.
Add annotations and other fields as per need to prepare your template. Here
I created the template with all annotations I need for SAP Fiori Elements
application.
5
4. Click on OK.
6
6. Finally our new template is ready for use. Lets create a ABAP CDS view
based on newly created template. Select the custom template
7. DDL source code is pre-populated based on the template, all you have to
do is to replace the table and field names.
7
ABAP CDS - DDL for Data Definitions
The CDS data definitions in ABAP CDS are created using the data definition
language CDS DDL in DDL source code. The CDS DDL follows the general CDS
syntax rules for ABAP CDS and comprises the following statements for the
definition and enhancement of CDS entities and CDS DDIC-based entities:
8
● Entity annotations
● Input parameters
● Typing
● Element annotations
■ Statements for CDS entity extensions:
● EXTEND VIEW ENTITY
● EXTEND ABSTRACT ENTITY
● EXTEND CUSTOM ENTITY
● EXTEND VIEW
● Define View
Defines a CDS view in the ABAP CDS in a CDS source code. A CDS is
implemented using a query select_statement. The annotation
AbapCatalog.sqlViewName must be specified before the view itself is defined
using DEFINE VIEW.
Two objects are created for a CDS view that is defined using DEFINE VIEW. A
name must be specified for each of the two objects:
9
on the database. The name given to the database view can no longer
be changed after the CDS view is transported into a follow-on system.
● The name cds_entity of the CDS entity is defined after the keywords
DEFINE VIEW (DEFINE is optional). No quotation marks need to be
specified. This name follows the rules of the CDS database view, but
can have 30 characters. The CDS entity represents all properties of the
CDS view.
Defining a join between two data sources of a CDS view in ABAP CDS.using
join expression.
● A join between two data sources using INNER JOIN or just JOIN selects
all entries of the data sources whose fields meet the ON condition.
● A join between two data sources using LEFT OUTER JOIN selects all
entries on the left side. A join between two data sources using RIGHT
OUTER JOIN selects all entries on the right side. Entries that meet the
ON condition have the same content as in the inner join. In entries that
do not meet the ON condition, the elements on the right or left side
10
have the null value that is set to a type-friendly initial value when the
CDS view is used in Open SQL.
11
optional domain prefix, a parameter, or a session variable can be
data source and a field of the right data source of the join must
be performed.
12
When specifying the ON condition, the following special rules apply:
2. A field of one of the two data sources data_source of the association can
be specified for lhs.
13
3. A field of one of the two data sources data_source of the association or a
literal can be specified for rhs.
4. At least one comparison for equality between a field of the initial data
source and a field of the target data source of the association must be
performed.
Defines Input parameters pname1,pname2 in a CDS View in ABAP CDS in a comma separated
list. Each input parameter must be typed with a data type parameter type.
14
In above shown example, here in zcds_view CDS view carid and conid are
used as parameters to get refined result based on filter values given by user
at the time of execution. In WHERE clause the parameters are mapped to
data source fields used in CDS view.
or an association.
expression.
15
Note:- The CDS views with parameters are not supported on all SAP certified
databases – At least SAP HANA does support it 🙂 . However, the DDL of the
ABAP CDS allows creating and accessing CDS views with parameters
independent of the database system.
16
■ CDS abstract entities
A CDS view entity is a CDS entity defined using the statement DEFINE VIEW ENTITY in the CDS DDL of
ABAP Core Data Services (CDS). A CDS view entity can be used to select fields from one or more data
sources (database tables or other CDS entities). Additional semantic properties can be added by
using annotations. CDS view entities are the successor of CDS DDIC-based views (obsolete). They
have the same structure and serve the same purpose as CDS DDIC-based views (obsolete). Generally
spoken, they represent an improved version of "classic" CDS DDIC-based views (obsolete).
When a CDS view entity is activated, a repository object is created. This repository object can be
accessed using the name of the CDS view entity. As a global data type, each CDS view entity
represents a structured type with the elements of the CDS view entity as components and can be
used like any CDS entity:
■ In ABAP CDS, the CDS entity can be used as a data source of other CDS entities.
■ In ABAP programs, the CDS entity can be used as a data type and in ABAP SQL read
statements.
■ The CDS entity cannot be used as a data type for definitions of dictionary objects.
The name of the CDS entity is in the namespace of all global types of an AS ABAP.
The following sections describe client handling and table buffering for CDS view entities. Afterwards,
the statement DEFINE VIEW ENTITY and all possible additions are described.
■ Client handling
■ Table buffering
17
■ Creation of a CDS view entity
A CDS projection view is defined in the DDL source code of a CDS data
definition using the statement DEFINE [TRANSIENT] VIEW ENTITY AS
PROJECTION ON in the CDS DDL of the ABAP Core Data Services (CDS).
18
A CDS projection view is based on a CDS entity and exposes a subset of its
features.
The name of a CDS projection view is in the namespace of all global types of
an AS ABAP.
Client handling is done implicitly and automatically for CDS projection views.
The rules are the same as for CDS view entities, see section ABAP CDS - Client
Handling in CDS View Entities.
Table buffering does not work for CDS projection views, since buffering in
general does not work with another CDS view as data source.
19
within the CDS data model. They are evaluated by the analytical engine.
For details, see the section about Analytical Queries.
■ no provider contract specified
Deprecated. It is strongly recommended that a provider contract is
specified. If no provider contract is specified, the same features are
available as for transactional queries. There are only a few differences
in the syntax checks to transactional queries. The differences are listed
in topic no contract.
20
ABAP CDS - Table Functions
A CDS table function is defined in the DDL source code of a CDS data
definition in the ABAP Development Tools using the statement DEFINE TABLE
FUNCTION in the CDS DDL of the ABAP Core Data Services (CDS). A CDS table
function includes the following:
21
FOR TABLE FUNCTION.
The parameter interface of the AMDP table function is defined using
the input parameters and the element list of the CDS table function.
22
The figure below presents a definition of AMDP function for Table function
with parameters.
23
Notes:-
A CDS hierarchy is defined in the DDL source code of a CDS data definition in the ABAP Development
Tools using the statement DEFINE HIERARCHY in the CDS DDL of the ABAP Core Data Services (CDS).
The name of the CDS hierarchy must match the name of the DDL source code.
A CDS hierarchy represents an SQL hierarchy created when the CDS hierarchy is accessed. CDS
hierarchies can currently only be used when the standard database is a SAP HANA database. When a
CDS hierarchy is activated, a view with the same name is created as an ABAP-managed database
object on the database. This view accesses a hierarchy generator function such as HIERARCHY.
A CDS hierarchy is declared as a CDS entity hierarchy using the statement DEFINE HIERARCHY. As a
global data type, the CDS entity represents a structured type with the elements of the CDS hierarchy
as components and can be used like any CDS entity.
■ In ABAP CDS, the CDS entity can be used as a data source of other CDS entities.
■ In ABAP, the CDS entity can be used as a data type and in ABAP SQL read statements.
■ The CDS entity cannot be used as a data type for definitions of dictionary objects.
24
A CDS hierarchy is located in the namespace of all global types of an AS ABAP.
When using CDS hierarchies, the handling of the special hierarchy attributes is of special
importance. These attributes occur as part of the result set of the hierarchy function on the
database:
25
■ In these cases, only the explicit elements of the element list are respected. These can,
however, represent hierarchy attributes.
A CDS custom entity is defined in the DDL source code of a CDS data definition using the statement
DEFINE CUSTOM ENTITY in the CDS DDL of the ABAP Core Data Services (CDS). The name of the CDS
custom entity must match the name of the DDL source code.
CDS custom entities allow developers to implement their own data provision using ABAP. Data
retrieval is implemented via an ABAP class and performed at runtime. On CDS level, only an
interface is defined, while the implementation of the logic is encapsulated in the application server
26
artifact. Custom entities are used if data access cannot be done via means of SQL and the available
CDS feature set and other CDS entity types. For example, custom entities can be used when
In the context of the ABAP RESTful Application Programming Model, custom entities are used as a
data model basis for RAP unmanaged queries.
■ ABAP CDS
● A CDS custom entity can be specified as the association target of a CDS association,
CDS composition, or CDS to-parent association. A CDS association, CDS composition,
or CDS to-parent association of this type can be exposed only and cannot be created
as an instance of a join expression. Such associations can only be followed in Fiori
OData scenarios where the RAP query engine (not SQL) is used to execute the query.
● Since no SQL artifact is generated for CDS custom entities and the query is
implemented in ABAP, a CDS custom entity cannot be used as a data source of
SELECT statements or used by SQL path expressions in other CDS entities.
■ ABAP Programs
● The structured type of the CDS custom entity is known in ABAP programs. Like the
type of any CDS entity, it can be used after the addition TYPE.
● A CDS custom entity cannot be used as a data source of SELECT statements or used
by path expressions in ABAP SQL.
■ Frameworks
27
● In the context of the ABAP RESTful Application Programming Model, custom entities
are used as a data model basis for RAP unmanaged queries. The ABAP query is in
this case executed by a framework such as the RAP query engine.
● The annotations of a CDS custom entity can be evaluated using the methods of the
class CL_DD_DDL_ANNOTATION_SERVICE.
● The parameters and the CDS associations of CDS custom entities can be evaluated
by frameworks such as the RAP query engine.
An instance of a CDS custom entity is not created as a database object and client handling is not
defined.
28
A CDS abstract entity is defined in the DDL source code of a CDS data definition in the ABAP
Development Tools (ADT) using the statement DEFINE ABSTRACT ENTITY in the CDS DDL of the ABAP
Core Data Services (CDS).
An instance of a CDS abstract entity is not created as a database object and client handling is not
defined. A CDS abstract entity can be used as follows:
■ ABAP CDS
● A CDS abstract entity can be specified as the association target of a CDS association,
CDS composition, or CDS to-parent association. A CDS association, CDS composition,
or CDS to-parent association of this type can be exposed only and cannot be created
as an instance of a join expression.
● A CDS abstract entity cannot be used as a data source of SELECT statements or used
by SQL path expressions in other CDS entities, such as CDS view entities or
DDIC-based CDS views.
■ ABAP Programs
● The structured type of the CDS abstract entity is known in ABAP programs. Like the
type of any CDS entity, it can be used after the addition TYPE.
● A CDS abstract entity cannot be used as a data source of SELECT statements or used
by path expressions in ABAP SQL.
● The statement ANNOTATE ENTITY can be used to add CDS metadata extensions to
the annotations of a CDS abstract entity.
■ Frameworks
● The annotations of a CDS abstract entity can be evaluated using the methods of the
class CL_DD_DDL_ANNOTATION_SERVICE.
● The parameters and the CDS associations of CDS abstract entities can be evaluated
by frameworks such as the RAP framework.
29
ABAP CDS - Common DDL Elements
■ Entity annotations
■ Input parameters
■ Typings
■ Element annotations
30
■ EXTEND ABSTRACT ENTITY
● This variant is used to define a CDS abstract entity extension for
a CDS abstract entity.
● Available since release 7.84.
■ EXTEND VIEW
● This variant is used to define a CDS view extension that is also
linked with a DDIC append view in ABAP Dictionary.
● Available since release 7.40, SP08.
● Recommended for extending CDS DDIC-based views (obsolete),
defined using the statement DEFINE VIEW.
31
Note:-
32
33