ABAP - Keyword Documentation →  ABAP - Core Data Services (ABAP CDS) →  ABAP CDS - Data Definitions →  ABAP CDS - DDL for Data Definitions →  ABAP CDS - CDS Entities →  ABAP CDS - Projection Views →  CDS DDL - CDS Projection View, Transactional Queries → 
Mail Feedback

CDS DDL - DEFINE VIEW ENTITY AS PROJECTION ON, Transactional Query

Syntax

[@entity_annot1]
[@entity_annot2]
...
[@proj_view_annot1]
[@proj_view_annot2]
...
DEFINE [ROOT] VIEW ENTITY projection_view
   [ PROVIDER CONTRACT TRANSACTIONAL_QUERY]
    AS PROJECTION ON cds_entity [AS alias_name]
   [association1 association2 ...]
   [redefined_assoc1 redefined_assoc2 ...]
      { projection_list }
   [WHERE cds_cond]


Additions:

1. ... ROOT

2. ... AS alias_name

Effect

Defines a CDS transactional query with the name projection_view in CDS DDL. A CDS projection view is a direct projection of an underlying CDS entity cds_entity (called projected entity) and exposes a subset of the elements of the projected entity, which are defined in the projection list projection_list.

The projected entity cds_entity can be either a CDS view entity, a CDS transactional interface, or a CDS DDIC-based view (obsolete). No other CDS entities or data sources are allowed as projected entity. Path expressions are not allowed for specifying the projected entity. One CDS entity can be used as basis for multiple CDS projection views.

The name of the CDS projection view projection_view is defined after the DEFINE VIEW ENTITY statement. The usual rules for ABAP Dictionary views apply to this name and it is not case-sensitive (it is transformed internally into uppercase letters). It can have a maximum of 30 characters and is in the namespace of all global types of an AS ABAP. The name of the DDL source and of the CDS entity must be identical.

Prerequisites

A CDS transactional query that uses the addition PROVIDER CONTRACT TRANSACTIONAL_QUERY must be part of a RAP business object. That means that the view must either be a root entity itself, or it must be part of a composition tree and reach a root entity via a composition.

Components

Hints

Example

The following CDS transactional query DEMO_SALES_PV_BUPA is a projection of the existing CDS view DEMO_SALES_CDS_BUPA. The result set contains only rows where the last name of the business partner starts with P.

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Projection View for BuPa'
define root view entity DEMO_SALES_PV_BUPA
provider contract transactional_query
  as projection on
    DEMO_SALES_CDS_BUPA
    {
      key id          as BusinessPartnerID,
          given_name  as GivenName,
          middle_name as MiddleName,
          family_name as FamilyName
    }
  where $projection.familyname like 'P%'


Example

The following CDS transactional query DEMO_SALES_PV_SO_I_SL is a projection of the existing CDS view DEMO_SALES_CDS_SO_I_SL. It exposes a subset of the elements of the projected entity as well as an association.

A provider contract is not specified, since the provider contract is specified only once in the root entity of a CDS composition tree and all child entities automatically inherit this provider contract. In this case, the root entity is DEMO_SALES_PV_SO and it specifies the business object as transactional query.

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Projection View SO Item Schedule Line'
@Metadata.allowExtensions: true
define view entity DEMO_SALES_PV_SO_I_SL
  as projection on
    DEMO_SALES_CDS_SO_I_SL
    {
      key schedule_line_key as ScheduleLineKey,
          parent_key        as SalesOrderItemKey,
          _SalesOrderItem : redirected to parent DEMO_SALES_PV_SO_I
    }


Addition 1  

... ROOT

Effect

The keyword ROOT specifies that the projection view is the root entity of a composition tree. The projection view must always reflect the position of the projected entity in the composition tree: if the projected entity is a root entity, the projection view must be a root as well. If the projected entity is not a root, the projection view cannot be a root. In this case, the projected entity must contain a to-parent association.

Note: If a CDS projection view is defined as transactional query using the addition PROVIDER CONTRACT TRANSACTIONAL_QUERY, then the view must either be a root entity itself, or it must be part of a composition tree and reach a root entity via an association.

Addition 2  

... AS alias_name

Effect

Defines the name alias_name as alias name of the projected entity. The alias name can have a maximum of 30 characters. If no name is defined explicitly using AS, then the original name of the data source is used.