Application Development 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: 

CDS View - Coalesce and case statement not working

0 Kudos
5,176

Hi Experts,

I have developed a CDS view and one of the column in it is of Bill of Lading(BOLNR).


My requirement is to put '#' if BOLNR is initial. I tried with Coalesce and Case Statement with below code but it is not working as expected.

Code1 - coalesce( _likp.bolnr, '#' ) as bolnr,

Code2- cast ( case when _likp.bolnr = ' ' then '#' else _likp.bolnr end as bolnr) as bolnr.

Is there any other away to achieve the above requirement in CDS View?

6 REPLIES 6

BiberM
Active Participant
2,125

Coalesce only works if the value is null, which is currently only possible within a Join.

The Case should work through. I'm currently only at the Phone but is there something like "initial" or is that value not an empty string? In CDS there is much less automatik data type conversion which is also valid for constants.

MateuszAdamus
Active Contributor
0 Kudos
2,125

Hello,

What is the error message you get?

Or is it just not producing the expected results?

Kind regards,

Mateusz

maheshpalavalli
Active Contributor
2,125

This works right?

cast ( case when likp.bolnr = ' ' then '#' else likp.bolnr end as bolnr ) as test1

or if it is an older version, this also works, you don't need cast.

case when likp.bolnr = '' then '#' else likp.bolnr end as test

and tell us what is not working as well.

0 Kudos
2,125

Hi Mahesh,

By using Case or Coalesce, it is working for some records, but not for all records. Please see below screen shots:

0 Kudos
2,125

Hi All,

the issues with Coalesce and Case is, for some records which are blank, it is working as expected. But some it is showing blank.

Is it because BOLNR is CHAR35 and having Numeric as well as Alphabetical records?

0 Kudos
2,125

Hi All,

For Some records if you use either a case or coalesce it is working but for some records its not working.blank-bolnr.pngnon-blank-bolnr.png

Please refer Attachments for more clarification on the issue.