codemania23
codemania23

Reputation: 1071

Optional parameters in ABAP CDS views?

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

Answers (3)

Suncatcher
Suncatcher

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:

  1. #CLIENT: sy-mandt
  2. #SYSTEM_DATE: sy-datum
  3. #SYSTEM_TIME: sy-uzeit
  4. #SYSTEM_LANGUAGE: sy-langu
  5. #USER: sy-uname

Sample 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

Eralper
Eralper

Reputation: 6612

Did you check the Consumption.defaultValue annotation Please have a look at reference document

Upvotes: 3

user6593371
user6593371

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

Related Questions