Get Current System Time Stamp in CDS
September 8, 2018

In CDS View get current System Time Stamp using CDS Time Functions

In CDS Environment there is no Session Variable for Time. Session variable for Date is $session.system_date.

There are different ways to Get Current Time Stamp

1. Use Environment Variable Annotation

Define parameter for time and Use Environment Variable Annotation to supply System Time as default value and use system date from session variable to generate time-stamp.

2. Create CDS Functions

3. Use CDS Time Functions to generate current time stamp

This Post deals with the 3rd Scenario

CDS Definition with Current Time Stamp

Current Time Stamp

Data Preview

Data Preview

Sample Code

@AbapCatalog.sqlViewName: 'Z2812TIMSTMP'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Get Current Time Stamp'
define view Z2812_GET_CURRENT_TIMESTAMP
  as select from sbook
{
  carrid,
  connid,
  // Current System Time Stamp
  dats_tims_to_tstmp(
  // Current System Date
    tstmp_to_dats( tstmp_current_utctimestamp(),
                   abap_system_timezone( $session.client,'NULL' ),
                   $session.client,
                   'NULL' ),
  // Current System Time
    tstmp_to_tims( tstmp_current_utctimestamp(),
                   abap_system_timezone( $session.client,'NULL' ),
                   $session.client,
                   'NULL' ),
  // System Time Zone
    abap_system_timezone( $session.client,'NULL' ),
    $session.client,
    'NULL' ) as current_timstmp

}

More Posts from CDS (SAP Core Data Services) Category