Copyright 2024 - BV TallVision IT

A timestamp is in fact a type P(8) number which holds year, month, day, hour, minute and second. There is an actual type TIMESTAMP available and there is a statement to populate your timestamp with "now". But there's more..

The statement to populate your timestamp variabele with the current date and time is

DATA: lv_timestamp type timestamp.
GET TIME STAMP FIELD lv_timestamp.

Feed your timestamp to the WRITE statement and you'll get something like

20.150.619.151.126

Easy formatting can be done with

write: / lv_timestamp using EDIT MASK '____/__/__ __:__:__'.

2015/06/19 15:11:26

If you need some calculating on timestamp data, there is a class CL_ABAP_TSTMP that may be useful. Here's an example that gets the current timestamp and subtracts a number of hours (5) from it:

 DATA: 
  lv_timestamp type timestamp, 
  lv_seconds TYPE p.

  GET TIME STAMP FIELD lv_timestamp.
  write: / lv_timestamp.
  lv_seconds = 5 * 60 * 60.
  lv_timestamp = cl_abap_tstmp=>SUBTRACTSECS( exporting
    TSTMP = lv_timestamp
    SECS = lv_seconds ).
  write: / lv_timestamp.