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

CDS view Case statement/ Nested condition

Former Member
42,684

Scenario:

IF Purch. doc. Category (EKPO-bstyp) = ‘F’ then Display Purchasing Document (EBLEN)for each unique Material + Vendor (EKKO Table) Combination

IF Purch. doc. Category (EKPO-bstyp) != ‘F’ (or it doesn’t exists) then Display Purchasing Document (EBLEN)where Purch. doc. Category (bstyp) = ‘K’

What We have tried :

1.casewhen ekpo.bstyp ='F'then ekpo.ebeln

when(ekpo.bstyp <>'F'and ekpo.bstyp ='K')then ekpo.ebeln endas PO,

5 REPLIES 5
Read only

monalisa_biswal
Contributor
0 Likes
15,552

Your logic seems to be ok only the condition ekpo.bstyp <>'F' is redundant. Are you facing any issues with these statements?

Read only

Former Member
0 Likes
15,552

Why don't you use the direct check in case statement instead of using not equal to F in second condition.When your condition satisfies then if will fill data.If both the conditions doesn't satisfies then use others statements to set default values.

case ekpo.ebeln.

when ekpo.bstyp ='F'then ekpo.ebeln

when ekpo.bstyp ='K' then ekpo.ebeln endas PO,

when others

endcase.

Read only

ShyamPindiproli
Active Participant
0 Likes
15,552
Refer demo CDS view - DEMO_CDS_SEARCHED_CASE 

cast( case when ekpo.bstyp= 'F'                         // Purchase Order   
              then  ekpo.ebeln
            when ekpo.ebeln = 'K'                        // Contract    
               then  ekpo.ebeln   
            when others 
      end  as ebeln )        as  DocumentNumber

Regards,
Shyam
Read only

Former Member
0 Likes
15,552

Hello Shyam,

Thank you so much for the response. Our requirement if Flag=’F’ condition is met for any material + Vendor combination then we need to ignore all the EBELN records where Flag = ‘K’.

As of now with the use of your suggested CAST(CASE STATEMENT), we are able to mask the records where Flag=K with ‘#’, but question is can we remove this record line (#) as well from the result set.

Attached is the Screenshot for the same (CAST_CASE_STATEMENT).

Read only

0 Likes
15,552

In case you want to remove then your where clause condition has to do the same. Please share your complete CDS code