Skip to Content
0

ABAP CDS View Cast in Case Expression

Dec 15, 2016 at 02:01 PM

1.9k

avatar image

Hello,

I want to make a new field in my CDS-View, with a CASE-condition, like that:

case 
        when usage_6m  = 0 then '1'
        when usage_6m < '10' or usage_6m > '0' then '2'
        when usage_6m < '250' or usage_6m > '10' then '3'
        else '0'
        end as usage_icon

The problem is that the type of the field "usage_6m" NUMC10 is, so eclipse throws an error : "data type conflict". So then I wanted to cast the field to abap.int4, but that does not work eighter, because the CAST--expression is not supported in this position like this:

case 
        when cast( usage_6m  as abap.int4 )  = 0 then '1'

...

Do any of you have an idea how I cand solve this, or why I can't cast a field inside of a CASE-expression.

Thank you!

Cristina

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Raymond Giuseppi
Dec 16, 2016 at 09:00 AM
1

Could you consider NUMC10 as a string giving a simpler

CASE
  WHEN usage_6m = '0000000000' then '1'
  WHEN usage_6m < '0000000010' then '2'
  WHEN usage_6m < '0000000250' then '3'
  ELSE '0'
END AS usage_icon

Regards,
Raymond

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Whoa, that was an easy workaround! Thank you!

0
Horst Keller
Dec 16, 2016 at 09:23 AM
1

Hi Cristina,

Sorry, but the searched CASE does not support expressions as LHS, see docu.

You have to find a workaround e.g. as Raymond suggested.

Share
10 |10000 characters needed characters left characters exceeded