Skip to Content
avatar image
Former Member

ABAP CDS View Cast in Case Expression

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Dec 16, 2016 at 09:00 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 16, 2016 at 09:23 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded