Application Development and Automation 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: 
Read only

Current date in ABAP CDS views

anita_dixit
Product and Topic Expert
Product and Topic Expert
0 Likes
41,968

Hi,

I am trying to get current system date into a variable (in the form of parameter) as shown below :

What I need is  : If the end date is less than today's date, it's fine(continue with the end date)  else replace it with today's date (that's get it from the system's date) . But I am getting error such that it is not supported.

Can anyone suggest a workaround solution at the earliest ?

Thanks & Kind Regards,

Anita

1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
13,604

Hi Anita,

Unfortunately, result1, result2, ... of a CASE expression cannot be parameters (up to now).

But, hey, they can be CAST expressions. Therefore, a cheap trick that gives no error in 7.50:

@AbapCatalog.sqlViewName: 'KELLERH_V_TEST'

define view kellerh_cds_test

  with parameters

    @Environment.systemField: #SYSTEM_DATE

    p_start_date : abap.dats

  as select from demo_expressions

{

  dats1,

  dats2,

  case when dats2 < $parameters.p_start_date

    then dats2

    else cast( $parameters.p_start_date as abap.dats )

  end as res

}

Cheers

Horst

10 REPLIES 10
Read only

michaelwurst
Associate
Associate
0 Likes
13,604

Hi Anita,

I think one (dirty) workaround in your scenario could be to define a second CDS view with identical interface as wrapper and use the parameter as colum output. Maybe you can try something like this (untested):

1. Adjust your CDS view by adding a column with system date, e.g.:

define view ZEMP_YEARS_1

with parameters

@Environment.systemField: #SYSTEM_DATE

@EndUserText.label: 'Test'

p_start_date : abap.dats

as select from ZAD_EMPSTAFFING{

  -- your column fields... 

  $parameters.p_start_date as sydatum    

}

2. Create new CDS view, e.g.:

define view ZEMP_YEARS_1_WRAP

with parameters

@Environment.systemField: #SYSTEM_DATE

@EndUserText.label: 'Test'

p_start_date : abap.dats

as select from ZEMP_YEARS_1( p_start_date: $parameters.p_start_date ){

  -- your column fields... 

  case

    when ZEMP_YEARS_1.EndDate < ZEMP_YEARS_1.sydatum then ZEMP_YEARS_1.EndDate

    else ZEMP_YEARS_1.sydatum end as EndDateU     

}

I hope this helps and all the best,

Michael

Read only

anita_dixit
Product and Topic Expert
Product and Topic Expert
0 Likes
13,604

Thanks. I did it long time back.

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
13,605

Hi Anita,

Unfortunately, result1, result2, ... of a CASE expression cannot be parameters (up to now).

But, hey, they can be CAST expressions. Therefore, a cheap trick that gives no error in 7.50:

@AbapCatalog.sqlViewName: 'KELLERH_V_TEST'

define view kellerh_cds_test

  with parameters

    @Environment.systemField: #SYSTEM_DATE

    p_start_date : abap.dats

  as select from demo_expressions

{

  dats1,

  dats2,

  case when dats2 < $parameters.p_start_date

    then dats2

    else cast( $parameters.p_start_date as abap.dats )

  end as res

}

Cheers

Horst

Read only

anita_dixit
Product and Topic Expert
Product and Topic Expert
0 Likes
13,604

Thanks a lot . It worked.

Read only

Former Member
13,604

Hello,

Is there any way to do arithmatic on date and time fields?

would you pls let me know syntax.

normal CDS view or Query type CDS view (@Analytics.query: true)

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
13,604

Since 7.50 there are built-in functions for this.

Read only

anita_dixit
Product and Topic Expert
Product and Topic Expert
0 Likes
13,604

Hi Saif,

I am using normal CDS view (dataCategory: #CUBE).

Read only

former_member597044
Participant
0 Likes
13,604

Hi Experts,
Without using Parameters , do we get the system field in Plain CDS View.

Thanks
Sumanth

Read only

13,604

Hi Sumanth,

Maybe, it can help.

"tstmp_to_tims(TSTMP_CURRENT_UTCTIMESTAMP(), abap_system_timezone( $session.client,'NULL' ), $session.client, 'NULL') as SYSTIME ,"

Kind Regards,

Carlos

Read only

dob1
Participant
13,604

I know this question is old, but I just had the same "challenge".

It depends on the release you are working on.

Release 7.51 and higher provides a session-variable that gives us directly the current date.

$session.system_date

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abencds_f1_session_variable.htm