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.

    DATA: BEGIN OF result,
            raw        TYPE string,
            iso        TYPE string,
            h24        TYPE string,
            h12_1_12_a TYPE string,
            h12_1_12_b TYPE string,
            h12_0_11_a TYPE string,
            h12_0_11_b TYPE string,
          END OF result,
          results LIKE TABLE OF result.

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

    setup( ).

    timetable =
      VALUE #( FOR j = 1 UNTIL j > 24 / n
               LET s = ( j - 1 ) * 3600 * n IN
               ( CONV t( s ) )
               ( CONV t( s + 1 ) )
               ( CONV t( s + ( n - 1 ) * 3600 + 59 * 60 + 59 ) ) ).

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

    teardown( ).

    cl_demo_output=>display( results ).

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.