‎2016 Dec 15 2:01 PM
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_iconThe 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
‎2016 Dec 16 9:00 AM
‎2016 Dec 16 9:00 AM
‎2016 Dec 19 1:45 PM
‎2016 Dec 16 9: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.
‎2019 Jul 30 4:28 PM
Hello Sir,
i have also got same requirement, how did you achieve.please let me know, its great thankful to you if you would give early response.
Thanks
Ravilla
‎2019 Sep 12 10:23 AM
Hi Cristina,
Take your usage_6m as string and then try . Hope it works.
Regards
Ram
‎2020 May 25 12:52 PM
Requirement Show Company Code from Table 1(o) if exist else if show Company code from table2(P) if exist elseif show it from Table 3(Q).
Data Type of Company code is different from table 1(o) or Table2 (p) Let us say CHAR 04 and table3 (Q) company code CHAR 20
For Table 1 and 2 we can write the below code
Case
when Q.lsa_bukrs is null then p.company_code
else Q.lsa_bukrs end as Company_code2,
For 3 table I wrote below code but it does not work because the Datatype of Company code is different in Table 3(Q)
Case
when t.org_unit_key is not null and Q.lsa_bukrs is null and p.company_code is null
then t.org_unit_key
when Q.lsa_bukrs is not null then Q.lsa_bukrs
when Q.lsa_bukrs is null and p.company_code is not null then p.company_code
end as Company_code2,
Then I went and Opted for another Approach Making one more CDS view Comparing two table and In Main cds View comparing the 3rd table and result of first View
Additional view
{ key a.lsa_id as lsa_id,
cast( Q.lsa_bukrs as abap.char(20))as Q_lsa_bukrs,
cast( p.company_code as abap.char(20))as p_company_code,
cast(case
when Q.lsa_bukrs isnull// Purchase Order
then p.company_code
else Q.lsa_bukrs
endas abap.char(20))as QP_Company_code,
cast( t.org_unit_key as abap.char(20))as t_Company_code,
Q.gsber_sc as Lsa_Business_area
}
View Main: In this View Compare the company code which u received from first View and Table 3 (Q) Company Code
{key U.QP_Company_code,
U.t_Company_code,
casewhen U.QP_Company_code isnull
then U.t_Company_code
else U.QP_Company_code
endas Company_code,
}