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 

Character String Templates, Time Formats

The example demonstrates the various time formats for embedded expressions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: seconds   TYPE i,
          timetable TYPE TABLE OF t,
          land      TYPE t005x-land,
          comp      TYPE i.

    CONSTANTS n     TYPE i VALUE 4.

    FIELD-SYMBOLS: <time> TYPE t,
                   <col>  TYPE string.

    setup( ).

    DO 24 / n TIMES.
      seconds = ( sy-index - 1 ) * 3600 * n.
      APPEND seconds TO timetable.
      seconds = seconds + 1.
      APPEND seconds TO timetable.
      seconds = seconds + ( n - 1 ) * 3600 + 59 * 60 + 58.
      APPEND seconds TO timetable.
    ENDDO.

    LOOP AT timetable ASSIGNING <time>.
      result-col1 = |{ <time> TIME = RAW }|.
      result-col2 = |{ <time> TIME = ISO }|.
      SELECT land
             FROM t005x
             INTO (land)
             WHERE land LIKE '@%'.
        comp = sy-dbcnt + 2.
        ASSIGN COMPONENT comp OF STRUCTURE result TO <col>.
        <col> = |{ <time> COUNTRY = land }|.
      ENDSELECT.
      APPEND result TO result_tab.
    ENDLOOP.

    teardown( ).

    display( ).

Description

An internal table timetable is filled with various times, and these times are output in all possible country-specific time formats using parameter COUNTRY. For this purpose, in the setup and teardown help methods, temporary rows with the possible values of column TIMEFM are inserted into database table T005X and are deleted again once they have been used.