Skip to Content
Technical Articles
Author's profile photo Masaaki Arai

CDS View Entity

Purpose of this blog

As of ABAP 7.55, a new type of CDS entity, CDS View entity is available, in which DDIC SQL View is no longer created together, so the activation time is optimized (about a half time in an internal test).

Details about CDS View entity are explained in the following blogs.

 

The purpose of this blog is to show the created CDS view entities including Analytic Query, Extended entity, Annotate Entity in the system.

 

Test system

  • S/4HANA On premise 2020 Initial shipment stack
  • ABAP Platform Initial shipment stack (SAP_BASIS 755/0000 with SAP Kernel 781 patch19).

 

Summary

  • DDIC SQL View is not created but View is generated in database layer only. The name of the view is the same as CDS View entity name.
  • To extend CDS View entity, Extend entity is used in which DDIC SQL View is not created either.
  • To add annotations to the CDS View entity, Annotate entity should be used.
  • Analytic Query name is “2C<CDS View entity>” normally, not “2C<SQL View name>, but can be renamed with annotation @Analytics.technicalName: ‘<ShortUniqueIdentifierForTheView>’.
  • CDS View can work as the ODP Data source to send data to BW or the data source in ETL tools like SDI.
  • CDS View entity can use CDS View as the source of CDS View entity and vice versa.

 

Definitions of CDS View entity and relevant views

Interface View: ZI_ACDOCA10


@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'ACDOCA'
@Analytics: { dataCategory: #CUBE,dataExtraction.enabled: true }
@OData.publish: true
@Metadata.allowExtensions: true
define view entity ZI_ACDOCA10
  as select from acdoca
  association [0..1] to I_Segment as _Segment on acdoca.segment = _Segment.Segment
{
  rldnr,
  rbukrs,
  gjahr,
  ryear,
  poper,
  fiscyearper,
  periv,
  ktopl,
  racct,
  kokrs,
  prctr,
  @ObjectModel.foreignKey.association: '_Segment'
  segment,
  matnr,
  rbusa,
  bstat,
  rtcur,
  rhcur,
  @DefaultAggregation: #SUM
  @Semantics.amount.currencyCode: 'rtcur'
  tsl,
  @DefaultAggregation: #SUM
  @Semantics.amount.currencyCode: 'rhcur'
  hsl,
  _Segment
}


 

Extend entity: ZX_ACDOCA10

Field kunnr with master view I_Customer, Product type with I_Product._ProductType are added with Extend View entity.


extend view entity ZI_ACDOCA10 with
association [0..1] to I_Customer as _Customer on acdoca.kunnr = _Customer.Customer
association [0..1] to I_Product  as _Product  on acdoca.matnr = _Product.Product
{
  @ObjectModel.foreignKey.association: '_Customer'
  acdoca.kunnr,
  @ObjectModel.foreignKey.association: '_ProductType'
  _Product.ProductType,
  _Customer,
  _Product._ProductType
}

 

Analytic Query: ZC_ACDOCA10

@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'ZC_ACDOCA10'
@Analytics.query: true
define view entity ZC_ACDOCA10
  as select from ZI_ACDOCA10
{
  //ZI_ACDOCA10
  rldnr,
  rbukrs,
  gjahr,
  ryear,
  poper,
  fiscyearper,
  periv,
  ktopl,
  @AnalyticsDetails.query.axis: #ROWS
  racct,
  kokrs,
  prctr,
  segment,
  matnr,
  rbusa,
  bstat,
  rtcur,
  rhcur,
  kunnr,
  @AnalyticsDetails.query.display: #KEY_TEXT
  ProductType,
  tsl,
  hsl,
  /* Associations */
  //ZI_ACDOCA10
  _Segment
}

 

Annotate entity: ZM_ACDOCA10

@Metadata.layer: #CORE
annotate entity ZI_ACDOCA10 with
{
  @EndUserText.label: 'SegmentTxt'
  segment;
}

DB hint cannot be added with Annotate entity but can be done with Annotate View.

Target of Annotate entity is not only CDS View entity but other CDS objects like CDS Projection View, Table Function.

Annotate View: ZM_ACDOCA20

@Metadata.layer #CORE
@Consumption.dbHints: ['USE_OLAP_PLAN ']
annotate view ZI_ACDOCA10 with
{
}

 

Object checks

SQL View in database layer

Although DDIC SQL View is not created, the database view is created internally in HANA DB layer as shown below.

Run the following query with Transaction DBACOCKPIT > Diagnostics > SQL Editor

 

select top 100 * from ZI_ACDOCA10

Result

 

Run Analytic Query

Analytic Query is a Consumption View type which works almost the same as BW Query. See the blog for more about Analytic Query (CDS Query).

The name of the Analytic Query is “2C<CDS View entity name>” (It can be renamed with annotation @Analytics.technicalName: ‘<ShortUniqueIdentifierForTheView>’). In CDS View, the Analytic Query name is “2C<SQL View name>”.

The query “2CZC_ACDOCA10” can be run with the Transaction RSRT.

 

 

Data Source

ZI_ACODOCA10 is set as Data Source (@Analytics.dataExtraction.enabled: true), so it works as ODP data source to send data to BW, or can be used as the data source in the ETL Tools like Data Intelligence and Smart Data Integration. See the blog for more about ODP.

In BW system, run Replicate the Data Source (Transaction RSA1 > Data Source, and select BW system. in the context menu in the right side, select Replicate Data Source). Select the CDS View entity name (“ZI_ACODCA_F”). “_F” is added as suffix as is the transaction data.

Now the CDS View entity is added as ODP Data Source.

Select change in the context menu of the ODP Data Source and activate it.

 

Go to preview tab and run “Read Preview Data”.

 

 

CDS View entity using CDS View as the source and vice versa

CDS View and CDS View entity can be nested: CDS View can use CDS View entity as the source and vice versa.

CDS View Z_VBAPVBEP2

@AbapCatalog.sqlViewName: 'ZVBAPVBEP2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_VBAPVBEP2'
define view Z_VBAPVBEP2
  as select from Z_VBAPVBEP
{
  //Z_VBAPVBEP
  vbeln,
  posnr,
  etenr,
  netwr,
  waerk
}

CDS View entity Z_VBAPVBEP3

@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Z_VBAPVBEP3'
define view entity Z_VBAPVBEP3
  as select from Z_VBAPVBEP2
{
  //Z_VBAPVBEP2
  vbeln,
  posnr,
  etenr,
  @DefaultAggregation: #SUM
  @Semantics: { amount : {currencyCode: 'waerk'} }
  netwr,
  waerk
}

 

Others

  • The View created with Key user Tool “Custom CDS views” is CDS View, NOT CDS View entity (future plan).
  • is not possible at the moment (future plan).

 

Thanks!

Assigned tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sai Reddy
      Sai Reddy

      Is there a way to extend and add fields to a SAP provided CDS "root custom entity", eventually to display additional field on Fiori screen?

      Author's profile photo Masaaki Arai
      Masaaki Arai
      Blog Post Author

      Hello Sai,

      See the blog for extend view.

      https://blogs.sap.com/2018/08/22/sample-custom-cds-view-using-predefined-virtual-data-model-and-extend-view-in-s4hana/

      Self-join optimization:

       

      Supposed a VDM has the following structure

       

      Interface View1

      |

      Private View2

      |

      Private View1

      |

      ACCOCA

       

      Now you want to add the fiend X which has already been in ACDOCA but not in Interface View1.

      When you associate ACDOCA to the Interface View1 with Extend View, “join ACDOCA to ACDOC” should not happen thanks to “Self-Join optimization”.  When this kind of join happens, HANA SQL optimized understood Join is not needed to get the value of Field X, but optimize the SELECT statement to get the value of field X together with other fields from ACDOCA when data is selected from the original source ACDOCA, and remove the second join of ACDOCA internally. How cleaver the HANA is !

      Thanks, Masa

      Author's profile photo Sai Reddy
      Sai Reddy

      Hi Masa,

      That blog seems to be about CDS Views. I am trying to extend (add fields) a CDS entity (not view) that has been defined as a "root custom entity" specifically C_ProcmtDocSubcontrgHierarchy in S4-2020.

      SAP's CDS Custom Entity built as in this tutorial,

      Implement a CDS Custom Entity and Query Implementation Class | Tutorials for SAP Developers

      Regards,
      Sai

      Author's profile photo Sai Reddy
      Sai Reddy

      Hi Masa,

      Found a "Extend custom entity" but looks like that isn't supported by the latest hana studio/s42020 fps01

      https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abencds_cus_entity_extend_glosry.htm

      And the "Extend view entity" doesn't work for custom entity.. "Extension not supported for abstract and custom entities"

      Any solutions or thoughts would be highly appreciated?

       

      Regards,
      Sai

      Author's profile photo Andrea Schlotthauer
      Andrea Schlotthauer

      Hi Sai,

      CDS custom entity extensions are currently under development and they are not yet publicly available.

      Currently available are:

      • EXTEND VIEW ENTITY for CDS view entities and CDS projection views
      • EXTEND ABSTRACT ENTITY for CDS abstract entities
      • EXTEND VIEW for CDS DDIC-based views.

      Currently, it's not possible to extend CDS custom entities.

      Best

      Andrea

       

       

      Author's profile photo Sai Reddy
      Sai Reddy

      Thanks Andrea.

      Just wondering which S4 on-premise release can we expect this functionality?

      Author's profile photo Andrea Schlotthauer
      Andrea Schlotthauer

      Sorry, this is not sure yet and we can't commit to any release.

      The next on-premise release will be shipped in October this year and you can check the release news to see whether it's available.

      Author's profile photo Gaurav Karkara
      Gaurav Karkara

      Hi Masa,

      For extend entity ZX_ACDOCA10, below code:

      @ObjectModel.foreignKey.association: '_ProductType'
        _Product.ProductType,

      There is no association '_ProductType' defined, but there is one '_Product'. Can you help to understand this?

      Gaurav

      Author's profile photo Masaaki Arai
      Masaaki Arai
      Blog Post Author

      Hi,

      _Product._ProductTyp

      has been added.

      regards, Masa

      Author's profile photo Yiqun Shuai
      Yiqun Shuai

      Hello Masa

      I go through your blog and we are try to check how to use the CDS view to consumer as CDS entity.

      could you please give me the detail for CDS View Z_VBAPVBEP in how to code this entity and then CDS view can consume this CDS view entity.

      Thanks and regards
      Peter