Show TOC

ABAP CDS ViewsLocate this document in the navigation structure

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

Defining ABAP CDS Views

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

A CDS view is defined 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 define 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
Figure 1: Defining the CDS view in the DDL editor
@AbapCatalog.sqlViewName: 'CUSTOMER_VW'
DEFINE VIEW cust_book_view_entity AS SELECT FROM scustom
     JOIN sbook 
     ON = sbook.customid

The CDS entity cust_book_view_entity defines 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.

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.

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

Overview of Process and Architecture

The following figure 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 first 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 definition for a new CDS view. For each CDS view that is defined in the DDL source, you will generate – using the activation process – exactly one SQL view and the corresponding CDS entity in the ABAP Dictionary.

CDS view building architecture
Figure 2: CDS view building architecture

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. Defining 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
    Caution Before deleting a DDL Source, check whether it is still being used by other development objects. To find out if an object is still in use, call the where-used function(Searching Usages (Where-Used)). See also: Deleting Development Objects