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: 

Date Calculation in the CDS View Select

chandravadanj
Explorer
0 Kudos

I am working on CDS view where I need to pass the date value. This date should be current date minus 12 months.

Please see below code, where first commented line works fine in my CDS view. Now I want to pass (Current date - 12 months ) instead of '20180122'.

Please guide how can I achieve that. I am trying to use ADD_MONTHS function but it does not work. Please 2nd line of code.

Thanks!

define view ZPO

//as select from  P_OverduePO(P_StartDate : '20180122' , P_EndDate : $session.system_dat ) as P_OverduePO 

as select from  P_OverduePO(P_StartDate : ADD_MONTHS ($session.system_date, -12), P_EndDate : $session.system_date ) as P_OverduePO
5 REPLIES 5

geert-janklaps
Active Contributor
0 Kudos

Hi,

I think you should use function DATS_ADD_MONTHS instead of ADD_MONTHS. (which needs 3 parameters)

Maybe try using something like:

DATS_ADD_MONTHS ($session.system_date,-12,'UNCHANGED')

Documentation can be found here: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abencds_f1_date_functions.htm#!ABAP_VARIA...

Best regards,

Geert-Jan Klaps

former_member598417
Discoverer
0 Kudos

Hi All,

I have requirement to pass a calculated date to the CDS view. I tried using DATS_ADD_MONTHS function but it still does not work. It gives syntax errors.

I want to pass P_StartDate as (system_date - 12 Months) in the above CDS view.

P_OverduePO1 is also another view and P_StarDate and P_EndDate are mandatory fields.

define view ZPO_ITEMS as select from  P_OverduePO1 (P_StartDate : $session.system_date , P_EndDate : $session.system_date)

Please guide me on how to perform calculation on date in the CDS view.

stephenl1
Participant
0 Kudos

I had a similar problem. See my solution here Link

hsurwase
Discoverer
0 Kudos

DATS_ADD_MONTHS (cast( $session.system_date as abap.dats ), 12,'UNCHANGED')

0 Kudos

this I used which worked in CDS