Friday 8 July 2022

CDS Projection Views in ABAP CDS: What’s Your Flavor

Since kernel release 7.83, CDS projection views are available in different flavors, specified using the syntax statement PROVIDER CONTRACT. Each flavor has a different feature set and different syntax checks. This blog post describes the available types of CDS projection views and where to find further details.

CDS Projection Views, ABAP CDS, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Preparation, SAP ABAP Exam Preparation
Types of CDS projection views

CDS projection view: definition and purpose


CDS projection views are the top-most layer of a CDS data model. They expose data of an underlying CDS data model for a dedicated use case. They correspond to consumption views that make up the C-layer in the Virtual Data Model (VDM) that is used within S/4HANA.

Different kinds of CDS projection views are available. Each comes with its own feature set and its own syntax checks, designed for a dedicated purpose. The type of projection view is specified using the syntax statement PROVIDER CONTRACT.

The following types of CDS projection views are currently available:

Type Available since
CDS transactional query  Kernel release 7.76
SAP BTP ABAP Environment 1905
ABAP release 7.54 
CDS analytical query Kernel release 7.86
SAP BTP ABAP Environment 2111
Next big on-prem shipment, perhaps ABAP release 7.57 
CDS transactional interface  Kernel release 7.86
SAP BTP ABAP Environment 2111
Next big on-prem shipment, perhaps ABAP release 7.57 
No contract  Kernel release 7.76
Deprecated since kernel release 7.83 | SAP BTP ABAP Environment 2102 | ABAP release 7.56 when provider contracts were first introduced 

CDS transactional query


CDS transactional queries are intended for modeling the projection layer of a RAP business object in the context of the ABAP RESTful Application Programming Model (RAP).

Role of a CDS projection view of type transactional query in a RAP business service:

CDS Projection Views, ABAP CDS, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Preparation, SAP ABAP Exam Preparation

Example

@EndUserText.label: 'CDS projection view, REDEFINED ASSOC'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define root view entity DEMO_CDS_PV_PARENT
  provider contract transactional_query
  as projection on DEMO_CDS_VIEW_PARENT

    redefine association _child
      redirected to composition child DEMO_CDS_PV_CHILD

{
  key Id,
      Int1,
      /* Associations */
      _child.Int1 as field_exposure
      }

CDS analytical query


CDS analytical queries are designed for modeling analytical queries within a CDS data model. Previously, analytical queries were realized using “normal” CDS views (DEFINE VIEW). This had some disadvantages. Now, CDS projection views of type analytical query improve on the previous version of CDS analytical queries.

Example

@AccessControl.authorizationCheck: #NOT_ALLOWED
define transient view entity DEMO_CDS_ANALYTIC_CASE
  provider contract analytical_query
  as projection on DEMO_CDS_CUBE_VIEW
{
  so_key,

  currency_sum,

  //selection-related case expression
  @Semantics.amount.currencyCode: 'currency_sum'
  case when lifecycle_status between 'A' and 'B'
  then amount_sum else null end as QuantityAB,

  //formula-related case expression
  @Aggregation.default: #FORMULA
  case
  when created_on = $session.system_date
  then abap.int8'200'
  else abap.int8'700'
  end                 as formula_demo
}
where created_on = $session.system_date

CDS transactional interface


CDS transactional interfaces are intended to serve as stable public interface. They should be released for developer extensibility under a release contract (C0 or C1) and they provide the basis for a RAP BO interface in the context of the ABAP RESTful Application Programming Model (RAP). The feature set is restricted to projection elements from the underlying projected entity. No new associations, virtual elements, or fields can be defined.

Position of a CDS transactional interface in a CDS data model:

CDS Projection Views, ABAP CDS, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Preparation, SAP ABAP Exam Preparation

Example

@EndUserText.label: 'CDS transactional interface'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define root view entity DEMO_CDS_TRANS_INTERFACE_ROOT
  provider contract transactional_interface
  as projection on DEMO_CDS_PURCH_DOC_M
{
  key PurchaseDocument,
      Description,
      Status,
      Priority,
      /* Associations */
      _PurchaseDocumentItem: 
        redirected to DEMO_CDS_TRANS_INTERFACE_CHILD
}

No Contract


If no provider contract is specified…

◉ CDS projection views were first released with kernel release 7.76.

◉ The syntax PROVIDER CONTRACT was first introduced with kernel release 7.83.

◉ Projection views that were created before release 7.83 have no provider contract specified. These projection views are treated as transactional queries per default. The same statements are available and the same syntax checks are applied as for CDS transactional queries.

◉ Since provider contracts are available, it is mandatory to always specify a provider contract.

Source: sap.com

No comments:

Post a Comment