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 output, and time output.

Other versions: 7.31 | 7.40 | 7.54

Source Code

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

    DATA: BEGIN OF result,
            name      TYPE string,
            key       TYPE string,
            number    TYPE string,
            date      TYPE string,
            time      TYPE string,
            utclong   TYPE string,
            timestamp TYPE string,
          END OF result,
          results LIKE TABLE OF result.

    SELECT land AS key
           FROM t005x

    LOOP AT country_tab INTO country.
      DATA(idx) = sy-tabix.
      SELECT SINGLE landx AS name
             FROM t005t
             WHERE  land1 = @country-key AND
                    spras = @sy-langu
             INTO CORRESPONDING FIELDS OF @country.
      IF sy-subrc = 0.
        MODIFY country_tab FROM country INDEX idx.
        DELETE country_tab INDEX idx.

    SORT country_tab BY name AS TEXT.
    INSERT VALUE #( key =  space name = 'User Master Record' )
           INTO country_tab INDEX 1.

    num     = sy-datum / 100.
    date    = sy-datum.
    time    = sy-uzeit.
    utclong = utclong_current( ).
    tstamp  = cl_abap_tstmp=>utclong2tstmp_short( utclong ).

    LOOP AT country_tab INTO country.
      DATA(tabix) = sy-tabix.
      SET COUNTRY country-key.
      results = VALUE #( BASE results
      ( name      = country-name
        key       = country-key
        number    = |{ num     NUMBER    = ENVIRONMENT }|
        date      = |{ date    DATE      = ENVIRONMENT }|
        time      = |{ time    TIME      = ENVIRONMENT }|
        utclong   = |{ utclong TIMESTAMP = ENVIRONMENT }|
        timestamp = |{ tstamp  TIMESTAMP = ENVIRONMENT }| ) ).
      IF tabix = 1.
        results = VALUE #( BASE results ( ) ).

    cl_demo_output=>display( results ).


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