CDS View entity union all: take the value of a field from table EINA to table EINE

Hello, I am new to CDS, I want to extract data from two tables in a view: EINA and EINE.

For each EINE line we have an EINA line, the reverse is not true.

To do this I use the UNION ALL statement.

My need is very simple, in the EINA table we have the MATNR field, but not in the EINE table, so in my CDS view I would like for each EINE line to take the associated value from EINA.MATNR to my CDS view.

Here is my example code:

 

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘EINA/EINEE Union’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}

define view entity ZC_EinaEineUnion as select from eina
{
key eina.infnr,
‘EINA’ as TableSource,
eina.matnr
}
union all select from eine
{
key eine.infnr,
‘EINE’ as TableSource,
” as matnr
}

 

When executed it gives:

EINA_EINE_UNION.png

My need: in the matnr column, I would like to have for all EINE lines the value ‘000000000007047609’.

Thank you in advance for your help

Scroll to Top