EDTCDE (Edit Code) keyword for display files

You use this field-level keyword to edit output-capable numeric fields.

The format of the keyword is:

EDTCDE(edit-code [* |floating-currency-symbol])
Editing includes the following changes to the appearance of displayed fields, depending on which edit code is specified:
  • Leading zeros are suppressed.
  • The field can be punctuated with commas and periods to show decimal position and to group digits by threes.
  • Negative values can be displayed with a minus sign or CR to the right.
  • Zero values can be displayed as zero or blanks.
  • Asterisks can be displayed to the left of significant digits to provide asterisk protection.
  • A currency symbol (corresponding to the system value QCURSYM) can be displayed immediately to the left of the significant digit that is farthest to the left (called floating-currency symbol). For fixed-currency symbols, use the EDTWRD keyword.
  • The field can be further edited using a user-defined edit code.

EDTCDE covers most editing requirements. Use EDTWRD when the EDTCDE keyword is not sufficient.

You cannot specify both EDTCDE and EDTWRD for the same field. If a field previously defined in a database file has EDTCDE specified, you need not specify EDTCDE for that field in the display file. You can specify R in position 29 to refer to the previously defined field. The editing specified for the referenced field is included in the display file. However, if you also specify length, data type, or decimal positions for a display file field, editing specified for the referenced field is not included in the display file, and you must specify editing again in the display file.

The DFT and DFTVAL keywords cannot be specified with the EDTCDE keyword.

Option indicators are not valid for this keyword.

The rules for specifying edit codes and edit words are the same in all types of files. You can specify two kinds of edit codes: IBM® i edit codes and user-defined edit codes.

The EDTCDE keyword is valid only for fields with Y or blank in position 35 (Data Type/Keyboard Shift). The use of this keyword changes the default used for position 35 to a Y.

IBM i edit codes

The IBM i edit codes are:

1 through 4
A through D
J through Q
W through Z
Note: The IBM i hardware operates with a preferred sign of F, which is equivalent to using edit code X. Edit code X sets the default of a blank keyboard shift (position 35) to numeric-only (attribute Y). The display length of the field is determined by the keyboard shift, not by edit code X (the default numeric-only Y attribute might add 1 position to the field for decimals). If the DATE or TIME keyword is specified with edit code X, the separator character is not displayed.

Optionally specifying asterisk fill or floating currency symbol

You can optionally specify asterisk fill or floating currency symbol with edit codes 1 through 4, A through D, and J through Q.

When you specify asterisk fill, an asterisk (*) is printed for each zero that is suppressed. A complete field of asterisks is printed for a zero balance field.

When you specify floating currency symbol, the symbol appears to the left of the first significant digit. The symbol does not print on a zero balance when an edit code is used that suppresses the zero balance. (The symbol that you specify must match the system value for the currency symbol (QCURSYM). The symbol must match when the file is created. It need not match when the file is used.)

Note: If an edit code is changed after a file is created, the editing specified at the time the file was created is used. The new edit code is not used unless the file is recreated.

The following table summarizes the functions provided by IBM i edit codes.

Table 1. Summary chart for IBM i edit codes
Edit codes Commas1 displayed Decimal points1 displayed Sign displayed when negative value Blank value of QDECFMT system value I value of QDECFMT system value J value of QDECFMT system value Leading Zero suppressed
1 Yes Yes No sign .00 or 0 ,00 or 0 0,00 or 0 Yes
2 Yes Yes No sign Blanks Blanks Blanks Yes
3   Yes No sign .00 or 0 ,00 or 0 0,00 or 0 Yes
4   Yes No sign Blanks Blanks Blanks Yes
A Yes Yes CR .00 or 0 ,00 or 0 0,00 or 0 Yes
B Yes Yes CR Blanks Blanks Blanks Yes
C   Yes CR .00 or 0 ,00 or 0 0,00 or 0 Yes
D   Yes CR Blanks Blanks Blanks Yes
J Yes Yes -(Minus) .00 or 0 ,00 or 0 0,00 or 0 Yes
K Yes Yes -(Minus) Blanks Blanks Blanks Yes
L   Yes -(Minus) .00 or 0 ,00 or 0 0,00 or 0 Yes
M   Yes -(Minus) Blanks Blanks Blanks Yes
N Yes Yes -(Minus) .00 or 0 ,00 or 0 0,00 or 0 Yes
O Yes Yes -(Minus) Blanks Blanks Blanks Yes
P   Yes -(Minus) .00 or 0 ,00 or 0 0,00 or 0 Yes
Q   Yes -(Minus) Blanks Blanks Blanks Yes
W2             Yes
Y3             Yes
Z4             Yes
Notes:
  1. The QDECFMT system value determines the decimal point character (period in U.S. usage), the character used to separate groups of three digits (comma in U.S. usage), and the type of zero suppression (depending on comma and period placement).
  2. The W edit code suppresses the farthest left zero of a date field that is five digits long. It also suppresses the three farthest left zeros of a field that is six to eight digits long. The W edit code also inserts slashes (/) between the month, day, and year according to the following pattern:
    • nn/nnn
    • nnnn/nn
    • nnnn/nnn
    • nnnn/nn/nn
  3. The Y edit code suppresses the farthest left zero of a date field that is three to six digits long or eight digits long. It also suppresses the two farthest left zeros of a field that is seven positions long. The Y edit code also inserts slashes (/) between the month, day, and year according to the following pattern:
    • nn/n
    • nn/nn
    • nn/nn/n
    • nn/nn/nn
    • nnn/nn/nn
    • nn/nn/nnnn

    If the DATE keyword is specified with EDTCDE(Y), the separator character used is the job attribute, DATSEP at run time. The slash (/) is the default DATSEP.

  4. The Z edit code removes the sign (plus and minus) from a numeric field. The sign of the units position is changed to a hexadecimal F before the field is written.

User-defined edit codes

Edit codes 5 through 9 are user-defined edit codes. A user-defined edit code can do more editing than an IBM i edit code. For example, you might need to edit numbers that include hyphens (such as telephone numbers) or more than one decimal point. You can use user-defined edit codes for these functions. These edit codes are named QEDIT5, QEDIT6, QEDIT7, QEDIT8, and QEDIT9, and can be referred to in DDS or a high-level language program by number (5, 6, 7, 8, or 9).

A user-defined edit code is an IBM i object and must exist before display file creation. It is created using the Create Edit Description (CRTEDTD) command. When you create a display file in which a user-defined edit code is specified, editing information is extracted from the previously created edit description. Changing a user-defined edit code after display file creation does not affect the display file unless the display file is re-created.

The following table shows edit codes, unedited source data, and edited output. Zero suppression and decimal characters are determined by the system value QDECFMT. The date separator character is determined by the job attribute DATSEP. In this figure, QDECFMT is assumed to equal x (blank), and DATSEP is assumed to equal / (slash).

Table 2. Valid edit codes, source data, and edited output
Edit codes Positive number with two decimal positions Positive number with no decimal positions Negative number with three decimal positions1 Negative number with no decimal positions1 Zero balance with two decimal positions1 Zero balance with no decimal positions1
Unedited 1234567 1234567 xxxx.125– 125– xxxxxx xxxxxx
1 12,345.67 1,234,567 .125 125 .00 0
2 12,345.67 1,234,567 .125 125    
3 12345.67 1234567 .125 125 .00 0
4 12345.67 1234567 .125 125    
A 12,345.67 1,234,567 .125CR 125CR .00 0
B 12,345.67 1,234,567 .125CR 125CR    
C 12345.67 1234567 .125CR 125CR .00 0
D 12345.67 1234567 .125CR 125CR    
J 12,345.67 1,234,567 .125- 125- .00 0
K 12,345.67 1,234,567 .125- 125-    
L 12345.67 1234567 .125- 125- .00 0
M 12345.67 1234567 .125- 125-    
N 12,345.67 1,234,567 -.125 -125 .00 0
O 12,345.67 1,234,567 -.125 -125    
P 12345.67 1234567 -.125 -125 .00 0
Q 12345.67 1234567 -.125 -125
W2 1234/567 1234/567 0/125 0/125 0/000 0/000
Y3 123/45/67 123/45/67 0/01/25 0/01/25 0/00/00 0/00/00
Z4 1234567 1234567 125 125    
Notes:
  1. The x represents a blank.
  2. The W edit code suppresses the farthest left zero of a date field that is five digits long. It also suppresses the three farthest left zeros of a field that is six to eight digits long. For more information, see the second footnote in Table 1.
  3. The Y edit code suppresses the farthest left zero of a date field that is three to six digits long or eight digits long. It also suppresses the two farthest left zeros of a field that is seven positions long. For more information, see the third footnote in Table 1.
  4. The Z edit code removes the sign (plus or minus) and suppresses leading zeros.

Example

The following example shows how to specify the EDTCDE keyword.

|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00010A            PRICE          5  2   1 10EDTCDE(J)
00020A            SALES          7  2   2 10EDTCDE(K $)
00030A            SALARY         8  2   3 10EDTCDE(1 *)
     A
The display length for PRICE is 7 because the J edit code is specified, causing the field to contain a decimal point and an ending minus sign. It is edited as:
ddd.dd-
where d represents a digit.
The display length for SALES is 11 because the K edit code and floating currency symbol are specified. It is edited as:
$dd,ddd.dd-
The display length for SALARY is 10 because the edit code 1 is specified with asterisk fill. It is edited as:
ddd,ddd.dd