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.

    FIELD-SYMBOLS <timezone> TYPE timezone.

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

    DATA(ts) = utclong_current( ).

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

    SORT timezones BY datetime.

    cl_demo_output=>new(
      )->begin_section( 'Timezones Around the World'
      )->display( timezones ).

Description

All time zones with a geographical reference are exported from the database table TTTZ into an internal table. A time stamp is created in a time stamp field and, formatted using each of this time zones, written to the internal table. The internal table is sorted and displayed in accordance with the formatted time stamp.