SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation →
ABAP − Reference →
Processing Internal Data →
Date and Time Processing →
Time Stamp →
CONVERT TIME STAMP 
Short Reference
Syntax
CONVERT TIME STAMP time_stamp TIME ZONE tz
INTO [DATE dat]
[TIME tim] [DAYLIGHT SAVING TIME dst].
Effect
This statement interprets the content of time_stamp as a
time stamp, converts it to the local data and the
local time in the time zone specified in tz, and assigns the result to the variables dat, tim, and dst.
time_stamp and tz are functional operand positions.
-
The operand time_stamp must have the type TIMESTAMP
or TIMESTAMPL from ABAP Dictionary, in accordance with the ABAP type
p with length 8 or p with length 11 with seven decimal places. Depending on the data type, the content is interpreted either as a time stamp in the
short form or as a time stamp in the
long form. No other data types can be specified.
If time_stamp does not contain a valid time stamp, the content of dat
and tim is not changed, and sy-subrc is set to 12.
-
The operand tz must be character-like and contain a
time zone from the database table TTZZ.
- If tz is initial, the time zone is set implicitly to "UTC", dat
and tim are given the appropriate values, and sy-subrc is set to 8.
- If the specified time zone is not found in the database table TTZZ, the content of dat
and tim is not changed and sy-subrc is set to 8.
- If the rule set for the specified time zone is incomplete, an exception that cannot be handled is raised.
-
The local date in the format of the data type d is assigned to dat and a variable must be specified to which the return value can be converted.
-
The local time in the format of the data type t is assigned to tim
and a variable must be specified to which the return value can be converted. If the time stamp in time_stamp is in the
long form, the seconds fractions in the decimal places are ignored.
-
If the time stamp in time_stamp for the time zone specified in tz
is in summer time, then dst is given the value "X". Otherwise it is given the value " ".
The following applies to the return values dat, tim, and dst:
-
The return value for dat has the data type d. The following can be specified for dat:
- An existing variable to which the return value can be converted.
- An inline declaration DATA(var), where a variable of data type d is declared.
-
The return value for tim has the data type t. The following can be specified for tim:
- An existing variable to which the return value can be converted.
- An inline declaration DATA(var), where a variable of data type t is declared.
-
The return value for dst has the data type c with the length 1. The following can be specified for dst:
- An existing variable of the type c with length 1
- An inline declaration DATA(var), where a variable of data type c with length 1 is declared.
When time stamps are converted to reflect the conversion from the Julian calendar to the Gregorian calendar
and the non-existence of the days between 19/5/1582 and 10/14/1582, this returns the same results as the conversion for the days from 10/15/1582 to 10/24/1582 (which do exist).
System Fields
sy-subrc |
Meaning |
0 |
Time stamp was converted into the local time of the specified time zone and assigned to the target fields. |
4 |
Time stamp was assigned to the target fields without conversion into the local time. |
8 |
Time stamp could not be converted, because the specified time zone is not in the database table TTZZ. |
12 |
Time stamp could not be converted since time_stamp contains an invalid value. |
Notes
-
A current UTC time stamp can be created using the GET TIME STAMP statement.
-
The current user time zone can be found in the system field sy-zonlo.
-
It is now possible to use the return value for the summer time in dst to
differentiate between duplicate local time specifications that occur when UTC time stamps are converted into local time during the double hour in the changeover between summer and winter time.
Example
For the time zone "BRAZIL" in database table TTZZ, a shift of -3 hours
from the UTC reference time is entered in database table TTZR. The end
of the summer time is defined in database table TTZDV as the second Sunday
in March at 02:00, which in the year 2003 is March 9. With these settings in the rules, the two conversions
below both result in the same local time of "01:30:00". The first conversion shows that the time is still in the summer time.
DATA: time_stamp TYPE timestamp,
tz TYPE ttzz-tzone.
tz = 'BRAZIL'.
time_stamp = 20030309033000.
CONVERT TIME STAMP time_stamp TIME ZONE tz
INTO DATE DATA(dat) TIME DATA(tim)
DAYLIGHT SAVING TIME DATA(dst).
cl_demo_output=>write( |{ dat DATE = ISO } {
tim TIME = ISO } { dst }| ).
time_stamp = 20030309043000.
CONVERT TIME STAMP time_stamp TIME ZONE tz
INTO DATE dat TIME tim
DAYLIGHT SAVING TIME dst.
cl_demo_output=>write( |{ dat DATE = ISO } {
tim TIME = ISO } { dst }| ).
cl_demo_output=>display( ).
Exceptions
Non-Catchable Exceptions
-
Cause: Inconsistent control tables for the conversion.
Runtime Error: CONVERT_TSTMP_INCONSISTENT_TAB