You are on page 1of 42

11/21/2019

SAP - ABAP CDS Development User


Guide
Generated on: 2019-11-21

SAP NetWeaver 7.5 | SPS15

PUBLIC

Original content: https://help.sap.com/viewer/f2e545608079437ab165c105649b89db/7.5.15/en-US

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/viewer/disclaimer.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 1/42
11/21/2019

About the ABAP CDS Development User


Guide
Scope of Documentation
This documentation describes the functionality and usage of tools for Core Data Services (CDS) within ABAP development for
SAP HANA scenarios. In particular, it focuses on use cases for creating, editing, testing, and analyzing ABAP CDS entities -
starting from the Eclipse-based IDE.

Target Audience
ABAP developers who are involved in the code push-down development activities.

Validity of Documentation
This documentation belongs to ABAP Development Tools for SAP NetWeaver and refers to the range of functions that have been
shipped as part of the standard delivery for SAP NetWeaver 7.5, SP03.

More on ABAP for SAP HANA Scenario

Tip
You can also visit our ABAP for SAP HANA space on SCN to view discussions and nd further resources on how ABAP-
based applications can leverage SAP HANA.

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 enhancement of a CDS view is de ned as source code in the CDS 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 an ABAP CDS entity, you rst need to create a DDL source 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
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 2/42
11/21/2019
In the DDL editor, you can only de ne one ABAP CDS entity in one DDL source.

Related Information
ABAP CDS in ABAP Dictionary

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 ABAP Dictionary, using the ABAP CDS
statement DEFINE VIEW. A CDS view serves to de ne the structure of an SQL view and represents a projection onto one or
several Dictionary tables or Dictionary views.

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

Defining the CDS view in the DDL editor

Example

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

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

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 3/42
11/21/2019

Activating CDS Views


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

The actual CDS entity

An SQL 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.

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 DDL
source 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 DDL source, you will generate –
using the activation process – exactly one SQL view and the corresponding CDS entity in the ABAP Dictionary.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 4/42
11/21/2019

CDS view building architecture

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

Developer-Relevant Activities
1. Creating DDL Sources

2. De ning a CDS view

See also: Editing DDL Source Code

3. Adding Access Control to CDS Entities

4. Checking Syntax of DDL Sources

5. Activating DDL Sources

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 Entities

8. [Optional:] Analyzing associations between views

See also: Working with 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:] Deleting DDL Sources

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 5/42
11/21/2019

Caution
Before deleting a DDL Source, 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 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
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

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 6/42
11/21/2019

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;

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
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 7/42
11/21/2019
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 DDL Sources

2. De ning a CDS table function

See also: Editing DDL Source Code

3. Adding Access Control to CDS Entities

4. Checking Syntax of DDL Sources

5. Activating DDL Sources

6. Implementing a CDS table function in the AMDP class

7. Debugging CDS Table Functions

See also: Debugging AMDPs

Related Information
ABAP CDS Synatx – Table Functions

Access Control for CDS Entities


ABAP Core Data Services (CDS) has its own authorization concept based on 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 service adaptation de nition language (SADL) or
Open SQL.

Overview of Process and Architecture


The following gure shows the main components for creating DCLs. After you have created the CDS entities you want to protect in
DDL, you use a wizard within the Eclipse-based ABAP IDE to create the DCL sources for the authorization objects. In DCL sources
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 SADL or Open SQL, the following is checked:

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

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 8/42
11/21/2019
If no role is de ned for a CDS entity, there are no restrictions on the data returned by the query.

2. Does the current user have the required authorizations?

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

When you activate a DCL source, SAP NetWeaver AS for ABAP generates the authorization views and lls the access control
management tables with the required metadata. The roles are characterized as global internal objects in the ABAP Dictionary.

Defining a DCL source in the DCL editor

Notes
We recommend that you continue to use the classical authorization concept for start authorizations (used to 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 (used to check the authorization of a user as de ned by the data model and the data in
question).

Related Information
Adding Access Control to CDS Entities
ABAP CDS - Access Control

Creating DDL Sources


Prerequisites
You need the standard developer authorization pro le to create ABAP development objects.

Context
A DDL source allows you to de ne an entity that represent as a projection onto one or multiple database tables. With the DDL
source you have the appropriate ABAP development object, which you can use directly to access the standard ABAP Workbench
functionality (transport, syntax check, activation).

Procedure
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e20… 9/42
11/21/2019
1. In your ABAP project, select the relevant package node in the Project Explorer.

2. Open the context menu and choose New Other ABAP Repository Object Core Data Services DDL Source to launch the
creation wizard.

3. In addition to the Project and Package, enter the Name and the Description for the DDL Source to be created.

Note
The maximum length for names of DDL sources is 30 characters.

4. Choose Next.

Wizard page when creating a DDL source

5. Assign a transport request.

6. Choose Finish.

Results
In the selected package, the ABAP back-end system creates an inactive version of a DDL source and stores it in the ABAP
Repository. In the Project Explorer, the new DDL source is added to the Core Data Services folder of the corresponding package
node. As a result of this creation procedure, the source editor will be opened. Here, you can start de ning a CDS entity.

Related Information
ABAP CDS Entities
ABAP Development Objects
Editing DDL Source Code

Activating DDL Sources


Prerequisites
Make sure that the DDL source you wish to activate is syntactically correct. The system performs a syntax check of the entire
object before it is activated.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 10/42
11/21/2019

Context
To generate a CDS view, you must activate the DDL source.

Procedure

To activate the DDL source from the DDL source editor ...

1. Open the relevant DDL source in the DDL editor.

2. Click the icon (Activate the ABAP Development Object) in the toolbar.

Tip
Alternatively, you can use the keyboard shortcut Ctrl + F3 .

To activate the DDL source from the Project Explorer ...

1. Select the node of the relevant DDL source in the ABAP project in the Project Explorer.

2. Open the context menu and choose Activate.

Results
In the selected package, the ABAP back-end system creates an active version of the CDS view and stores it in the ABAP Dictionary.
The corresponding CDS database view is added to the Core Data Services folder of the selected package.

Related Information
Displaying Activation Log for DDL Sources
Status of a Development Object
Previewing Data Records

Displaying Activation Log for DDL Sources


If activation errors should ever occur, it can be of advantage for you to be able to get more information on diagnosis and
troubleshooting. This information is provided with the activation log.

To view the activation log for an error item in the Problems view, select the corresponding function in the context menu.

To view the activation log from the DDL source editor, choose the toolbar menu Navigate Open Navigation Log .

Note
For details, see also: Troubleshooting for Dictionary Activation Errors

Editing DDL Source Code


Note
In the current version of the DDL editor within ABAP Development Tools, you can only de ne one CDS entity in a DDL source.

Sub Topics
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 11/42
11/21/2019
Getting Help for DDL Sources

Getting Support from Content Assist

Applying Quick Fixes

Using DDL Code Templates

Adding and Removing Comments

Changing Colors for DDL Sources

Comparing DDL Source Code Versions

Displaying CDS View Extensions

Getting Help for DDL Sources


When editing DDL sources, you will generally need to make use of the ABAP CDS language reference. Here, you can nd more
information about the syntax and meaning of ABAP CDS language elements. For this, ABAP Development Tools provides a
context-sensitive link (F1 help) from within the DDL source editor. The CDS help content is displayed in a separate help view.

In addition, you may need to display the de nition and documentation of elements used, like tables, views, or individual table
elds that you used when de ning CDS views in the DDL editor. For this purpose, press F2 to access the code element info popup.

Accessing CDS Language Reference (F1)


To access the CDS language reference, position the cursor on a CDS language element or annotation for which you need help and
press F1 .

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 12/42
11/21/2019

Context-sensitive language help in DDL editor

Tip
In addition, you will nd the complete CDS Language Reference on the SAP Help Portal.

Accessing Element Info (F2)


In the DDL source editor, move the cursor to the element of your interest and choose F2 .

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 13/42
11/21/2019

Opening the code element information popup

Tip
From within the element info popup, you have the option to open the ABAP Element Info view by pressing the Show in ABAP
Element Info View icon.

Tip
When opening the element info popup for a table, you have the option to show a tree-based display that indicates the includes
or append structures – if they are de ned for the table elds.

Element info popup for a table with appends or includes

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 14/42
11/21/2019

Tree display for a table with appends/includes

Getting Support from Content Assist


In the DDL source editor, the content assist proposes valid DDL keywords and identi ers to you that can be inserted within the
source code at your current position. Consequently, you can reduce the time spent on code editing and ensure that you are using
the valid source code elements.

The following help is provided by the content assist:

Keyword completion: The best matching DDL keyword is automatically proposed as soon as you start typing

Semantic keyword completion: A list of all matching DDL keywords is displayed for the position where you have chosen
the Ctrl + Space shortcut

Semantic completion (data source and signature parameter completion): This enables you to insert the best matching
data sources (tables) or add the parameters of a table to the DDL source code.

Keyword Completion
In the DDL source code editor, the best matching DDL keyword is displayed when start typing the keyword. If you choose the
tabulator key, the keyword is inserted.

Keyword completion in the DDL editor

Semantic Keyword Completion

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 15/42
11/21/2019
In the DDL source editor, you can open the code completion list manually at any position by choosing Ctrl + Space . This
enables you to add the possible keywords to your source code using the Shift + Enter shortcut.

Choose Ctrl + Space to display the list of suggested entries at this position

Semantic Completion
To get a list of best matching data sources (database tables, database views, CDS views, or CDS table functions), type the rst
letter(s) of the data source and then press Ctrl + Space .

Data source completion in the DDL editor

The list with the elements of the signature is automatically displayed after you have typed a dot as the component selector. This
enables you to add a component of a table to the DDL source code.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 16/42
11/21/2019

Completion of elements in the DDL editor

Using DDL Code Templates


Code templates can help to reduce the time spent on routine coding. The IDE provides a number of prede ned code templates for
DDL sources. In addition, you can create further templates for your own use.

To search for all DDL templates available...


1. Open the preferences page ABAP Development Editors Source Code Editors DDL Templates from the menu bar.

To use a template...
1. In the DDL source editor, write the beginning characters of the template.

2. Select Ctrl + Space (code completion).

Tip
Alternatively, you can use the Templates view to insert the template code in the DDL source using Drag & Drop.

To create an additional DDL template for your own use...


1. Open either the Templates view or the preferences page (referred above).

2. Open the New Template dialog and specify the Name and the Description, and edit the Pattern of the template.

Tip
If you want to add the new template to the DDL source creation wizard, select DDL (creation) as the Context.

3. Improve the format for the source code template manually.

4. Save the new template with OK.

Navigating Associations
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 17/42
11/21/2019
In addition to the F3 Eclipse navigation functionality, you can also navigate between the origin, the de nition, and the target of
the Associations you are using in your DDL source.

You have the following options:

Navigating to the Association Origin


If an association originates in another data source or is de ned within the same data source, you can navigate to its origin or
de nition as follows:

1. In the CDS source code editor, select the name of the Association.

2. Open the context menu on the name and chose Navigate To.

Note
Alternatively, you can press F3 or Ctrl + click . A small dialog is then opened below the Association name. Here you
choose Navigate To.

The cursor opens the corresponding DDL source and highlights the relevant origin or navigates to the relevant de nition within the
same DDL source. In both cases, the selected occurrences and names are highlighted.

Navigating to Association Targets


You can navigate to the origin data source of the Association's target – for example, another CDS entity or a database table – as
follows:

1. In the CDS source code editor, select the name of the Association.

2. Open the context menu on the name and chose Navigate To Target.

Note
Alternatively, you can press Ctrl + click . A small dialog is then opened below the Association name. Here you choose
Navigate To Target.

The target of the Association is opened in the appropriate editor.

Related Information
Opening Development Objects

Applying Quick Fixes


Quick xes enable you to resolve errors and warnings in the DDL source code using the corresponding functionality that is
provided in the Quick Fix popup.

In the DDL source code editor, the following quick xes are provided:

Name of SQL view is missing

Effect: Adds the annotation @AbapCatalog.sqlViewName: 'SQL_VIEW_NAME' , which speci es the name of the
SQL view to be generated in the ABAP Dictionary.

Name of SQL view append is missing

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 18/42
11/21/2019
Effect: Adds the annotation @AbapCatalog.sqlViewAppendName: 'APPEND_VIEW_NAME' , which speci es the
name of the append view that will be generated in the ABAP Dictionary.

GROUP BY clause is missing

Effect: Adds the GROUP BY clause that is required if aggregate functions (MAX, SUM, ...) are contained in the SELECT list.
In addition, all elements not de ned using aggregate functions are speci ed after GROUP BY.

EXTEND GROUP BY clause is missing

Effect: If the GROUP BY clause is already added, you can extend this group to include all elements not de ned using
aggregate functions and not yet part of the GROUP BY clause. The latter elements, when included, are also added to the
existing GROUP BY clause.

Alias is missing

Effect: Adds an alternative name (alias) for each aggregate function that is used as an element in the SELECT list.

To execute a quick x...


You can trigger quick xes in any of the following ways::

1. From the Problems view:

a. Click on the error to open the context menu.

b. Choose Quick x .

c. In the list of possible quick xes, double-click the relevant quick x function.

2. From the ruler bar in the DDL source code editor:

a. Click the error decorator in the ruler bar.

b. In the list of possible quick xes, double-click the relevant quick x function.

Adding annotation for missing SQL view name

3. From the Quick Assist view:

a. In the DDL source code editor, position the cursor where the error occurs and is highlighted.

b. In the Proposals tree, double-click the relevant quick x function.

De ning ON Conditions by Use of a Wizard


A wizard helps you to de ne the ON conditions in the JOIN clauses and ASSOCIATION de nitions of your CDS view de nition.

Prerequisites
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 19/42
11/21/2019
This function affects the CDS view in the currently opened editor.

Context
You can use the ON conditions wizard when de ning:

Joins between two data sources (JOIN condition) in a CDS view.

Conditions for association in a SELECT statement.

The wizard considers the used data sources and their elements and provides proposals (strategies) for joining the data sources.
As developer you can also specify the elements for a JOIN manually using drag and drop (User De ned strategy).

To launch the wizard, proceed as follows:

Procedure
1. Open the relevant CDS view in the DDL editor.

2. In the CDS source code, position the cursor on the ON keyword where you want to de ne an ON condition for a join or
association.

3. Press CTRL + 1 key shortcut.

Starting the ON conditions wizard from the quick fix view

A quick x view appears.

4. On the quick x view, double-click the De ne ON conditions entry to start the wizard.

Note
If the ON condition already exists, the mapping between elements of data sources will be displayed on the wizard page,
where you can then modify them.

5. To specify the condition expression, de ne the mapping between the source and the target data source.

The wizard offers you automatic proposals for mapping elements of the data sources:

Strategy > By Name: Elements with identical names are mapped to each other.

Strategy > By Foreign Key: Based on the foreign key relationship, that has been de ned for a table in the ABAP
Dictionary, mappings are suggested for each key de nition.

When using the User De ned option, you can map the elements in a straightforward manner using drag & drop.

In addition, the wizard provides you with additional functionality, so that you can:

Filter the data sources and their elements by

Name

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 20/42
11/21/2019
Dictionary type

Built-in type

Expand or collapse all elements of the

$parameter

$projection

data source

Access context menu functions to...

Delete a selected condition

Delete all conditions

Restore the initial mapping

Tip
To open the context menu on the wizard page, select the relevant element from the Source or Target area.

For defining mapping drag and drop relevant elements from source to target

6. Choose Finish.

Results
The wizard inserts the corresponding condition expression after the ON keyword into the DDL source code.

Note

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 21/42
11/21/2019
The wizard does not check the syntax or semantic correctness of a CDS view. So, the modi ed coding might contain syntax or
semantic errors.

Related Information
ABAP CDS – SELECT, Association
ABAP CDS – SELECT, JOIN

Adding and Removing Comments


Within DDL source code, double slashes ( //) introduce a comment that continues until the end of the line.

You can also use the following shortcuts for comments in the DDL editor:

Ctrl + < Add Comment The editor inserts a double slash (//) at the
beginning of each selected line.

Ctrl + > Remove Comment The editor removes an existing double slash
(//) at the beginning of each selected line.

Ctrl + 7 Toggle Comment The editor inserts or removes a double slash


asterisk (//) at the beginning of each
selected line.

Note
Alternatively, you can access the comments functions using the context menu entries of the DDL source editor ( Source Add
Comment... )

Changing Colors for DDL Sources


Context
The source code editor displays the DDL source code and annotation types with prede ned colors. However, you can change these
default settings to adapt them to your personal needs. You can de ne the color for displaying the keywords, identi ers,
annotation, or further code elements in DDL source code.

Procedure
1. Open the General Appearance Colors and Fonts preference page.

2. Expand the folders CDS DDL.

3. Select the text type you want to change and click the Edit... button.

4. Select the color and con rm with OK.

Remember
To restore the default color settings, click the Restore Defaults button.

Results
The new color settings become immediately effective in the source code editor.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 22/42
11/21/2019

Comparing DDL Source Code Versions


The following options are available for comparing DDL source code:

Comparing local changes using the local change history

Comparing changes from one transported version to another

Comparing changes across the ABAP systems.

For details, see also: Comparing Source Code

Displaying CDS View Extensions


DDL enables extensions of existing CDS view entities without modi cations. This is achieved using the EXTEND VIEW keyword:

EXTEND VIEW cds_view_entity WITH cds_view_entity_extension


{ ... };

For each CDS view entity that has been extended, a marker is added to the vertical ruler of the DDL source editor.

A marker indicates the extended CDS view entity

If you choose the marker, an extension popup will be opened. From this popup, you can navigate to the de nitions of the view
extensions that exist in the system.

Extension popup

Checking Syntax of DDL Sources


Context
With the editor check function, you can check whether the source code of DDL sources is syntactically correct or not.

To enable the check function, there are two options available:

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 23/42
11/21/2019
Automatic syntax check: This option is enabled by default for all source code based editors.

Note
If you wish to disable the automatic syntax check, you have to switch off the corresponding setting in the preferences:
ABAP Development Editors Source Code Editors Automatic syntax check .

Explicit syntax check: You can use this option whenever the automatic syntax check is disabled.

To trigger an explicit syntax check, proceed as follows:

Procedure
1. Open the editor with the relevant DDL source.

2. Click the icon (Check ABAP Development Object) in the toolbar. Alternatively, you can use the keyboard shortcut
Ctrl + F2 .

Results
If errors occur during the check, these will be issued to the Problems view and displayed there as ABAP Syntax Check Problem. In
addition, the code line with the error is labeled with a decorator in the DDL source editor.

Displaying syntax error in the DDL source

Tip
The DDL editor offers corrections to some problems found. In case of missing annotation, for example, you can take advantage
from the quick x for that speci c error item.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 24/42
11/21/2019

Accessing quick fix in the Problems view using the context menu of the error item

Related Information
Activating DDL Sources
Previewing Data Records

Working with the Graphical Editor


In the graphical editor, you can use any of the following options to see the source code of an entity:

Double-click the object

Use the context menu of the object

Related Information
CDS Graphical Editor
Displaying the Graphical Representation of DDL Source Code
Updating the Graphical Representation of a CDS Entity
Opening a CDS Entity in the Source-Based Editor
Highlighting Used Columns
Navigating Through Data Models
Positioning Objects Automatically in the CDS Source Editor
Printing and Exporting Diagrams

Displaying the Graphical Representation of DDL Source Code


The CDS Graphical Editor provides an overview of the various entities and their relationships in graphical format.

Context

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 25/42
11/21/2019
This visualization allows you to understand the code implementation much faster as you do not have to read and understand the
code itself.

Procedure
1. Open the context menu on a DDL source.

2. Choose Open With Graphical Editor .

Tip
Alternatively, you can also open the graphical editor from the DDL source editor context menu of a CDS entity using
Open With Graphical Editor .

Results
The CDS Graphical Editor is opened and provides a graphical display of the entity as described in the DDL source editor.

Related Information
CDS Graphical Editor

Updating the Graphical Representation of a CDS Entity


You can edit the source code in the text editor.

Context
Changes made in the text editor appear immediately in the graphical editor.

Note
Syntax errors appear as parsing errors in the object where the error occurred.

Syntax Errors

Procedure
1. Choose a CDS entity.

2. In the context menu of the CDS entity, choose Open With Graphical Editor .

3. In the context menu of the graphical editor, choose Open DDL Source Editor.

4. Make the required changes to the CDS entity in the source editor.

5. Choose the graphical editor view to see the changes.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 26/42
11/21/2019

Opening a CDS Entity in the Source-Based Editor


This functionality allows you to open the source code editor of a CDS entity from a graphical editor.

Procedure
1. Choose a CDS entity.

2. In the context menu of the CDS entity, choose Open With Graphical Editor .

The Graphical Editor is opened.

3. In the graphical editor, select the relevant entity and choose Open DDL Source Editor from the context menu.

Opening DDL Source Editor

Highlighting Used Columns

Context
This feature enables you to view the usage of a user-de ned type within the DDL source.

Procedure
1. Choose a user-de ned type.

2. In the context menu of the user-de ned type, choose the option Highlight Used Columns.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 27/42
11/21/2019

Highlighting Used Columns

Results
The user-de ned type appears highlighted.

Navigating Through Data Models

Context
If the data model is so large that not all the objects are visible in the graphical editor at once, you can use the Miniature View to
browse the data model.

Procedure
1. Open a CDS entity in a graphical editor.

2. Choose the Quick Access eld.

Tip
To navigate to Quick Access, you can also press CTRL + 3 .

3. In the Quick Access eld, enter Miniature View.

4. From the Views category, choose Miniature View.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 28/42
11/21/2019

Miniature View

Positioning Objects Automatically in the CDS Source Editor


The graphical editor positions the objects in the editor automatically.

Context
You can manually change the position of the objects, but these positions are not persisted. The next time you open the DDL
source, the graphical editor lays out the position of the objects automatically.

If you have manually changed the position of the objects, follow the step below to have the objects positioned automatically.

Procedure
In the context menu of the graphical editor, choose Auto Layout.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 29/42
11/21/2019

Auto Layout

Printing and Exporting Diagrams

Context
You can print or export object diagrams using the graphical editor.

Procedure
1. To print the graphical representation, select the relevant entity and choose Print from the context menu.

The Print preview and preferences dialog is opened. Here you select the relevant printer and print settings.

2. To export the graphical representation as an image le, select the relevant entity and choose Export from the context
menu.

The Export Diagram dialog is opened. Here you can select the relevant area for the graphical representation as well as the
target le format and its size to be generated as an image le.

Adding Access Control to CDS Entities


Prerequisites
You have the standard developer authorization pro le to create ABAP development objects.

Context
Use DCLs to develop access-control logic for Core Data Services (CDS) entities from SAP NetWeaver AS for ABAP. DCLs enable
you to lter access to data in the database based on static values or conditions based on user data (classical authorization
objects). If no DCL document for the CDS entity was created and deployed, a user who can access the CDS entity has access to all
data returned by the entity.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 30/42
11/21/2019

Example
For example, you provide a view of sales orders. You can add a condition that users can only view open sales orders or only
sales orders for companies, which are in the countries that are listed in a classical authorization object.

Tip
We recommend that you protect applications that use CDS entities with classic start authorizations available from SAP
NetWeaver AS for ABAP.

Procedure
1. Create the DCL sources.

2. Edit the DCL source code.

Edit DCL source code just as you would DDL source code.

There is no support for the following:

Quick xes

Adding and removing comments

Comparing DCL source code versions

3. Check the syntax of DCL sources

Check the syntax of DCL sources just as you would check the syntax of DDL sources.

4. Activate DCL sources.

Activate DCL sources just as you would activate DDL sources.

Activation logs for DCL sources are not supported.

Related Information
Creating DCL Sources
Editing DDL Source Code
Checking Syntax of DDL Sources
Activating DDL Sources
Access Control for CDS Entities

Creating DCL Sources


A DCL source allows you to limit the results returned by a CDS entity to those you authorize a user to see.

Prerequisites
You have the standard developer authorization pro le to create ABAP development objects.

You have created the CDS entities for which you want to restrict access.

Context
A DCL source is an ABAP development object, which supports standard ABAP Workbench functions such as transport, syntax
check, and activation.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 31/42
11/21/2019

Procedure
1. In your ABAP project, select the relevant package node in the Project Explorer.

2. Open the context menu and choose

New Other ABAP Repository Object Core Data Services DCL Source .

3. In addition to the Project and Package, enter the Name and the Description for the DCL source to be created.

Wizard Page When Creating a DCL Source

4. Choose Next.

5. Assign a transport request.

6. Choose Next.

7. Determine if you want to use a template for the DCL source.

Option Description

Use a template. SAP offers example templates for DCL sources. The template
provides you with example coding for you to modify.

Do not use a template. The tool creates an empty DCL source for you to ll.

8. Choose Finish.

Results
In the selected package, SAP NetWeaver AS for ABAP creates an inactive version of a DCL source and stores it in the ABAP
Repository. In the Project Explorer, the new DCL source is added to the Access Control Management Objects folder of the
corresponding package node. As a result of this creation procedure, the DCL source editor is opened. Here, you can start de ning
the role for the CDS entity.

Example
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 32/42
11/21/2019
The following role grants access to entries of the SFlight_Entity CDS entity, which meet the following conditions:

The ConnID of the entry has the same value as is assigned to the user through the PFCG authorization object S_CONNID
in the CONNID eld.

The CarrID of the entry has the value LH.

The @MappingRole annotation must have the value true, so this role is assigned to all users in the system. The value false is
not supported.

@EndUserText.label: 'Show only flights for which the carrier ID is LH'


@MappingRole: true
define role Sflight1 {
grant select on SFlight_Entity
where ( ConnID ) = aspect pfcg_auth( S_CONNID, CONNID) AND CarrID ='LH';
}

Related Information
Access Control for CDS Entities
Editing DDL Source Code

Previewing Data Records


Data Preview provides a test environment that enables you to verify the output (result set) of a CDS view.

Procedure
In the Project Explorer view, open the context menu of a DDL source and choose Open Data Preview.

Note
In addition, you can also open the Data Preview view from the source code editor of a DDL source. Then choose Open
With Data Preview from the context menu.

Results
1. If the CDS View does not require any parameters, the Data Preview displays the result set directly.

2. If the CDS View requires parameters, a dialog to enter parameter values appears:

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 33/42
11/21/2019

a. Enter your parameter values.

b. Choose OK.

The Data Preview displays the result set.

The Outline view displays parameter values of a CDS View. If you want to modify parameter values, choose the
Parameter option that appears in the Data Preview tool.

Note
If the result set contains less records than you expect, there may be a DCL role for the CDS entity that lters the data returned
by the preview.

Related Information
Activating DDL Sources

Working with Associations in the CDS Data


Preview
In CDS, an association represents the relationship between two CDS views.

Context
You use associations to:

Identify related CDS views. An association lists the hierarchy of related CDS views.

Navigate backwards and view the result sets of the previous CDS view in a hierarchy. Any lters applied to the result sets
are retained.

Procedure

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 34/42
11/21/2019
1. In the Project Explorer view, open the context menu of a DDL source and choose Open Data Preview.

Note
In addition, you can also open the Data Preview view from the source code editor of a DDL source. Then choose Open
With Data Preview from the context menu.

Note
If the selected CDS view requires parameters, a wizard for providing parameter values appears.

The Data Preview tool appears and displays the top 100 records by default.

2. In the table context menu, choose Follow Association.

Note
You can also choose > in the breadcrumb bar to follow an association.

Associations de ned for the CDS view are listed.

3. Choose an association.

Results
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 35/42
11/21/2019
The Data Preview tool displays the result set for the selected association. You can apply lters to the current result set or use the
breadcrumb to navigate to the previous result set.

You can use the SQL Console option on the Data Preview menu to view the generated Open SQL query for an association. The
generated query uses the SQL view to display records.

Analyzing Dependencies in Complex CDS


Entities
You use the Dependency Analyzer to view and analyze SQL dependency tree of views when implementing more complex CDS
views (based on view on view pattern).

Prerequisites
The SQL dependency of data sources can only be calculated for active version of the DDL source.

Context
To open the Dependency Analyzer, proceed as follows:

Procedure
1. In the Project Explorer, select the DDL source that includes the CDS view to be analyzed.

2. Open the context menu and choose Open with Dependency Analyzer .

Tip
Alternatively, you can open the same context menu from the DDL editor of the relevant CDS entity.

Results
The dependency of data sources involved in the CDS view de nition is calculated and displayed in a tree structure ( SQL
Dependency Tree tab).

Related Information
Dependency Analyzer View

Displaying The Annotation Values of an


Active CDS View
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 36/42
11/21/2019
You can display the annotation values of a CDS view, its elements, and its parameters in the Active annotations view. If the values
are inherited from underlying data sources or data elements, you can navigate to these development objects.

Prerequisites
The DDL source you are currently editing has already been activated.

Context
You can open the Active annotations view from the Project Explorer as follows:

Procedure
1. Open the context menu on a DDL source.

2. Choose Open with Active Annotations .

Note
Alternatively, you can open the same context menu from the DDL editor of a CDS view.

Results
The Active Annotations view is opened in the structured mode. It displays all the CDS annotations that are de ned in the CDS
view itself or are inherited from the underlying data sources or data elements.

Related Information
Active Annotations View

General DDL Syntax Rules


Keywords
Keywords must be written all-uppercase, all-lowercase, or capitalized; for example KEYWORD, keyword, and Keyword are
all valid notations for the same keyword, but keyWord and KeyWord will cause a syntax error.

Identi ers
Identi ers are case-insigni cant; for example, if two view entities are named myView and MYVIEW, respectively, there will
be a naming con ict.

The maximum length of identi ers is 30 characters.

Literals
Only single quotes are allowed for string literals.

Numbers cannot be abbreviated; for example .5 is not allowed for 0.5.

Comments
Double slashes ('//') start a comment from the token to the end of the line.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 37/42
11/21/2019
'/*' and '*/' delimit multi-line and inline comments.

Delimiters
Statements may be terminated with a semi-colon ';' .

Active Annotations View


In the Active Annotations view, the CDS annotations that are used for an active CDS view are displayed.

Annotations and their values can be de ned in the CDS view itself or inherited from the underlying data sources or data elements.
Annotation values are only inherited for elements ( elds and associations) and parameters. Parameters can only inherit from the
corresponding data elements, not from underlying data sources.

Example of a setup from an Active Annotations view an its functionalities

In the Active Annotations view, the following columns are displayed:

Annotated Elements: The view, its parameters, elds, and associations, and their active CDS annotations.

Annotation Value: Values of the corresponding CDS annotations

Origin Data Source: Name of the development object, for example, a DDL source or database table from which the
corresponding annotation is inherited. You can navigate to this object by double-clicking its name.

Origin Data Element: Name of the data element from which the corresponding annotation is inherited. You can navigate to
this object by double-clicking its name.

Here you can:

Enter a lter text in the search eld to display speci c entries in the Annotated Elements column.

Toggle between the at or structured display of the active annotations. The structured mode groups the CDS annotations
by their parent node and is set by default. To switch the display mode, choose the arrow button from the view toolbar and
select the relevant entry.

Related Information
https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 38/42
11/21/2019
Displaying The Annotation Values of an Active CDS View

Dependency Analyzer View


The Dependency Analyzer provides you with an overview of the complexity of the CDS entity with regards to the SQL de nition.

This means, you can see which database tables are used by your query to select data from the database and you can easily
identify redundant joins which might negatively affect the performance of your query.

The Dependency Analyzer recursively analyzes the data sources and also displays the indirect dependencies to other database
objects in the SQL Dependency Tree tab.

Calculated SQL dependency tree

The data sources involved are determined recursively and the result is displayed in a tree structure. As data sources, the following
entities are possible:

CDS Views

CDS Table Functions

Database Views

Database Tables

The following relations are considered in the dependency tree:

(SELECT) FROM

Joins: INNER, LEFT OUTER, RIGHT OUTER

Joins resulting from using Associations

Set operations: UNION, UNION ALL

This view also provides you with additional functionality to:

Refresh the dependency tree, for example, after modi cations have been made and the source has been activated

Expand/collapse all nodes in the tree structure

Navigate to the listed data sources through double-click or using the context menu

Export the dependency tree into a local CSV le

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 39/42
11/21/2019
Search for data sources within the tree structure

Example
As a developer who implements CDS views, you may not always be aware of the real JOIN behavior of the view de nitions at
database level – For example, the number of JOINs generated when you use Associations in a CDS view.

Related Information
Analyzing Dependencies in Complex CDS Entities

CDS Graphical Editor


The CDS Graphical Editor provides a read-only view containing CDS entities, user-de ned types, and the relationships between
entities in graphical representations.

The editor allows you to understand the code implementation much faster as you do not have to read and understand the code
itself.

Example of a data source structure displayed in the CDS Graphical Editor

In the CDS Graphical Editor, the following graphical representations of CDS entities are provided:

Symbol Description

Represents an entity

Represents a key element in an entity

Represents elements in an entity

Represents an association in an entity

Represents a user-de ned type.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 40/42
11/21/2019

Symbol Description

Also de nes an association

Note
This line indicates the relationship between entities. The
association name appears on the line. It also displays the
cardinality if you have de ned cardinality for the association.

Indicates an inner join

Indicates a left outer join

Indicates a union

The CDS Graphical Editor provides you with the following options:

View CDS entities in a source code editor

Make changes to the CDS entities in the source code editor and view the changes in the graphical editor

View usage of a user-de ned type within a DDL source

Navigate within a data model

Auto layout objects in the editor

Related Information
Working with the Graphical Editor

Glossary
Core Data Services (CDS)
CDS introduce a common set of domain-speci c languages (DSL) and services for de ning and consuming semantically rich data
models.

CDS Entity
Part of a DDL source

The de nition of a CDS entity is introduced with the DEFINE VIEW statement. A CDS entity is used to specify the structure of an
SQL view.

Data Control Language (DCL)


DCL is used to de ne authorizations for CDS entities. The main goal of CDS is to make the usage of SQL easier for application
developers. DCL offers a possibility to de ne the authorizations needed for the CDS entities in a modeled, declarative way.

DCL Editor
Text-based editor for editing DCL sources

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 41/42
11/21/2019
The DCL editor is part of ABAP Development Tools and allows you to de ne the role or access policy for the CDS entity.

DCL Source
ABAP development object that is used to de ne authorizations for CDS entities

A DCL source allows you to limit the results returned by a CDS entity to those you authorize a user to see.

Data De nition Language (DDL)


Subset of SQL

DDL statements are used to create and delete the entities of a relational database. In AS ABAP, DDL is integrated into ABAP
Dictionary.

DDL Editor
Text-based editor for editing DDL sources

The DDL editor is part of ABAP Development Tools.

DDL Source
ABAP development object that is used to de ne a CDS view entities

A DDL source is created in ABAP Repository using a wizard of ABAP Development Tools.

SQL View
Projection onto one or multiple relational database tables or other views

An SQL view is generated in the ABAP Dictionary after activation of the DDL source. The structure of an SQL view is de ned in a
CDS entity. SQL view is a technical representation of the CDS entity.

https://help.sap.com/http.svc/dynamicpdfcontentpreview?deliverable_id=21801752&topics=4ed1f2e06e391014adc9fffe4e2… 42/42

You might also like