Options:
... NO-ZERO
...
NO-SIGN
... NO GROUPING
...
DD/MM/YY
... MM/DD/YY
...
DD/MM/YYYY
... MM/DD/YYYY
...
DDMMYY
... MMDDYY
...
YYMMDD
... CURRENCY w
...
DECIMALS d
... ROUND r
...
UNIT u
... TIME ZONE tz
...
EXPONENT e
... USING EDIT MASK mask
... USING NO EDIT MASK
... UNDER g
(only with
WRITE)
... NO-GAP
(only with
WRITE)
...
LEFT-JUSTIFIED
... CENTERED
... RIGHT-JUSTIFIED
The formatting options
UNDER g and NO-GAP
are intended only output to lists and therefore cannot be used with WRITE ... TO.
... NO-ZERO
If the contents of f are equal to zero, only blanks are
output; if f is of type C or N, leading zeros are replaced by blanks.
... NO-SIGN
The leading sign is not output if
f is of type I, P or F.
... NO GROUPING
If f has the type I or P, the thousand separators are omitted.
... DD/MM/YY
... MM/DD/YY
If f is a date field (type D), the date is output with
a 2-character year as specified in the user's master record. Both of these formatting options have the same value.
... DD/MM/YYYY
... MM/DD/YYYY
If f is a date field (type D), the date is output with
a 4-character year as specified in the user's master record. Both of these formatting options have the same value.
... DDMMYY
... MMDDYY
Date formatting like the additions ... DD/MM/YY and ... MM/DD/YY, but without separators.
... YYMMDD
If f is a date field (type D), the date is output in the format YYMMDD (YY = year, MM = month, DD = Day).
... CURRENCY w
Correct format for currency specified in the field w.
Treats the contents of f as a currency amount. The
currency specified in w determines how many decimal places
this amount should have.
The contents of w are used
as a currency key for the table TCURX; if there is no
entry for w, the system assumes that the currency amount has 2 decimal places.
... DECIMALS d
d specifies the number of decimal places for a number
field (type I, P
or F) in d.
If this value is smaller than the number of decimal places in the number, the number is rounded. If
the value is greater, the number is padded with zeros.
Since accuracy with floating point arithmetic
is up to about 15 decimal places (see ABAP number types), up to 17
digits are output with floating point numbers (type F).
(In some circumstances, 17 digits are needed to differentiate between two neighboring floating point
numbers.) If the output length is not sufficient, as many decimal places as possible are output. Negative
DECIMALS specifications are treated as DECIMALS 0.
Effect of different DECIMALS specifications:
DATA: X TYPE P DECIMALS 3 VALUE '1.267',
Y TYPE F VALUE
'125.456E2'.
WRITE: /X DECIMALS 0, "output: 1
/X DECIMALS 2, "output: 1.27
/X DECIMALS 5, "output:
1.26700
/Y DECIMALS 1, "output: 1.3E+04
/Y DECIMALS 5, "output: 1.25456E+04
/Y DECIMALS 20. "output: 1.25456000000000E+04
... ROUND r
Scaled output of a field of type P.
The decimal
point is first moved
r places to the left (r > 0) or to the right
(r < 0); this is the same as dividing with the appropriate
exponent 10**r. The value determined in this way is output
with the valid number of digits before and after the decimal point. If the decimal point is moved to
the left, the number is rounded.
For further information about the interaction between the formatting
options CURRENCY and DECIMALS, see the notes below.
Effect of different ROUND specifications:
DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.
WRITE: /X ROUND -2, "output: 1,249,397.00
/X ROUND 0, "output: 12,493.97
/X ROUND 2, "output:
124.94
/X ROUND 5, "output: 0.12
... UNIT u
Formats a value according to the unit specified in the field u.
The contents of f are treated as a quantity. The unit
specified in u determines how many decimal places should
be output.
If f has more places after the decimal
point than determined in u, the output value will only
have the number of decimal places determined by u, unless
the operation truncates digits other than zero.
If f
has fewer places after the decimal point than determined by u,
the option has no effect.
The contents of u are used
as a unit in the table T006, but if there is no entry,
the formatting option has no effect.
The field f which
is to be output must have the type P.
This option is used for table fields which have the Dictionary type QUAN,
or for fields defined with reference to such fields (
DATA ... LIKE ...).
This formatting option excludes
the options DECIMALS and ROUND.
Suppose the unit 'STD' has 3 decimals
DATA HOUR TYPE P DECIMALS 3 VALUE '1.200'.
WRITE (6) HOUR UNIT 'STD'. "output: 1,2
HOUR = '1.230'.
WRITE (6) HOUR UNIT 'STD'. "output: 1,230
... TIME ZONE tz
Outputs f as a time
stamp
with reference to time zone
tz.
f must
have type
P(8) (short form) or type P(11)
with 7 decimal places (long form).
tz must have type C(6).
You can specify the type exactly by using DATA
... LIKE ...
with reference to the appropriate elements of the structure TZONREF
in the ABAP Dictionary.
It is assumed that the time stamp f
is in
UTC time (see GET TIME
STAMP FIELD f). The system then uses the time zone tz
to determine the difference from UTC time and converts
the time stamp. If tz has the initial value ' ',
the time stamp is output in UTC time
Outputting a
time stamp in long form requires 27 characters, the short form requires 19. The date (corresponding
to a date output with length 10) is formatted according to the setting in the user master record. There
is a space between date and time. In the time part (corresponding to a time output with length 8), the
system inserts ':' as a separator. If you output a time stamp in its long form, the system separates
seconds and fractions of seconds using a comma. If you use an output length shorter than the default,
all separators in both the time and date parts are omitted. If the time stamp is still too long, the
system omits the spaces between the date and the time. After this, the output is truncated from the
right-hand end. If you specify a date formatting option that uses separators, these are not suppressed,
even when you shorten the output.
If the time stamp f is inconsistent, or the system cannot find
the time zone tz, it places a '*' as the first character
of the output. The time stamp f is then output without
taking the time zone into account (in other words, as UTC time).
The output is shifted one character to the right, and the last character is omitted.
If time zone
tz does not exist, you may need to create (or recreate) it in table TTZZ.
You may not use the
TIME ZONE option with CURRENCY,
DECIMALS, EXPONENT,
NO-SIGN, NO-GROUPING,
NO-ZERO, ROUND or UNIT.
Effect of the TIME ZONE option:
DATA: S_TST TYPE timestamp,
L_TST TYPE
timestampl.
SET COUNTRY 'US'.
GET TIME STAMP FIELD S_TST. " S_TST = 19971224111245
GET TIME STAMP FIELD L_TST. " L_TST = 19971224111245,1234567
WRITE: S_TST TIME
ZONE 'UTC+12', " 12/24/1997 23:12:45
/, L_TST TIME ZONE 'UTC+12', " 12/24/1997
23:12:45,1234567
/, (18) S_TST TIME ZONE 'UTC+12', " 24121997 231245
/, (26) L_TST TIME ZONE 'UTC+12', " 24121997 231245,1234567
/,
S_TST TIME ZONE 'UTC+12' DD/MM/YY, " 12/24/97 23:12:45
/, S_TST TIME ZONE 'no tz ' DD/MM/YY. " *12/24/97 11:12:4
... EXPONENT e
The field e defines a fixed exponent for a floating point
number (type F). The mantissa is adjusted to the exponent
by moving the decimal point and padding with zeros. With EXPONENT
0, the exponent specification is suppressed.
However, if the output length is too short to accommodate all digits before the decimal point, the standard output format is used.
Effect of different EXPONENT specifications:
DATA: X TYPE P VALUE '123456789E2'.
WRITE: /X EXPONENT 0, "output:
12345678900,000000
/X(10) EXPONENT 0, "output: 1,235E+10
/X EXPONENT 3, "output: 12345678,90000000E+03
/Y EXPONENT -3, "output: 12345678900000,00E-03
/Y EXPONENT 9, "output: 12,34567890000000E+09
/Y EXPONENT 2
/Y DECIMALS 4. "output: 123456789,0000E+02
... USING EDIT MASK mask
Outputs
f according to the formatting template mask.
Without this addition, f is output in the standard
format for that particular type or with a format defined in the ABAP Dictionary. The addition allows you to define a different format.
You can specify the formatting template as follows:
When formatting, the characters '_' in the template are
replaced from the left (
'LL') or from the right ('RR')
by the characters or digits (type P or I) of the field f.
Formatted output of the time:
DATA TIME TYPE T VALUE '154633'.
WRITE (8) TIME USING EDIT MASK '__:__:__'. "Output: 15:46:33
If the output length "(8)" was not specified here, the
output would be "15:46:" because the implicit output length for the type T is 6.
... USING NO EDIT MASK
Switches off a conversion routine specified in the ABAP Dictionary.
... UNDER g
Output of the field f begins at the column from which
the field g was output. If this happens in the same output line, the output of the field g is overwritten.
After UNDER, the field g
must be written exactly as the reference field in the previous WRITE
statement, i.e. with an offset and length if necessary. The exception to this rule is if
g is a text symbol. In this case, the reference field is determined by the number of the text symbol (not by the text stored there).
Align output to the reference fields:
FIELD-SYMBOLS <FNAME>.
ASSIGN 'First Name' TO <FNAME>.
WRITE: /3 'Name'(001),
15 <FNAME>, 30 'RoomNo', 40 'Age'(002).
...
WRITE: / 'Peterson' UNDER 'Name'(001),
'Ron' UNDER
<FNAME>,
'5.1' UNDER
'RoomNo',
(5) 24 UNDER TEXT-002.
This produces the following output (numbers appear right-justified in their output fields!):
Name First
Name RoomNo Age
Peterson
Ron 5.1 24
... NO-GAP
Suppresses the blank after the field f. Fields output one after the other are then displayed without gaps.
Output several literals without gaps:
WRITE: 'A' NO-GAP, 'B' NO-GAP, 'C'. "Output: ABC
If NO-GAP was not specified here, the output would have
been "A B C" because one blank is always implicitly generated between consecutive output fields.
... LEFT-JUSTIFIED
... CENTERED
... RIGHT-JUSTIFIED
Left-justified, centered or right-justified output.
For number fields (types
I, P and F),
RIGHT-JUSTIFIED is the standard output format, but LEFT-JUSTIFIED is used for all other types, as well as for templates.
Output to a list (WRITE):
DATA: FIELD(10) VALUE 'abcde'.
WRITE: / '|' NO-GAP, FIELD LEFT-JUSTIFIED NO-GAP,
'|',
/ '|' NO-GAP, FIELD CENTERED NO-GAP,
'|',
/ '|' NO-GAP, FIELD RIGHT-JUSTIFIED NO-GAP,
'|'.
* Output: |abcde |
*
| abcde |
* | abcde|
Formatting in a program field (WRITE...TO...)
DATA: TARGET_FIELD1(10),
TARGET_FIELD2 LIKE TARGET-FIELD1,
TARGET_FIELD3
LIKE TARGET-FIELD1.
WRITE: '123' LEFT-JUSTIFIED TO TARGET-FIELD1,
'456' CENTERED TO TARGET-FIELD2,
'789' RIGHT-JUSTIFIED TO TARGET-FIELD3.
WRITE: / '|' NO-GAP, TARGET_FIELD1 NO-GAP, '|',
/ '|' NO-GAP, TARGET-FIELD2 NO-GAP, '|',
/ '|' NO-GAP, TARGET_FIELD3 NO-GAP, '|'.
* Output: |123 |
* | 456 |
* | 789|
Setting date format und decimal character
Every user can specify in his/her
master record (User defaults) how the date is to be formatted on output
and whether the decimal character should be a comma or a period. You can also set these output parameters
for a particular program by using the statement SET COUNTRY.
Specifying several formatting options
You can use the additions of the first
group (NO-ZERO, NO-SIGN,
DD/MM/YY etc., CURRENCY,
DECIMALS, ROUND,
EXPONENT) simultaneously, provided it makes sense. You
can combine the additions
UNDER and NO-GAP
with all other additions in any permutation; however, they are not taken into account until the field f has been formatted according to all the other options.
Templates, conversion routines and alignment
If you want to format a field
using a
special conversion routine
, all the other additions (apart from
UNDER and NO-GAP)
are ignored. This also applies if the conversion routine is not explicitly specified, but comes from
the ABAP Dictionary.
If you want to format a field using a template, the system
first takes into account the options of the first group, and then places the result in the template.
However, if you specify one of the date-related formatting options (DD/MM/YY
etc.), the template is ignored.
Finally, the formatted field or the template is copied to the target
field according to the requested alignment. For type C
fields, it is the occupied length that is relevant, not the defined length; this means that trailing blanks are not taken into account.
Combined usage of
CURRENCY, DECIMALS
and ROUND
The rounding factor (from
the right) in
WRITE price CURRENCY c ROUND r DECIMALS
d
results from the formula
rounding factor = c
+ r - d.
If
DECIMALS is not specified, d
= c applies.
You read this formula in the following
manner:
The field price is supposed to be of
ABAP type P (or I);
it contains a currency amount. The CURRENCY specification
expresses how many decimal places price is to have and
may differ from the definition of price (the decimal point
is not stored internally, but comes from the type attributes of price).
Normally, price is output with as many decimal places
as the field has internally according to the type attributes or the CURRENCY
specification. You can override this number of output decimal places with
DECIMALS. The addition ROUND
addition moves the decimal point r places to the left,
if r is positive, otherwise to the right. This means that
a $ amount is output with ROUND 3 in the unit 1000 $.
According to the above formula, there can also be a "negative" rounding factor; then, the corresponding
number of zeros is appended to the amount price on the right using the "rounding factor". However, the value of "rounding factor" must be at least equal to -14.
Currency fields and
DATA with DECIMALS
If the field price is normally formatted with
decimal places (e.g. fields for currency amounts), these are treated like a
CURRENCY specification when rounding, if CURRENCY
was not expressly specified.
If present, the DECIMALS
specification defines how many decimal places are to be output after rounding.
If the
DECIMALS and the (explicit or implicit) CURRENCY
specifications are different, rounding takes place according to the above formula, even if no
ROUND specification was made (i.e. r = 0).
If a field in the DATA
statement was declared with
DECIMALS n, WRITE treats it like a currency field with n decimal places.
Sales in pfennigs or lira: 246260
Unit TDM or TLira with 1 decimal place.
DATA SALES TYPE P VALUE 246260.
WRITE SALES CURRENCY 'DEM' ROUND 3 DECIMALS 1. " 2,5 TDM
WRITE SALES CURRENCY 'ITL' ROUND 3 DECIMALS 1. " 246,3 TLira
Sales in pfennigs or lira: 99990
Unit TDM or TLira with 1 decimal place.
SALES = 99990.
WRITE SALES CURRENCY 'DEM' ROUND 3 DECIMALS 1. " 1,0 TDM
WRITE SALES CURRENCY 'ITL' ROUND 3 DECIMALS 1. " 100,0 TLira
Sales in pfennigs or lira: 93860
Unit 100 DM or 100 lira with 2 decimal places:
SALES = 93860.
WRITE SALES CURRENCY 'DEM' ROUND 2 DECIMALS 2. " 9,38 HDM
WRITE SALES CURRENCY 'ITL' ROUND 2 DECIMALS 2. " 938,60 HLira
Sales in pfennigs: 93840
Unit 1 DM without decimal places.
SALES = 93860
WRITE SALES CURRENCY 'DEM' DECIMALS 0. " 938 DM
Sales in pfennigs: 93860
Unit 1 DM without decimal places.
SALES = 93860.
WRITE SALES CURRENCY 'DEM' DECIMALS 0. " 939 DM
Non-Catchable Exceptions