Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Date and Time Processing →  Character-Like Date Fields and Time Fields →  Accessing Character-Like Date Fields and Time Fields 

Character-Like Access to Character-Like Date Fields and Time Fields

Character-like access to character-like content of character-like date fields and time fields is evaluated in a character-like manner. The character-like nature of character-like date fields and time fields can be exploited, for example, to access detailed information. To avoid unexpected results from this type of access, you must verify that the content of the date or time fields is valid. Most statements and functions used in string processing are not suitable for editing character-like date fields and time fields because they generally produce invalid content.

Other versions: 7.31 | 7.40 | 7.54


Example

The following example demonstrates how substring functions can be used to extract the components year, month, day, hour, minute, and second from character-like date fields and time fields.

DATA: date TYPE d,
      time TYPE t.

DATA: year   TYPE i,
      month  TYPE i,
      day    TYPE i,
      hour   TYPE i,
      minute TYPE i,
      second TYPE i.

date = sy-datlo.
time = sy-timlo.

year   = substring( val = date off = 0 len = 4 ).
month  = substring( val = date off = 4 len = 2 ).
day    = substring( val = date off = 6 len = 2 ).
hour   = substring( val = time off = 0 len = 2 ).
minute = substring( val = time off = 2 len = 2 ).
second = substring( val = time off = 4 len = 2 ).