Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  string_exp - String Expressions →  string_exp - String Templates →  Examples of string templates 

String Templates, Time Zones

The example demonstrates the formatting of a time stamp using time zones.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    TYPES: BEGIN OF timezone,
             tzone    TYPE ttzz-tzone,
             descript TYPE ttzzt-descript,
             datetime TYPE string,
           END OF timezone.

    DATA: timezones TYPE TABLE OF timezone,
          tstamp    TYPE timestamp,
          result    TYPE string.

    FIELD-SYMBOLS <timezone> TYPE timezone.

    SELECT ttzz~tzone ttzzt~descript
           FROM ttzz INNER JOIN ttzzt
           ON ttzz~tzone = ttzzt~tzone
           INTO CORRESPONDING FIELDS OF TABLE timezones
           WHERE ttzz~tzone  NOT LIKE '%UTC%' AND
                 ttzzt~langu = 'E'
           ##too_many_itab_fields.

    GET TIME STAMP FIELD tstamp.

    LOOP AT timezones ASSIGNING <timezone>.
      <timezone>-datetime = |{ tstamp TIMEZONE  = <timezone>-tzone
                                     TIMESTAMP = USER }|.
    ENDLOOP.

    SORT timezones BY datetime.

    WRITE / 'Timezones Around the World' COLOR COL_HEADING.
    ULINE.
    LOOP AT timezones ASSIGNING <timezone>.
      result = |{ <timezone>-descript WIDTH = 32 }| &&
               <timezone>-datetime.
      WRITE / result.
    ENDLOOP.

Description

All time zones with a geographical reference are extracted from the database table TTZZ into an internal table. The current time stamp is formatted with each of these time zones and written to the internal table. The internal table is sorted and displayed according to the formatted time stamp.