cancel
Showing results for 
Search instead for 
Did you mean: 

Conditional Statement to determine the CDS to be executed

sauravsinha12
Explorer
0 Kudos

Hi,

We have a Fiori tile based on an underlying custom CDS view say 'A'.

Now this CDS view 'A' is built on another custom CDS view 'B' which is again built on left outer join of 2 other custom CDS views namely 'B1' & 'B2'. Now my requirement is that I need to build a new custom CDS view 'B3' with certain logic parallel to the CDS Views 'B1' & 'B2'. Based on the selection of a Comp Code by the user in the Fiori App Selection screen, either the newly created CDS View B3 should be executed or else the existing CDS views B1 & B2 should be executed. How can we achieve this without breaking the existing CDS views functionalities.

Any help would be highly appreciated as I am very new to CDS views developments.

Thanks.

ThorstenHoefer
Active Contributor
0 Kudos

Hi,

have both CDS views the same columns? In this case, try to select union like

select 'VIEW_A' as CDS_VIEW
      , a~*
from a
union // or union all
select 'VIEW_B' as CDS_VIEW
      , b~*
from b
From outside, you can perform as select likeselect * from c where cds_view = 'VIEW_A'

Accepted Solutions (0)

Answers (3)

Answers (3)

sauravsinha12
Explorer
0 Kudos

@Thorsten Thanks a lot for the detailed explanation. Trust me we also came with this solution but still need to check. Just wanted to know that do we have conditional statements like if-else in CDS views.

ThorstenHoefer
Active Contributor
0 Kudos

Hi Saurav,

CDS View B and B3 has the same structure, like View A.

Create a new CDS View B4.

This is an union over B and B3. The View B4 sould be placed between A and B.

create view b4 as ( 
select  *
from b
where company_code != 'XY00'
union // or union all
select *
from b3
where company_code = 'XY00'
)
sauravsinha12
Explorer
0 Kudos

@Thorsten - Thanks for replying. I didn't quite got your suggestion above. The below picture depicts my scenario exactly. If your above suggestion holds true for the below scenario, please explain in a bit detail.