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: 

Convert/Calculate Date to Fiscal year in CDS View

sunil_hirgude2
Explorer

Hi,

I am trying to convert date to fiscal year in CDS view but not working.

Is there any way to achieve this?

Kindly help.

Thanks & Regards,

Yogesh

4 REPLIES 4

sunil_hirgude2
Explorer
0 Kudos

Hi Floarian,

I am working on ABAP CDS View.

I have to convert date to fiscal year(April to March).

e.g. 20180201 to 2017, 20180301 to 2017, 20180401 to 2018, 20180501 to 2018...like that

I tried this -

case

when a.vmonth = '01' then (a.calyear - 1)

when a.vmonth = '02' then (a.calyear - 1)

when a.vmonth = '03' then (a.calyear - 1)

when a.vmonth = '04' then a.calyear

when a.vmonth = '05' then a.calyear

when a.vmonth = '06' then a.calyear

when a.vmonth = '07' then a.calyear

when a.vmonth = '08' then a.calyear

when a.vmonth = '09' then a.calyear

when a.vmonth = '10' then a.calyear

when a.vmonth = '11' then a.calyear

when a.vmonth = '12' then a.calyear

end as vfiscalyear,

but (a.calyear - 1) this is not working...Error: Data type NUMC is currently not supported in an arithmetic expression


Kindly help with this or please provide any other way to achieve the requirement.


Thanks & Regards,

Yogesh

pfefferf
Active Contributor
0 Kudos

According to the message "...Error: Data type NUMC is currently not supported in an arithmetic expression" it should be clear what the error is and how it can be solved?

One option is to case the NUMC value to an integer. E.g.

...
case when a.vmonth = '01' then ( cast( a.calyear as abap.int2 ) - 1) ...

Details can be found here

Regards,
Florian

eswaramaharaja_n
Discoverer

Please use standard SAP provided CDS view like I_FiscalYearPeriod, which could be used to convert the date to fiscal year and period.

Regards,

Eswara.

0 Kudos

Best choice eswaramaharaja_n !

This one my integration if someone else need it :

association [0..1] to I_FiscalYearPeriod as _FiscalYearPeriod on

$projection.budat >= _FiscalYearPeriod.FiscalPeriodStartDate // Sebastiano Marchesini 28/10/2022 TKT 5000033224

and $projection.budat <= _FiscalYearPeriod.FiscalPeriodEndDate

and _FiscalYearPeriod.IsSpecialPeriod <> 'X'