SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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.
Source Code
REPORT demo_string_template_env_sett.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
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.
DATA: BEGIN OF result,
name TYPE string,
key TYPE string,
number TYPE string,
date TYPE string,
time TYPE string,
timestamp TYPE string,
END OF result,
results LIKE TABLE OF result.
SELECT land AS key
FROM t005x
INTO CORRESPONDING FIELDS OF TABLE country_tab
##TOO_MANY_ITAB_FIELDS.
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-name = country-name.
result-key = country-key.
result-number = |{ num NUMBER = ENVIRONMENT }|.
result-date = |{ date DATE = ENVIRONMENT }|.
result-time = |{ time TIME = ENVIRONMENT }|.
result-timestamp = |{ tstamp TIMESTAMP = ENVIRONMENT }|.
APPEND result TO results.
IF sy-tabix = 1.
CLEAR result.
APPEND result TO results.
ENDIF.
ENDLOOP.
cl_demo_output=>display( results ).
ENDMETHOD. "main
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
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.