0% found this document useful (0 votes)
54 views21 pages

ABAP CDS Development User Guide 1726926497

The SAP ABAP CDS Development User Guide provides an overview of ABAP Core Data Services (CDS) entities, including how to define and implement CDS views and table functions. It outlines the process for creating data definitions, activating CDS entities, and managing access controls using data control language (DCL). Additionally, the document emphasizes the importance of using the official SAP Help Portal for complete and accurate information, as the generated document may be incomplete.
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)
54 views21 pages

ABAP CDS Development User Guide 1726926497

The SAP ABAP CDS Development User Guide provides an overview of ABAP Core Data Services (CDS) entities, including how to define and implement CDS views and table functions. It outlines the process for creating data definitions, activating CDS entities, and managing access controls using data control language (DCL). Additionally, the document emphasizes the importance of using the official SAP Help Portal for complete and accurate information, as the generated document may be incomplete.
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/ 21

8/27/2024

SAP - ABAP CDS Development User Guide


Generated on: 2024-08-27 09:05:00 GMT+0000

SAP NetWeaver Application Server for ABAP 7.52 | SP13

PUBLIC

Original content: https://help.sap.com/docs/SAP_NETWEAVER_AS_ABAP_752/f2e545608079437ab165c105649b89db?


locale=en-US&state=PRODUCTION&version=7.52.13

Warning

This document has been generated from the SAP Help Portal and is an incomplete version of the official SAP product
documentation. The information included in custom documentation may not re ect the arrangement of topics in the SAP Help
Portal, and may be missing important aspects and/or correlations to other topics. For this reason, it is not for productive use.

For more information, please visit the https://help.sap.com/docs/disclaimer.

This is custom documentation. For more information, please visit the SAP Help Portal 1
8/27/2024

ABAP CDS Entities


ABAP CDS entities are data models based on the data de nition language (DDL) speci cation and are managed by ABAP
Dictionary.

Overview
ABAP CDS provides a framework for de ning and consuming semantic data models on the central database of the application
server AS ABAP. The speci ed data models are based on the data de nition language (DDL) and the data control language
(DCL). So, a CDS entity or the extension of a CDS view is de ned as source code in the data de nition.

The following types of ABAP CDS entities are supported:

ABAP CDS Views

ABAP CDS Table Functions

De ning ABAP CDS Entities


To de ne or extend an ABAP CDS entity, you rst need to create a data de nition or metadata extension as the relevant
development object with which you can use the standard functions of the ABAP Workbench – such as syntax check, activation,
or connecting to the Transport Organizer. A CDS entity is de ned in the text-based DDL editor of ABAP Development Tools.

 Remember
In the DDL editor, you can only de ne one ABAP CDS entity in one data de nition or metadata extension.

Related Information
ABAP CDS in ABAP Dictionary (ABAP Keyword Documentation)

ABAP CDS Views


The data of an application is distributed across several database tables. Using ABAP CDS views, you can rearrange the table
elds according to application-speci c needs from the ABAP source code of your implementation.

De ning ABAP CDS Views


The structure of such a view is de ned by specifying the relevant database tables and the set of table elds to be used in the
view.

A CDS view is de ned for existing database tables and views, or for other CDS views in the ABAP Dictionary, using the DEFINE
VIEW DDL statement. A CDS view serves to de ne the structure of a CDS database view and represents a projection onto one
or several database tables or database views in the ABAP Dictionary.

 Note
CDS database views and CDS entities are part of one and the same namespace. Therefore, you must assign different names
for a CDS database view and the entity.

This is custom documentation. For more information, please visit the SAP Help Portal 2
8/27/2024

Defining the CDS view in the DDL editor

 Example
@AbapCatalog.sqlViewName: 'CUSTOMER'
DEFINE VIEW cust_book_view_entity AS SELECT FROM scustom
JOIN sbook
ON scustom.id = sbook.customid
{
scustom.id,
scustom.name,
sbook.bookid
}

The cust_book_view_entity CDS entity de nes a projection onto the database tables scustom and sbook by joining
both tables. The generated CDS database view (CUSTOMER) comprises the ID, the name, and the booking ID of all customers
for which the bookings exist.

Activating CDS Views


When activating a CDS view, the following objects are created in the ABAP Dictionary:

The actual CDS entity

A CDS database view

Accessing CDS Views in ABAP


Like regular Dictionary projection views, ABAP CDS entities can be used in ABAP Open SQL for data selection. The following
method lists the customer's booking data that is stored in the underlying database tables. As demonstrated in the listing below,
the CDS entity (in this case: cust_book_view_entity) is used for data selection in the ABAP source code.

 Example
CLASS cl_demo_access_cds_entity IMPLEMENTATION.
...
METHOD get_data.

This is custom documentation. For more information, please visit the SAP Help Portal 3
8/27/2024
SELECT id name bookid
FROM cust_book_view_entity
INTO TABLE @DATA(result_data)
WHERE ... .

ENDMETHOD.
...
ENDCLASS.

Overview of Process and Architecture


The following gure combines the main components of the view-building architecture and also displays the most important
activities that are involved in the view-building process. Using a wizard within the Eclipse-based IDE, you rst create the data
de nition as the relevant development object. In ABAP Development Tools, the text-based DDL editor is used to write source
code in which you specify the data de nition for a new CDS view. For each CDS view that is de ned in the data de nition, you will
generate – using the activation process – exactly one CDS database view and the corresponding CDS entity in the ABAP
Dictionary.

CDS view building architecture

 Note
When activating a data de nition, a CDS entity and CDS database view form a unity with the data de nition as development
object. So, after transporting the data de nition, the name of the CDS entity and CDS database view can no more be
changed. To rename any part of this unity, you need to delete the corresponding data de nition. Consequently, you recreate
it and use the new name for the relevant part.

This is custom documentation. For more information, please visit the SAP Help Portal 4
8/27/2024

Developer-Relevant Activities
1. Creating Data De nitions

2. De ning a CDS view

See also: Editing DDL Source Code

3. Adding Access Controls to CDS Entities

4. Checking Syntax of DDL Source Code

5. Activating Data De nitions

6. [Optional:] Previewing Data Records

7. [Optional:] Analyzing the SQL dependency tree of the view in case of more complex CDS views

See also: Analyzing Dependencies in Complex CDS Views

8. [Optional:] Analyzing associations between views

See also: Following Associations in the CDS Data Preview

9. [Optional:] Analyzing the relationship between views in a graphical tool in case of more complex views

See also: Displaying the Graphical Representation of DDL Source Code

10. [Optional:] Extending a CDS View of the SAP standard

See also: Creating Extend Views

11. [Optional:] Deleting DDL

 Caution
Before deleting DDL, check whether it is still being used by other development objects. To nd out if an object is still in
use, call the where-used function(Searching Usages (Where-Used)). See also: Deleting Development Objects

Related Information
ABAP CDS - View (ABAP Keyword Documentation)
Extend Views

ABAP CDS Table Functions


ABAP CDS table functions de ne table functions that are implemented natively on the database and can be called in CDS. As
such, they support the HANA platform code pushdown capabilities in ABAP CDS.

De ning ABAP CDS Table Functions


A CDS table function is de ned using the ABAP CDS statement DEFINE TABLE FUNCTION and can be used as the data
source in Open SQL read statements.

Each CDS table function includes the following components:

The actual CDS entity of the table function that is generated in the ABAP Dictionary

The CDS table function implementation (ABAP class library)

 Note

This is custom documentation. For more information, please visit the SAP Help Portal 5
8/27/2024
In contrast to the CDS views, the CDS table functions can be implemented using Native SQL. This implementation is done
within an AMDP method of an AMDP class and is managed as an AMDP function by the AMDP framework in the database
system.

Defining and Implementing CDS table functions

 Note
The name of the implementing AMDP method can only be speci ed in a single CDS table function (1: 1 relation).

 Example
Table Function De nition

In the following listing, a client-speci c ABAP CDS table function TAB_FUNCTION_EXAMPLE is de ned using the DDL syntax.
This table function declares two input parameters clnt (with the prede ned value: #CLIENT) and carrid, and a list of
elements that provide the return values of the AMDP method that implements the table function. The table function is
associated with the AMDP class CL_EXAMPLE_AMDP, where the method GET_FLIGHTS is used to implement the table
function.

 Sample Code
@ClientDependent: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
define table function TAB_FUNCTION_EXAMPLE

with parameters @Environment.systemField: #CLIENT


clnt:abap.clnt, carrid : s_carr_id
returns {
client : s_mandt;
carrname : s_carrname;
connid : s_conn_id;
cityfrom : s_from_cit;
cityto : s_to_city;

This is custom documentation. For more information, please visit the SAP Help Portal 6
8/27/2024

implemented by method CL_EXAMPLE_AMDP=>GET_FLIGHTS;

 Example
Table Function Implementation

The public ABAP class (AMDP class) in this example provides the AMDP method get_flights, which serves as the
implementation of the table function tab_function_example. As with any other AMDP class, cl_example_amdp
must implement the marker interface IF_AMDP_MARKER_HDB. The AMDP method get_flights implements the data
selection using Native SQL code.

 Sample Code
class cl_example_amdp definition public.

public section.
interfaces IF_AMDP_MARKER_HDB.
class-methods get_flights for table function tab_function_example.

protected section.
private section.
endclass.

class cl_example_amdp implementation.

method get_flights by database function


for hdb
language sqlscript
options read-only
using scarr spfli.
RETURN SELECT sc.mandt as client,
sc.carrname, sp.connid, sp.cityfrom, sp.cityto
FROM scarr AS sc
INNER JOIN spfli AS sp ON sc.mandt = sp.mandt AND sc.carrid = sp.carrid
WHERE sp.mandt = :clnt AND
sp.carrid = :carrid
ORDER BY sc.mandt, sc.carrname, sp.connid;
endmethod.

endclass.

Developer-Relevant Activities
1. Creating Data De nitions

2. De ning a CDS table function

See also: Editing DDL Source Code

3. Adding Access Controls to CDS Entities

4. Checking Syntax of DDL Source Code

5. Activating Data De nitions

6. Implementing a CDS table function in the AMDP class

7. Debugging CDS Table Functions

See also: Debugging AMDPs and CDS Table Functions

Related Information

This is custom documentation. For more information, please visit the SAP Help Portal 7
8/27/2024
ABAP CDS Synatx – Table Functions (ABAP Keyword Documentation)

Access Controls
ABAP Core Data Services (CDS) has its own authorization concept CDS access controls using a data control language (DCL).
The authorization concept of ABAP CDS uses conditions de ned in CDS and can draw upon classical (PFCG) authorizations to
check the authorizations of users.

The CDS authorization concept coexists with the classical authorization concept of SAP NetWeaver Application Server for ABAP
(SAP NetWeaver AS for ABAP). You can use the concepts together or independently from another. The classical authorization
concept is based on authorization objects. The authorization of a user occurs either implicitly, for example while calling a
transaction, or explicitly with the statement AUTHORITY-CHECK. The CDS authorization concept is based on implicit
authorization checks that occur during access attempts to CDS entities over Open SQL.

Overview of Process and Architecture


The following gure shows the main components for creating access controls (DCLs). First you create the CDS entities you
want to protect in data de nitions (DDLs). Next, use a wizard within the Eclipse-based ABAP IDE to create the access controls
for the authorization objects. In access controls you de ne CDS roles.

A developer de nes a CDS role in a separate CDS source code for a CDS entity using the DCL statement DEFINE ROLE. When
a CDS entity is accessed using Open SQL, the following is checked:

1. Is a CDS role de ned for the CDS entity?

If no CDS role is de ned for a CDS entity, there are no restrictions on the data returned by the query.

 Note
There are cases where a CDS role is de ned, but it is not taken into account at runtime.

The developer of the DDL source has set the annotation @AccessControl to #NOT_ALLOWED.

The DDL has been inherited by another CDS entity. Only the CDS role for the parent DDL is relevant at
runtime. If the parent DDL has no CDS role or the annotation @AccessControl has been set to
#NOT_ALLOWED, then the CDS role is masked and ignored at runtime.

The developer has added the keywords WITH PRIVILEGED ACCESS in the FROM clause of an Open SQL query.

2. Does the current user have the required authorizations?

If a CDS role is de ned for the CDS entity, access control management checks the current user for authorizations. The
system only reads data for which an authorization exists. CDS roles are assigned to all users implicitly.

When you activate an access control, SAP NetWeaver AS for ABAP generates the artifacts access control management needs
and saves them in the ABAP runtime environment. At runtime, an application accesses a CDS entity using Open SQL and ABAP
adds the restrictions to the selection conditions.

This is custom documentation. For more information, please visit the SAP Help Portal 8
8/27/2024

Defining an Access Control (DCL Source) in the Access Control Editor

Notes
We recommend that you continue to use the classical authorization concept for start authorizations. Start authorizations check
whether a user can start an application in the rst place. The CDS authorization concept can be used within an application to
perform instance-based authorization checks. Instance-based authorization checks the authorization of a user as de ned by the
data model and the data in question.

Related Information
Adding Access Controls to CDS Entities
ABAP CDS - Access Control (ABAP Keyword Documentation)

CDS Annotations
A CDS annotation (or annotation for short) enables you to add ABAP and component-speci c metadata to the source code of
any CDS entity.

Types in Accordance to the Evaluating Runtime


In accordance with consistency and how validity of annotations is evaluated, SAP's annotations are divided into the following
categories:

ABAP annotations are evaluated by the ABAP runtime environment.

Component annotations are evaluated by the relevant SAP framework.

Use
You can use code completion ( Ctrl + Space ) to add annotations directly in a data de nition, for example, before the
define statement or within a select list in a CDS view. The validity of the annotation then depends on the corresponding
position where you use it. If they are added at the wrong position, the source editor will mark and underline them in red.

In addition, you can use annotations in metadata extensions to de ne customer-speci c metadata for a CDS view without
modifying SAP's CDS entities itself. When using metadata extensions, you can overwrite speci c annotation values de ned in a
data de nition or add additional annotation values to an entity. Note that you can only use those annotations in metadata
extensions that are not relevant when activating CDS entities.

 Example

This is custom documentation. For more information, please visit the SAP Help Portal 9
8/27/2024

@AbapCatalog.sqlViewName: 'CUSTOMER'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions: true
DEFINE VIEW cust_book_view_entity
AS SELECT FROM scustom
JOIN sbook
ON scustom.id = sbook.customid
{
@EndUserText.label: 'Customer ID'
scustom.id,
@EndUserText.label: 'Customer Name'
scustom.name,
@EndUserText.label: 'Customer Booking ID'
sbook.bookid
}

The example from above demonstrates how you can use annotations and at which positions you can add annotations:

Annotations that are used before the define view statement are valid for the whole cust_book_view_entity
CDS view:

@AbapCatalog.sqlViewName: 'CUSTOMER': After activation, the CUSTOMER CDS database view is


created in the ABAP Dictionary.

@AccessControl.authorizationCheck: #NOT_REQUIRED: There is no access control required to


retrieve the selected data from the database.

@Metadata.allowExtensions: true: Allows you or other developers to overwrite or add annotations in


a metadata extension.

The @EndUserText.label annotation used before an element in the select list provides a text for the
corresponding eld.

Activation
Errors resulting from the use of component annotations do not prevent activation or creation of a CDS entity at the rst time.
They are only evaluated if the activation of the entity was successful.

Component annotations can result in the generation of other ABAP repository objects.

 Example
An OData service is generated when using the @OData.publish: true annotation. In this case, the annotation is
highlighted with a marker that provides additional information about the generated object.

Marker that highlights the creation of an OData service

 Note
When the CDS entity is activated, the OData service is generated automatically. After activation, it can be opened from the
ABAP Element Information popup of the corresponding database table. To do this, select the underlined "OData-Service" link
in the Generated Object section.

This is custom documentation. For more information, please visit the SAP Help Portal 10
8/27/2024
Subsequently, the OData service also needs to be activated in the transaction /IWFND/MAINT_SERVICE manually.

Related Information
ABAP CDS - Annotations (ABAP Keyword Documentation)
CDS Annotations (Framework-Speci c Reference Documentation)
Annotation Propagation
Active Annotations View
Displaying Annotation Values of an Active CDS View
Extracting CDS Annotations to a Metadata Extension
Activate OData Service in the SAP Gateway Hub

Annotation Propagation
The values of CDS annotations can be inherited and merged between CDS entities.

Use
You as a developer have the following possibilities to use annotations in order to provide metadata in your data model:

Use another CDS view as the data source

Use a data element

Use metadata extensions to enrich a CDS entity with customer-speci c annotation values

You can build hierarchies when selecting data from other CDS views. In accordance to this hierarchy and the corresponding
elements in the select list, the annotation values are propagated from bottom to top. In addition, you can also use metadata
extensions. Note that metadata extensions can also re ect a hierarchy when assigning several metadata extensions to a CDS
view.

You can assign customer-speci c metadata through annotations in one or more metadata extensions to one data de nition.

The precedence of the annotations contained in the metadata extensions is determined by the layer of the extension. For this
the following values are provided:

Value Description

This is custom documentation. For more information, please visit the SAP Help Portal 11
8/27/2024

Value Description

CUSTOMER Used by SAP's customers to de ne their own metadata

 Example
@Metadata.layer: #CUSTOMER

In this example, the value CUSTOMER is used for a metadata extensions.

 Note
All annotations provided in metadata extensions are compounded with the
annotations in the corresponding data de nition. Element annotations
(scope ELEMENT) are propagated in the view hierarchy.

CUSTOMER is the highest level. If there are several metadata extensions


provided for a data de nition, the metadata extension with the highest value
will be considered.

PARTNER Used by SAP partners to de ne their own metadata

INDUSTRY Used by SAP to de ne metadata for industry solutions

LOCALIZATION Used by SAP to de ne regional or country-speci c metadata

CORE Used by SAP to de ne metadata of their basis applications

Annotation Propagation View


The value of annotations can be propagated within the hierarchy of CDS entities or metadata extensions.

You use the Annotation Propagation view to display the currently active and inactive values of CDS annotations and the CDS
entities from which these values have been propagated in accordance to the current position of the cursor in the DDL editor.

This view displays the following information:

Source CDS entity or metadata extension from which the value of a CDS annotation originates.

If you provide several metadata extensions for a data de nition, you can reproduce how metadata extensions provide
metadata on different layers.

After generating, all involved annotation values and their corresponding data sources are listed. The effective entries are
highlighted in black. The metadata that is ignored is highlighted grey. Based on this list, you can now check which values are
considered from your data de nition.

You can also adapt the selection of the data source at any time. To do this, choose the corresponding Browse... button in the
Selection area. Select then the relevant data source or key.

API for Merging Annotations


To return the value of the active annotations, ABAP frameworks and development tools access metadata using the
CL_DD_DDL_ANNOTATION_SERVICE ABAP API. This API merges the values between the used CDS view hierarchy and
metadata extensions.

 Example
The following example visualizes merging annotations through the ABAP API:

This is custom documentation. For more information, please visit the SAP Help Portal 12
8/27/2024

Precedence of the metadata contained in the data definitions and metadata extensions is as follows: <CUSTOMER Extension 2> >
<PARTNER Extension 2> > <CDS View 2> > <CUSTOMER Extension 1> > <CORE Extension 1> > <CDS View 1>

The active annotations returned by the API for the elds of the CDS View <CDS View 2> are as follows:

Field Annotation Value for @Anno

eld_1 'View 1'

eld_2 'CORE Extension 1'

eld_3 'CUSTOMER Extension 1'

eld_4 'CUSTOMER Extension 2'

eld_5 'View 2'

Related Information
ABAP CDS - Evaluation of Annotations (ABAP Keyword Documentation)
ABAP CDS - Evaluation of Metadata Extensions (ABAP Keyword Documentation)
Annotation Propagation View
Analyzing Annotation Propagations

This is custom documentation. For more information, please visit the SAP Help Portal 13
8/27/2024

Extending CDS Entities


You can extend CDS entities of the SAP standard in order to add customer-speci c functionality to a data model without
resulting in modi cations.

CDS View Extensions


An CDS view extension is an extend view or metadata extension that provides additional elements or CDS annotations for a
CDS view.

You can use the following CDS view extensions to extend CDS entities:

Extend Views to add new elements to a CDS view from its underlying data source or de ne new associations for the CDS
view.

Metadata Extensions to overwrite existing or add new CDS annotations to a one or more elements or parameters of a
CDS entity.

Overview
The following example shows you how to extend a CDS view:

 Example
In the select list of the cust_book_view_entity CDS view:

The metadata of the scustom.id, scustom.name, and scustom.bookid elds is overwritten by the metadata
extension. When the corresponding data de nition is consumed, the metadata of the metadata extension is taken
into account.

The scustom.street and scustom.city database elds are added through the extend view. When you select
data from the corresponding data de nition, the data of these database elds will also be retrieved.

This is custom documentation. For more information, please visit the SAP Help Portal 14
8/27/2024

Possibilities to overwrite existing CDS annotations as well as to add elements to a CDS view

After creating a CDS view extension, the indicator is added at the define view statement to indicate that the select
list of the view has been extended.

Marker that indicates that the select list of the CDS view has been extended

Metadata Extensions
As of SAP NetWeaver AS for ABAP 7.51 innovation package, you can use metadata extenstions to add customer-speci c
annotations to SAP's CDS entities. Note that these changes do not result in modi cations.

De nition
A metadata extension is a development object that provides CDS annotations in order to extend the CDS annotations used in a
CDS view. The standard ABAP Workbench functions (transport, syntax check, activation, and so on) are supported.

Use
This is custom documentation. For more information, please visit the SAP Help Portal 15
8/27/2024
Metadata extensions enable you to write the annotations for a CDS view in a different document to separate them from the
CDS view.

Overview
The metadata of CDS views are not extensible by default.

To use a metadata extension for a CDS view, you have to consider the following conditions:

1. In the de nition of the CDS view, the @Metadata.allowExtensions annotation with the value true is added. This
annotation explicitly allows the use of metadata extensions.

2. In the metadata extension, you have to de ne the name of the CDS view to be annotated in the annotate view
statement.

3. In the Switch Framework, metadata extensions are switchable.

Advantages
You can bene t from the following advantages using metadata extensions:

1. Separation of Concerns: Separating the metadata speci ed in the annotations from the implementation of the view:

Improves the readability of the source code

Simpli es the development and maintenance of the CDS view

In addition, the metadata can be developed and updated independently of the data de nition.

2. ABAP Dictionary-independent activation: When activating a CDS view, the metadata extensions will be ignored. This
results in the following advantages:

It reduces the number of ABAP Dictionary (mass) activations required to develop and maintain the CDS view.

It speeds up the overall development process.

It facilitates changing the metadata of a CDS view in a running system, thereby reducing downtime.

3. Modi cation-free enhancements: Customers, partners, and industries can customize the metadata without modifying
the CDS view.

In addition, metadata extensions are switchable. This means, the metadata can be speci cally enabled or disabled
depending on the use case.

Activation
In general, in a metadata extension only those annotations are permitted that do not affect the ABAP Dictionary
activation/generation or the activation/generation of secondary objects (for example, OData services). For example, the ABAP
annotation @EndUserText and the component-speci c annotations @UI can be speci ed in metadata extensions. A syntax
error occurs if annotations that are not permitted are speci ed.

Obtaining Merged Annotations


The metadata contained in metadata extensions is only available to consumption clients that access the CDS view metadata
using the ABAP API CL_DD_DDL_ANNOTATION_SERVICE. In this case, metadata in the metadata extensions is merged
together with the metadata in the CDS view and also with the metadata that is inherited from underlying views (and metadata
extensions) in the view hierarchy.

Related Information
This is custom documentation. For more information, please visit the SAP Help Portal 16
8/27/2024
ABAP CDS Metadata Enhancements (ABAP Keyword Documentation)
Extracting CDS Annotations to a Metadata Extension
Creating Metadata Extensions
Annotation Propagation

Extend Views
An extend view is the extension of an existing CDS view using the extend view statement. The extend view itself is not a CDS
entity.

Use
When extending, you add further element(s) from the data source (such as a database table or another CDS view) to the select
list of an existing CDS view. So, you can enrich a CDS view that is, for example, part of the SAP standard without resulting in
modi cations.

Creating and De ning Extend Views


You create extend views on the basis of the Extend View template that is provided in the creation wizard of data de nitions.

Entry to add the Extend View template through the creation wizard of data definitions

In this template, the following placeholders are provided and need to be adapted:

${sql_view_append_name}: Name of the append view to be created in the ABAP Dictionary when activating the extend
view

${ddl_source_description}: Description to provide further information about the extend view

This is custom documentation. For more information, please visit the SAP Help Portal 17
8/27/2024
${view_name}': Name of the CDS view to be extended

${ddl_source_name_editable}: Name of the extend view

${data_source_name}: Name of the data source from which you want to add new elements to the CDS view

${element_name}: Name of the element(s) (for example, elds or associations) to be added

 Sample Code
@AbapCatalog.sqlViewAppendName: 'DEMO_EXT_VIEW'
@EndUserText.label: 'Demo'
extend view Demo_Data_Model_Base with Demo_Extend_View {
spfli.countryfr as CountryFrom,
spfli.countryto as CountryTo
}

The Demo_Extend_View extend view extends the select list of the Demo_Data_Model_Base CDS view with the
countryfr and countryto elds. This data is now also provided whenever the Demo_Data_Model_Base CDS view is
used.

Activating Extend Views


When activating a data de nition containing the extend view statement,

an append view that represents the added eld(s) is created in the ABAP Dictionary

the extended eld(s) is added to the existing CDS view on the database

 Note
They are then

considered for every occurrence where the extended CDS view is used.

represented in the SQL Create statement.

Related Information
ABAP CDS - EXTEND VIEW (ABAP Keyword Documentation)
Creating Extend Views
Creating Data De nitions

ABAP CDS Test Double Framework


CDS Test Double Framework enables developers to test the logic expressed in their CDS entities in an automated way using the
well-known ABAP Unit test or Hierarchy test framework.

Challenges with Conventional ABAP Solutions


Since the logic in a CDS entity is executed in the underlying database, which is independent of the ABAP runtime, it is not
possible to use conventional ABAP solutions for inserting dependencies. The depended-on components (DOC) of the CDS
needs to be doubled in the database. It needs to be ensured that the database engine calls or executes these Test Doubles
instead of the dependent component when the CDS is tested.

This is custom documentation. For more information, please visit the SAP Help Portal 18
8/27/2024
In order to test the logic in CDS entity under test (CUT), it is required to insert test data into the double. This data is
returned by the Test Doubles when the CUT is executed. CUT must not be modi ed by the test framework to enable unit or
hierarchical testing. For example, the test frameworks should not modify the view de nition to exclude elds, joins, lters and so
on to enable certain testing aspects of its runtime behavior.

CDS Test Double Framework


Use CDS Test Double Framework to addresses these challenges. It enables unit or hierarchical testing of CDS views by
automatically:

1. Creating "updatable" Test Doubles for each dependent component in the same database schema. The framework
double that gets created is a stub which has the same structure as the original dependent component:

2. Creating a Clones of the CUT wherein the actual logic of the CUT is preserved and the actual entites of the DOC are
replaced by the corresponding Test Doubles.

CDS Test Double Framework

This is custom documentation. For more information, please visit the SAP Help Portal 19
8/27/2024

Related Information
ABAP CDS Unit Testing
ABAP CDS Hierarchical Testing
Glossary

ABAP CDS Unit Testing


CDS Test Double Framework enables automatic unit testing of CDS views.

The development object for CDS unit testing is a CDS view for which the runtime entity is in database layer (SQL View). Using
CDS Test Double Framework APIs available in ABAP unit class, you can write an ABAP unit test for a CDS View for runtime
artifacts that are in two different layers. You can also create test doubles for database entities.

CDS Test Double Framework:

Creates a copy of CDS under Test

Creates "updatable" doubles for each dependent component

 Note
The double has the same structure as the original dependent component.

Copies depended-on database tables, but do not copy its data and primary key constraints

Creates database tables for depended-on database views. These tables have the same structure as the
depended on database views

Copies depended-on database functions (resulting from depended-on CDS views with parameters) and modi es
the implementation of function double to "insert" desired test-data into the double

Supported Test Scenarios


CDS Test Double framework supports stubbing the following dependent components:

DDIC tables

DDIC views

CDS views
This is custom documentation. For more information, please visit the SAP Help Portal 20
8/27/2024
CDS views with Parameters

External Views

Table Functions

CDS special functions (CURRENCY_CONVERSION and UNIT_CONVERSION)

 Note
You can also turn on/off DCL for a given CDS. We recommend you to turned off DCL to truly isolate the CDS during unit
testing.

Related Information
Unit Testing in ABAP
Writing Unit Tests Using CDS Test Double Framework

ABAP CDS Hierarchical Testing


Developer can test the logic for all the dependencies in the hierarchy path of a given CDS View under test for the Doubles
creation.

You must select exact one dependency anywhere in each hierarchy path. You must choose the database dependencies in the
CDS View Hierarchy for which you wants to create Doubles for. The framework creates the Doubles for the dependent
database entities that are selected. For the database entities in the hierarchy path, that are above of these selected entities,
framework creates Clones entities. These cloned entities preserve the logic in the entity. However, these cloned entities point
to either the other Clones or Doubles as its dependencies than the actual database entities.

The database entities in the hierarchy path that are below these selected entities are not considered.

Related Information
Writing Hierarchy Test using CDS Test Double Framework

This is custom documentation. For more information, please visit the SAP Help Portal 21

You might also like