Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Optional Parameters in CDS view OR Default value

Former Member
0 Likes
4,278

Hi

I need to make a CDS view for consumption via Analysis for Office

However there are certain parameters which user will enter as mandatory(easily solved by parameters) but certain are optional (parameters )

How to solve this optional parameters in CDS, because while comparing in where condition it can be that for some parameters users might not enter anything and we have to get all the data corresponding to that value.

HOW TO USE OPTIONAL PARAMETERS IN CDS, OR A WORKAROUND if optional parameters aren't possible

Please suggest

Hi

I need to make a CDS view for consumption via Analysis for Office

However there are certain parameters which user will enter as mandatory(easily solved by parameters) but certain are optional (parameters )

How to solve this optional parameters in CDS, because while comparing in where condition it can be that for some parameters users might not enter anything and we have to get all the data corresponding to that value.

HOW TO USE OPTIONAL PARAMETERS IN CDS, OR A WORKAROUND if optional parameters aren't possible

Please suggest

5 REPLIES 5
Read only

Former Member
0 Likes
2,162

Hi Indresh,

I see two potential solutions:

1. Create multiple CDS views(with different number of parameters & different code) and call/consume them individually from ABAP based on parameters entered by user. Case or if/else construct can be used in ABAP to check parameter availability & consume right CDS

2. Create one CDS and use UNION to add result of different queries. e.g.

DEFINE VIEW XYZ as

select from Table1

{

...

}

WHERE field_a = mandatory_param1

UNION

select from Table1

{

...

}

WHERE field_a = mandatory_param1

AND field_b = optional_param2

UNION

select from Table1

{

...

}

WHERE field_a = mandatory_param1

AND field_c = optional_param3

Thanks,

Sumit

Read only

0 Likes
2,162

Hi Sumit,

But I am not able to find right annotataions for making a parameter optional.
I have period (MONAT) as optional parameter. how to make that

Read only

0 Likes
2,162

There is no annotation which makes CDS parameter optional(as of now). You need to think other way.

Read only

0 Likes
2,162

how to make parameter optional in cds views?

Read only

0 Likes
2,162

I have added consumption.filter.mandatory to parameter but it is not working

@AbapCatalog.compiler.compareFilter: true

@AbapCatalog.preserveKey: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'CDS Program1'

define view ZCD_training

with parameters doc_no : char10

as select from ekko

{

@Consumption.filter.mandatory:false

@Consumption.filter.selectionType: #SINGLE

key ebeln,

bukrs,

ernam

} where ebeln = $parameters.doc_no;


Can anyone tell how to make doc_no as optional parameter?