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, Formatting Settings

The example demonstrates the formatting settings for numbers, date outputs, and time outputs.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: num       TYPE p DECIMALS 2,
          date      TYPE d,
          time      TYPE t,
          tstamp    TYPE timestampl,
          BEGIN OF country,
            key  TYPE t005x-land,
            name TYPE t005t-landx,
          END OF country,
          country_tab LIKE TABLE OF country.

    SELECT land AS key
           FROM t005x
           INTO CORRESPONDING FIELDS OF TABLE country_tab.

    LOOP AT country_tab INTO country.
      SELECT SINGLE landx AS name
             FROM t005t
             INTO CORRESPONDING FIELDS OF country
             WHERE  land1 = country-key AND
                    spras = sy-langu.
      MODIFY country_tab FROM country INDEX sy-tabix.
    ENDLOOP.

    SORT country_tab BY name AS TEXT.
    country-key =  space.
    country-name = 'User Master Record'.
    INSERT country INTO country_tab INDEX 1.

    num  = sy-datum / 100.
    date = sy-datum.
    time = sy-uzeit.
    GET TIME STAMP FIELD tstamp.

    LOOP AT country_tab INTO country.
      SET COUNTRY country-key.
      result-col1 = country-name.
      result-col2 = country-key.
      result-col3 = |{ num    NUMBER    = ENVIRONMENT }|.
      result-col4 = |{ date   DATE      = ENVIRONMENT }|.
      result-col5 = |{ time   TIME      = ENVIRONMENT }|.
      result-col6 = |{ tstamp TIMESTAMP = ENVIRONMENT }|.
      APPEND result TO result_tab.
      IF sy-tabix = 1.
        CLEAR result.
        APPEND result TO result_tab.
      ENDIF.
    ENDLOOP.

    display( ).

Description

The formatting setting of the language environment is set using the SET COUNTRY statement to the standard format from the user master record and all the current country-specific formats contained in the table T005X. Using the ENVIRONMENT parameter of the formatting options NUMBER, DATE, TIME, and TIMESTAMP, the effect of the settings on the embedded expressions of string templates is demonstrated.