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.

Source Code

REPORT demo_string_template_timezone.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    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.

    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.

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

START-OF-SELECTION.
  demo=>main( ).

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.