Skip to Content
avatar image
Former Member

CDS - Date calculation

Hi,

I'm trying to do som calculation with date type fields.

@AbapCatalog.sqlViewName: 'ZDEMOSDN'

@EndUserText.label: 'test'

define view ZDEMOSDN as select from aufk as a inner join afko as b

    on a.aufnr = b.aufnr

{

    key a.aufnr,

    a.erdat - a.idat2 as date2   

}

I'm getting the error messages:

Data type DATS is currently not supported in an arithmetic expression

Will this be supported in near future? Is there kind of workaround 😊.

Regards,

Bart



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jul 22, 2015 at 07:53 AM

    There are functions like

    dats_is_valid

    dats_days_between

    dats_add_days

    dats_add_months

    If they are not available yet in your current SP-release then there is no workaround as date-time calculations are very complex (just think of leap years or things like that)

    Add comment
    10|10000 characters needed characters exceeded

    • Usage of a parameter could serve as workaround:

      define view ...

        with parameters

          sydat : abap.dats @<Environment.systemField: #SYSTEM_DATE

        as select from svers

      {

        dats_days_between( $parameters.sydat, $parameters.sydat ) as delta

      }

      or a join with another view (wrapping $session.system_date as column)

      define view ...

        as select from svers

      {

        $session.system_date as system_date

      }