Skip to content

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

ABAP CDS - Time Stamp Functions

Other versions: 7.31 | 7.40 | 7.54

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

In a CDS view, these functions perform operations with arguments of the built-in data type DEC with length 15 or of the data element TIMESTAMP. The content of an argument like this is interpreted as an ABAP-specific time stamp in a packed number.

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, built-in 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

  • The time stamp functions enable time stamps to be edited on the database that are saved as a packed number in the ABAP-specific format in database tables. As in ABAP, other types of access to these fields interpret these time stamps as regular numeric values.

  • Conversion functions make it possible to transform a time stamp to date fields and time fields and to transform date fields and time fields to a time stamp.

Variant 1

... TSTMP_IS_VALID(tstmp)

Effect

The function TSTMP_IS_VALID determines whether an argument tstmp contains a valid time stamp in the format YYYYMMDDHHMMSS. The actual parameter must have the built-in 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.


Notes

  • If the function TSTMP_CURRENT_UTCTIMESTAMP is used more thane once within a view, it cannot be guaranteed that the every call within a database access produces the same result. Hence, later calls can produce later time stamps.

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 built-in 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 built-in data type CHAR with the length 10 and must have one of the following values:

  • "FAIL" (an error raises an exception)
  • "NULL" (an error returns the null value)
  • "INITIAL" (an error returns the initial value)

The values are 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 built-in 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 built-in 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
}