D2PIC(rexxnum,picstr[,national][,synerrval])
Formatting is performed -- under the control of the picstr argument -- in a manner similar to that of COBOL numeric-edited fields. The national argument permits customization of D2PIC's algorithm to account for local differences in currency formats.
Conceptually, the operation of D2PIC is as follows:
Note: Each picture symbol's operation depends, in some
part, on whether or not the symbol lies within the significant
portion of the result. Significance is said to be "started"
whenever a significant digit is encountered in the REXX number,
or when a '9', 'V' or decimal point symbol is encountered in the
picture string.
Notes:
In the examples below, the lowercase letter "b" is used
to indicate a blank position in the result.
Note: Simple insertion symbols may also be used in
floating insertion editing. Their use in this context is
described in
"Floating Insertion Editing"
below.
The rules for floating insertion are as follows:
In this situation, the entire result will be filled with spaces.
So for example, if the picture string:
The following examples demonstrate the operation of floating
insertion editing:
The rules governing the use of zero suppression and replacement
editing are as follows:
If the string is composed of 'Z' characters, the entire result
will be filled with spaces. If the string is composed of '*'
characters, the entire result will be filled with asterisks,
except that if a decimal point is present, it will be placed in
its specified position.
The following examples demonstrate the operation of zero
suppression and replacement editing:
Picture String Symbols:
The picstr argument specifies the manner in which the REXX decimal
number given in rexxnum is to be formatted. The following symbols
are permitted in picstr:
99999.99
9(5).99
Simple Insertion Editing:
The characters 'B', '0', '/' and the hundreds separator (default:
',') are simple insertion symbols. These characters are replaced,
one-for-one, with the indicated character in the result. For
example:
picstr rexxnum Result
999B99/9 123 000b12/3
99,999 12345 12,345
99/99/99999 01021995 01/02/1995
Decimal Point Editing:
The decimal point symbol (default: '.') or the 'V' is used to
specify the location of the decimal point in picstr. The value in
rexxnum is aligned on the decimal point location in picstr. For
example:
picstr rexxnum Result
999.999 12.34 012.340
999.99 1.234 001.23
999V9999 12.345 0123450
Fixed Insertion Editing:
The currency symbol (default: '$') and the '+', '-', 'CR' and
'DB' symbols are used to indicate the currency and sign of the
number. When used in fixed insertion editing, only one
occurrence of any of these symbols is permitted. Fixed insertion
characters will appear in the result in exactly the same location
as they are found in picstr. The currency symbol will always
appear as coded. The resulting representation of the other fixed
insertion characters depends upon the sign of rexxnum (refer to
the symbol definitions above for the exact translation that takes
place). Below are some examples of fixed insertion editing:
picstr rexxnum Result
999.99+ 0 000.00+
$999.99CR 22.45 $022.45bb
$999.99CR -27 $027.00CR
-99.99 42 b42.00
-99.99 -79.4 -79.40
Floating Insertion Editing:
Floating insertion editing is used to specify both numeric digit
positions and an insertion character to place to the left of the
resulting number. For example, in the picture string
++++.99
the '+' symbol -- a floating insertion character -- is used to
reserve 4 whole number positions, and indicates that a sign is to
be inserted to the left of the most significant digit. If the
number 22 were to be formatted using this picture string, the
result would be:
b+22.00
Notice that the sign is placed immediately to the left of the
leftmost '2', and that the whole number position to the left of
the sign is blank.
$$,$$$.$$
is applied to a zero REXX number, the result will be:
bbbbbbbbb (9 blanks)
picstr rexxnum Result
$$$$9.99 123.45 b$123.45
+++++.++ 22.9 bb+22.90
+++++.++ 0.01 bbbb+.01
+++++.++ 0 bbbbbbbb
-----.99 23.72 bbb23.72
$$,$$9.99 432.97 bb$432.97
$$,$$9.99 2195.49 $2,195.49
Zero Suppression and Replacement Editing:
Zero suppression and replacement editing is a special case of
floating insertion editing. The two symbols used for this type of
editing -- 'Z' and '*' -- reserve numeric digit positions, and
specify the value that will be used to replace leading
(non-significant) zeros in the result.
picstr rexxnum Result
ZZZZ9.99 123.45 bb123.45
ZZZZZ.ZZ 22.9 bbb22.90
*****.** 0.01 *****.01
ZZZZZ.ZZ 0 bbbbbbbb
*****.** 0 *****.**
*****.99 0 *****.00
ZZZZZ.99 0 bbbbb.00
Z,ZZZ.ZZ 2194.973 2,194.97
Z,ZZZ.ZZ 46.92 bbb46.92
$*,***.** 46.92 $***46.92
Returned Information:
The D2PIC function returns the edited representation of rexxnum.
If you CALL the D2PIC function, the returned value is contained
in the RESULT special variable. The RC special variable is
unchanged.
Examples:
dollar = d2pic(100.42,'$$,$$9.99')
/* dollar = ' $100.42' */
dollar = d2pic(p2d('000010042c'x,2),'$$,$$9.99')
/* dollar = ' $100.42' */
amount = d2pic(1958.21,'ff.ff9,99','f,.')
/* amount = 'f1.958,21'*/
© Copyright 1998 by Open Software Technologies, Inc.