cancel
Showing results for 
Search instead for 
Did you mean: 

Passing values to input parameters using associations in CDS Views

Former Member
0 Kudos

Hi All,

Im trying to pass values to input parameters while doing an association between two CDS views. My scenario is as follows:

I have time-dependent HANA view H1 that has keyDate as input parameter. Created a CDS table function CDS1 on H1 and was able to pass inputs to the keyDate. While Im doing an association with another CDS view CDS2, I would want to pass a date from CDS2 to keyDate. I was able to pass current date using the following syntax,

associationDetails(keyDate : $session.system_date).column1, but getting an error while trying to pass a value from CDS2.

Is this scenario possible?

Accepted Solutions (1)

Accepted Solutions (1)

horst_keller
Product and Topic Expert
Product and Topic Expert

Answers (1)

Answers (1)

AbhijeetK
Active Participant
0 Kudos

There is way to do so below is example :

Parameters can’t be directly used within the definition on Associated targets. But you can expose fields in the associated target CDS view as shown in below example.

CDS with Parameter (to be used as association target)

@AbapCatalog.sqlViewName:'ZYX_SQL'

@AbapCatalog.compiler.compareFilter:true

@AbapCatalog.preserveKey:true

@AccessControl.authorizationCheck:#CHECK

@EndUserText.label:'Sales Order Item with Parameters'

defineview ZC_ZYX

withparameters p_matkl : matkl

as

selectfrom vbap {

key vbeln,

key posnr,

matnr,

matkl,

zmeng,

meins

}

where matkl =:p_matkl

Then Final CDS view where we want to use association --

@AbapCatalog.sqlViewName:'ZZZYX'

@AbapCatalog.compiler.compareFilter:true

@AbapCatalog.preserveKey:true

@AccessControl.authorizationCheck:#CHECK

@OData.publish:true

@EndUserText.label:'Sales Order Header with Associations & Parameters'

defineview ZC_ZZYX

withparameters

p_matkl1 : matkl,

p_vbeln1 : vbeln

as

selectfrom vbak

association[0..*]to ZC_ZYXas _item

on$projection.vbeln = _item.vbeln

{

key vbeln,

key _item(p_matkl::p_matkl1).posnr,

_item(p_matkl::p_matkl1).matkl,

_item(p_matkl::p_matkl1).matnr,

_item(p_matkl::p_matkl1).zmeng,

_item(p_matkl::p_matkl1).meins

}

where vbeln =:p_vbeln1

This will work similar to Right outer join. Alternatively, You can use CDS “ZC_ZYX” view as primary data source in Final CDS.

Regards,

Abhijeet Kankani