RPG, like most programming languages, has a mechanism for
editing numeric data. Typical editing involves suppression of leading
zeros, inserting commas and decimal points, inserting fixed or floating dollar
symbols to clarify monetary amounts, and providing sign status (+/- or DB/CR).
In order to edit a numeric field using an edit word,
column 38 of the output specification (Edit Codes) must remain blank.
Under RPG I, only the Z edit code is functional, so most of the time it is
necessary to utilize an edit word to achieve the most desirable result in
editing numeric information.
The name of the numeric field to be edited is placed in
columns 32-37 (Field Name) and the edit word, enclosed in apostrophes, is placed
in columns 45-70 (Constant or Edit Word) of the same output specification.
Here are a few general rules to follow for forming edit
words:
A blank in the edit word is replaced with the digit
from the corresponding position of the data field.
An ampersand (&) causes a space in the edited
field. There is no way to obtain an ampersand in an edited field.
A zero (0) is used to stop zero suppression. It
is placed in the rightmost position where zero suppression is to take
place. It will be replaced with the character from the corresponding
position of the data field, unless that character is a zero. At least
one leading zero is suppressed. If you do not want any leading zeros
suppressed, make the edit word one character larger than the data field and
place a zero in the first position of the edit word.
An asterisk (*) is used for asterisk protection and
zero suppression. Like the zero (above), it is placed in the rightmost
position where zero suppression is to take place. It will be replaced
with the character from the corresponding position of the data field unless
that character is a zero and there is no significant digit to its
left. Each zero that is suppressed is replaced by an asterisk.
A dollar sign in the edit word placed immediately to
the left of the zero suppression code (0) causes the insertion of a dollar
sign in the position to the left of the first significant digit. This
is what is usually referred to as a floating dollar sign. If it
is necessary for the dollar sign to appear when all digits in the data are
significant, the edit word must start with a blank to allow space in which
the dollar sign can print. A dollar sign in the edit word placed
immediately after the initial apostrophe will be printed in the same
location each time. This is referred to as a fixed dollar sign.
Commas and decimal points placed in the edit word are
printed in the edited output in the same relative positions in which they
were written unless they are to the left of significant digits. If
zero suppression has not been stopped by the presence of a zero in the edit
word, they will be replaced by either spaces or asterisks, depending upon
the method of zero suppression specified. Other than the fixed dollar
sign, any characters that precede the first non-zero digit position will
always be suppressed.
All other characters used in the edit word are printed
if they are to the right of the non-zero digits in the data field. If
they are to the left of the first non-zero digit in the data field, they
will be replaced by spaces or asterisks.
The letters CR or the minus symbol (-) placed on the
rightmost position of the edit word (typically known as the status portion
of the edit word) will be printed if the sign in the dat field is
minus. If the sign is positive, they will be replaced by spaces.
Asterisks to the right of the CR or minus symbol (-)
are printed. They are typically used to indicate a specific level of
control total.
If there are more digit positions in the edit word than
there are digits in the field to be edited, leading zeros will be added to
the field before editing.
An edit word can contain a maximum of fifteen digit
positions, the maximum length of a numeric data field in RPG.
When multiple CR or minus symbols are placed in an edit
word, the first one to the right of the last replaceable data character is
considered the status. Any other CR or minus symbols are treated as
constants.