ABAP - Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Data Definitions →  ABAP CDS - DDL Statements →  ABAP CDS - DEFINE VIEW →  ABAP CDS - SELECT →  ABAP CDS - SELECT, Predefined Functions →  ABAP CDS - Special Functions →  ABAP CDS - Date Functions and Time Functions → 

ABAP CDS - Time Stamp Functions

Syntax

... TSTMP_IS_VALID(tstmp)
  | TSTMP_CURRENT_UTCTIMESTAMP()
  | TSTMP_SECONDS_BETWEEN(tstmp1,tstmp2,on_error)
  | TSTMP_ADD_SECONDS(tstmp,seconds,on_error) ...


Variants:

1. ... TSTMP_IS_VALID(tstmp)

2. ... TSTMP_CURRENT_UTCTIMESTAMP()

3. ... TSTMP_SECONDS_BETWEEN(tstmp1,tstmp2,on_error)

4. ... TSTMP_ADD_SECONDS(tstmp,seconds,on_error)

Effect

These functions perform operations with arguments of the predefined data type DEC with length 15 or of the data element TIMESTAMP. The content of an argument of this type is interpreted as an ABAP-specific time stamp.

With the exception of TSTMP_CURRENT_UTCTIMESTAMP, these functions have positional parameters to which actual parameters must be assigned when called. There are currently no optional parameters. Suitable fields of a data source, literals, parameters, path expressions, predefined functions, or expressions can all be specified as actual parameters. Only literals can be passed to the parameter on_error. If an actual parameter contains the null value, every function except TSTMP_IS_VALID returns a null value.

Notes

Variant 1

... TSTMP_IS_VALID(tstmp)


Effect

The function TSTMP_IS_VALID determines whether tstmp (if specified) contains a valid time stamp in the format YYYYMMDDHHMMSS. The actual parameter must have the predefined data type DEC with length 15 and no decimal places. The result has the data type INT4. A valid time stamp produces the value 1 and all other input values (including the null value) produce the value 0.

Variant 2

... TSTMP_CURRENT_UTCTIMESTAMP()


Effect

The function TSTMP_CURRENT_UTCTIMESTAMP returns a UTC time stamp in accordance with the POSIX standard. The result has the data type DEC with length 15 and no decimal places.

Hinweise

Example

The date and time of the current UTC time stamp is extracted using the SQL function substring in the following CDS view. This requires a conversion to a character-like type using CAST.

@AbapCatalog.sqlViewName: 'demo_cds_datim'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_date_time
  as select from demo_expressions {  
    substring( cast( tstmp_current_utctimestamp()
      as abap.char(17) ), 1, 8 ) as dat,
    substring( cast( tstmp_current_utctimestamp()
      as abap.char(17) ), 9, 6 ) as tim }


Variant 3

... TSTMP_SECONDS_BETWEEN(tstmp1,tstmp2,on_error)


Effect

The function TSTMP_SECONDS_BETWEEN calculates the difference between two specified time stamps, tstmp1 and tstmp2 in seconds. The actual parameter must have the predefined data type DEC with length 15 and no decimal places and contain valid time stamps in the format YYYYMMDDHHMMSS. Any invalid time stamps produce an error. If tstmp2 is greater than tstmp1, the result is positive. In the reverse case, it is negative.

The actual parameter on_error controls error handling. It must have the predefined data type CHAR with the length 10 and must have one of the following values:

The format is not case-sensitive. Any incorrectly specified values raise an exception.

Variant 4

... TSTMP_ADD_SECONDS(tstmp,seconds,on_error)


Effect

The function TSTMP_ADD_SECONDS adds seconds seconds to a time stamp tstmp. The actual parameter tstmp must have the predefined data type DEC with length 15 and no decimal places and contain a valid time stamp in the format YYYYMMDDHHMMSS. An invalid time stamp produces an error. The actual parameter seconds must also have the predefined data type DEC with length 15 and no decimal places. Any negative values are subtracted. If the result is invalid, an error occurs.

The actual parameter on_error controls error handling. The same applies as to the function TSTMP_SECONDS_BETWEEN. The additional value "UNCHANGED" can be used to specify that an error caused the unchanged value of tstmp to be returned.

Example

The following CDS view applies time stamp functions in the SELECT list to columns of the database table DEMO_EXPRESSIONS. The program DEMO_CDS_TIMESTAMP_FUNCTIONS uses SELECT to access the view. The column NUM1 of the database table is given a value that is added to a time stamp in the column TIMESTAMP1 as seconds. The difference is found between this sum and a time stamp retrieved on the database by the function TSTMP_CURRENT_UTCTIMESTAMP. A delay, wait, can be integrated between the time stamp in the ABAP program and the time stamp created on the database.

@AbapCatalog.sqlViewName: 'demo_cds_tsfnc'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view demo_cds_timestamp_functions
  as select from demo_expressions {
    id,
    timestamp1 as timestamp1,
    tstmp_is_valid(timestamp1) as valid1,  
    tstmp_seconds_between(
      tstmp_current_utctimestamp(),        
      tstmp_add_seconds(
        timestamp1,
        cast( num1 as abap.dec(15,0) ),
        'FAIL'),
     'FAIL') as difference }