Reputation: 1071
I'm trying to create a CDS view for consumption with optional parameters. But at the moment, optional parameters are not supported.
Is there a workaround available to somehow choose which where clauses are to be executed/used based on input parameters ?
Upvotes: 4
Views: 9516
Reputation: 10621
I just put more complete answer than proposed by Dzhengo.
You can use parameter annotations for some of the parameters which can be filled implicitly by ABAP environmental values. Annotations can be specified by keyword @Environment.systemField
before or after the parameter and should be followeed by env field after the colon. Here is the list of possible environmental fields:
#CLIENT:
sy-mandt #SYSTEM_DATE:
sy-datum #SYSTEM_TIME:
sy-uzeit #SYSTEM_LANGUAGE:
sy-langu #USER:
sy-unameSample code for defining the view:
@AbapCatalog.sqlViewName: 'ZVW_MARA'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view zvw_mara
with parameters
p_matnr : matnr,
@Environment.systemField : #SYSTEM_DATE
p_datum : syst_datum,
p_uname : syst_uname @<Environment.systemField : #USER
as select from
mara
{
key mara.matnr,
mara.ernam,
mara.ersda
}
where
matnr = :p_matnr
and ernam = :p_uname
and ersda = :p_datum;
Upvotes: 3
Reputation: 6612
Did you check the Consumption.defaultValue annotation Please have a look at reference document
Upvotes: 3
Reputation:
At the moment the following are the only parameters you can use as optional.
p_date : sydatum
@<Environment.systemField:#SYSTEM_DATE
, p_language : spras
@<Environment.systemField:#SYSTEM_LANGUAGE
Upvotes: 2