How to find CDS View Entity?

How to find CDS View Entity?

How to find CDS view Entity or CDS view?

We need to fetch below data related to customer, check if any CDS view already exist to fulfil our requirement.

Create CDS view entity with below code:

Below code helps to find both CDS views and CDS view entity.

Note: code works on and after ABAP release given below

@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.ignorePropagatedAnnotations: true
@EndUserText.label: ‘find cds view based on data element name’
define view entity ZFIND_CDS_VIEW_ENTITY
with parameters
field1 : abap.char(30), // data element name
field2 : abap.char(30), // data element name
field3 : abap.char(30) // data element name

field4 : abap.char(30) // data element name
as select from DDCDS_ENTITY_ELEMENTS
{
entity_name as cds_view_entity
}
where data_element = $parameters.field1

intersect

select from DDCDS_ENTITY_ELEMENTS
{
entity_name as cds_view_entity
}
where data_element = $parameters.field2

intersect

select from DDCDS_ENTITY_ELEMENTS
{
entity_name as cds_view_entity
}
where data_element = $parameters.field3

intersect

select from DDCDS_ENTITY_ELEMENTS
{
entity_name as cds_view_entity
}
where data_element = $parameters.field4

Execute CDS view entity and provide input as data element of fields:

Most of time we provide alias names to CDS views fields so it’s always better to use data element of field instead of using field names.

Result:

CDS View Entity: ZFLIGHT has all required fields

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘zflight’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define view entity zflight as
select from sbook as a
inner join scarr as b on b.carrid = a.carrid
inner join scustom as c on c.id = a.customid
{
a.carrid,
b.carrname,
a.customid,
c.name
}where c.name like ‘SAP%’ and a.carrid = ‘AA’