RPG Tutorial: Output edit words

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:

Examples of Edit Words

Edit Word

Data Field

Result

if data is positive

if data is negative

' ,  0.  ' 000005      .05      .05
' ,  0.  ' 100000 1,000.00 1,000.00
'  AMT0' 005      5      5
'  AMT0' 100 10AMT0 10AMT0
'  0AMT ' 005   AMT5   AMT5
'  0AMT ' 1005 100AMT5 100AMT5
'  XX  ' 005      5      5
'  XX  ' 100  1XX00  1XX00
'.  ' 05   5   5
'  , $0.  ' 000005      $.05      $.05
'  , $0.  ' 100000 $1,000.00 $1,000.00
'  ,$0 .  ' 000010     $0.10     $0.10
'$0  .  ' 00100  $ 01.00  $ 01.00
'  0-' 010   10   10-
'  0CR*' 010  10  *  10CR*
'0  -  -    ' 123456789 123-45-6789 123-45-6789
' 0CR-' 05   5  -   5CR-
' 0CREDIT' 05  5  EDIT  5CREDIT
'  **' 10 *10* *10*
' 0**' 10 10** 10**
'$ ,  *.  ' 000010 $*****.10 $*****.10
'$ ,  *.  ' 050000 $**500.00 $**500.00
'    0 ' 05      5      5
'   0  ' 05     05     05
' 0    ' 05   0005   0005


Return to Site Home Page 


This page was last updated on January 17, 2015.