Skip to Content
Technical Articles
Author's profile photo Lakshminarasimhan Narasimhamurthy

Simple way to Identify the ABAP CDS views for the datasource in B4HANA

Introduction

Many a times we need to get the ABAP CDS view for the datasource in B4HANA system. This is needed to check and understand the code/annotations within the CDS view. There is a very simple way we can get the CDS views for a datasource.

Applies to

BW/4HANA

Summary

In BW4HANA system we are going identify the datasource and we are going to identify the respective ABAP CDS view in the source S4 Hana system.

Author          : Lakshminarasimhan Narasimhamurthy

Created on   : 29/Sep/2021

Body

Requirement

Many a times I had to deep dive into the CDS view for a datasource in B4HANA system. This is a frequent activity which needs to be performed at the source. So to make it easy I have created a very simple CDS view to identify the CDS view for a datasource.

This can be achieved using 2 tables,

“cdsviewanno” — Contains all the annotations(We are focused on “Analytics” annotations). We know all the CDS views which are supporting the datasource in B4HANA system will have “Analytics” annotations.

“cdsviewcrossref”  — Contains the CDS view for the DDIC object.

 

Every datasource will have a DDIC object mentioned in them. This object gets automatically generated when the CDS views are activated and they can be identified in the ABAP CDS view from the annotation “@AbapCatalog.sqlViewName”.

Datasource%20showcasing%20the%20DDIC%20object

Datasource showcasing the DDIC object

 

Now we are going to identify the CDS view based on the DDIC object. We are going to join 2 tables cdsviewanno & cdsviewcrossref as given below

@AbapCatalog.sqlViewName: 'ZCDSCDSDSINFO'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: false
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS Based Datasources Info'
define view zcds_cds_ds_info as select distinct from cdsviewanno 
inner join cdsviewcrossref on cdsname = objectddlsourcename
{
key cdsname as Cdsname,
key sqlviewname as DDICObject,
key annotationname as Annotationname,
annotationvalue as Annotationvalue,
actualposition as Actualposition,
nextannotationname as Nextannotationname    
}

 

You execute the above CDS to get all the DDIC object and the respective CDS view. since the join leads to more a 2 million + rows lets restrict it to Annotation = “ANALYTICS”

@AbapCatalog.sqlViewName: 'ZCDSCDSDSINFO'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: false
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS Based Datasources Info'
define view zcds_cds_ds_info as select distinct from cdsviewanno 
inner join cdsviewcrossref on cdsname = objectddlsourcename
{
key cdsname as Cdsname,
key sqlviewname as DDICObject,
key annotationname as Annotationname,
annotationvalue as Annotationvalue,
actualposition as Actualposition,
nextannotationname as Nextannotationname    
} where annotationname like '%ANALYTICS%'

It is always better to make it parameterized. So below is the view which accepts single DDIC object

@AbapCatalog.sqlViewName: 'ZCDSCDSDSINFO'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: false
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS Based Datasources Info'
define view zcds_cds_ds_info 
with parameters v_ddicObj : abap.char( 30 )
as select distinct from cdsviewanno 
inner join cdsviewcrossref on cdsname = objectddlsourcename

{
key cdsname as Cdsname,
key sqlviewname as DDICObject,
key annotationname as Annotationname,
annotationvalue as Annotationvalue,
actualposition as Actualposition,
nextannotationname as Nextannotationname    
} where sqlviewname = $parameters.v_ddicObj

Executing%20the%20parameterized%20CDS%20view

Executing the parameterized CDS view

i am passing the DDIC object “ICASEAPROFILE” present in the datasource. Below is the output of the CDS view

CDS%20Result

CDS Result

 

From the output I can see that the CDS is “I_CASEATTRIBUTEPROFILE” and their annotations.

Now I am more interested in getting CDS views only with “ANALYTICS” annotations and those which are extraction enabled, so I will create a CDS view to extract only Annotations like ANALYTICS.DATAEXTRACTION.ENABLED and value is true

@AbapCatalog.sqlViewName: 'ZCDSCDSDSINFO'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: false
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS Based Datasources Info'
define view zcds_cds_ds_info -- CDS Datasource Information with Analytic 
as select from cdsviewanno 
inner join cdsviewcrossref on cdsname = objectddlsourcename

{
key cdsname as CDSName,
key sqlviewname as DDICObject,
key annotationname as Annotationname,
annotationvalue as Annotationvalue,
actualposition as Actualposition,
nextannotationname as Nextannotationname    
} where annotationname = 'ANALYTICS.DATAEXTRACTION.ENABLED' and annotationvalue = 'true'

Based on this view output I will create below CDS view,

@AbapCatalog.sqlViewName: 'ZCDSCDSDSDET'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: false
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS Based Datasources Details'
define view zcds_cds_ds_det 
as select distinct from cdsviewanno as A
inner join zcds_cds_ds_info --First CDS which identifies only those with analytics annotations
as B on A.cdsname = B.CDSName {
key A.cdsname,
key B.DDICObject,
key A.annotationname,
A.annotationvalue,
A.actualposition,
A.nextannotationname  
}

Now execute the above CDS view “zcds_cds_ds_det” to get the CDS view with DDIC objects.

 

Also we can add “Analytics” annotations to the view as given below and then consume it in real time from B4HANA system.(Steps to make it real time can be found in Real time report using ABAP CDS views | SAP Blogs)

 

@AbapCatalog.sqlViewName: 'ZCDSCDSDSDET'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: false
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS Based Datasources Details'

@Analytics.dataCategory: #DIMENSION
@Analytics.dataExtraction.enabled: true
@ObjectModel.representativeKey: [ 'cdsname', 'DDICObject', 'annotationname' ]

define view zcds_cds_ds_det 
as select distinct from cdsviewanno as A
inner join zcds_cds_ds_info --First CDS which identifies only those with analytics annotations
as B on A.cdsname = B.CDSName {
key A.cdsname as cdsname,
key B.DDICObject as DDICObject,
key A.annotationname as annotationname,
substring(A.annotationvalue, 1, 250) as annotationvalue,
A.actualposition,
A.nextannotationname  
}

 

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.