Skip to Content
avatar image
Former Member

Current date in ABAP CDS views

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

current_date.PNG (39.5 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Aug 12, 2016 at 06:03 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 11, 2016 at 02:36 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 26, 2016 at 08:06 AM

    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)

    Add comment
    10|10000 characters needed characters exceeded