Wednesday 16 December 2020

CDS View Entity

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

@AbapCatalog.preserveKey: true

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

@AbapCatalog.preserveKey: true

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: layer

@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

SAP ABAP Certification, SAP ABAP Exam Prep, SAP ABAP Prep, SAP ABAP CDS, SAP ABAP Career

Run Analytic Query

Analytic Query is a Consumption View type which works almost the same as BW 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.

SAP ABAP Certification, SAP ABAP Exam Prep, SAP ABAP Prep, SAP ABAP CDS, SAP ABAP Career

SAP ABAP Certification, SAP ABAP Exam Prep, SAP ABAP Prep, SAP ABAP CDS, SAP ABAP Career

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. 

SAP ABAP Certification, SAP ABAP Exam Prep, SAP ABAP Prep, SAP ABAP CDS, SAP ABAP Career

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.

SAP ABAP Certification, SAP ABAP Exam Prep, SAP ABAP Prep, SAP ABAP CDS, SAP ABAP Career

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

SAP ABAP Certification, SAP ABAP Exam Prep, SAP ABAP Prep, SAP ABAP CDS, SAP ABAP Career

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

SAP ABAP Certification, SAP ABAP Exam Prep, SAP ABAP Prep, SAP ABAP CDS, SAP ABAP Career

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

SAP ABAP Certification, SAP ABAP Exam Prep, SAP ABAP Prep, SAP ABAP CDS, SAP ABAP Career

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

No comments:

Post a Comment