ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Character String and Byte String Processing → Statements for Character String and Byte String Processing → WRITE - TO → WRITE - format_options
Decimal Floating Point Numbers, Formatting with STYLE
This example demonstrates the formatting of decimal floating point numbers.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: number TYPE decfloat34 VALUE '-12345.67890',
BEGIN OF result,
style TYPE string,
write_to TYPE c length 20,
template_raw TYPE c length 20,
template_user TYPE c length 20,
END OF result,
results LIKE TABLE OF result,
off TYPE i,
exc TYPE REF TO cx_sy_unknown_currency.
get_formats( ).
LOOP AT demo=>formats INTO demo=>format.
result-style = demo=>format-name+2.
WRITE number TO result-write_to
STYLE demo=>format-value LEFT-JUSTIFIED.
result-template_raw =
|{ number STYLE = (demo=>format-value) }|.
result-template_user =
|{ number STYLE = (demo=>format-value)
NUMBER = USER }|.
APPEND result TO results.
ENDLOOP.
cl_demo_output=>display( results ).
Description
The program uses a classic list to depict the effects of all possible output formats from the CL_ABAP_FORMAT class for a
decimal floating point number.
The possible ouput formats are read using RTTI and are sorted according to their value. Formatting takes
place once with the STYLE
addition of the WRITE
TO statement and twice with the STYLE
parameter in
embedded expressions of string templates.
For the first string template, the format RAW
is implicitly used for the formating option NUMBER
, which is why a point
(.
) and not a thousand separator is displayed as the decimal separator. Explicitly
specifying the format USER
creates the same formatting as for WRITE TO
.