MainframeMaster

Editing Numeric Fields

Editing numeric fields in DFSORT means converting internal numeric values—packed decimal (PD), zoned decimal (ZD), or binary (BI)—into a human-readable form. Internal formats are compact and not readable when printed; editing inserts signs, commas, decimal points, and leading zero suppression so that numbers look like "1,234.56" or "-12,345". You can do this in both INREC and OUTREC using edit patterns (characters I, T, S and literals) or predefined masks (e.g. M11, M12). Editing in INREC is useful when the formatted value must be used for sorting or filtering; otherwise OUTREC is typical for report output. This page explains pattern characters, predefined masks, EDIT= and SIGNS=, and how to choose INREC vs OUTREC.

INREC Processing
Progress0 of 0 lessons

Why Edit Numeric Fields?

Packed decimal (PD) and zoned decimal (ZD) store numbers in a form that saves space and is fast for arithmetic, but when you print or display them you see unreadable characters or raw digits. Editing turns those values into strings that look like real numbers: with a decimal point in the right place, thousands separators (commas), a minus sign for negatives, and optional leading zero suppression (so 5 appears as "5" not "0005"). DFSORT does this with edit masks: a pattern that describes where digits and punctuation go. The same capability is available in INREC (before the sort) and OUTREC (after the sort). Use INREC when you need to sort or filter by the edited value; use OUTREC when you only need the formatted value in the final output.

Edit Pattern Characters

An edit pattern is a string of characters that controls how each position in the output is filled. DFSORT uses a few special characters; everything else is copied literally.

Edit pattern characters
CharacterMeaningExample
ILeading insignificant digit: displays 1–9 or blank for 0 (leading zero suppression)III → " 5" for 5, "123" for 123
TSignificant digit: always displays 0–9TTT → "005", "123"
S (before digits)Leading sign: + or − (or blank) at the startSII,III → "+1,234" or " 1,234"
S (after digits)Trailing sign: + or − at the endIII,IIIS → "1,234+" or "1,234-"
Other (,. - etc.)Literal character in output (comma, decimal point, hyphen, space)II,III.IIT → "1,234.56"

I (insignificant leading digit) gives leading zero suppression: the digit is shown as 1–9, or as a blank when it is 0. So III for the value 5 might produce " 5" (two blanks and 5). T (significant digit) always shows 0–9—no suppression. S is the sign: one character before the digits means a leading sign (e.g. + or − at the start); one S after the digits means a trailing sign. Commas, periods, spaces, and hyphens in the pattern are printed as-is in the output. So a pattern like II,III.IIT could produce "1,234.56" for 123456 (with implied decimal places).

Predefined Edit Masks (M0–M26)

DFSORT provides predefined masks so you do not have to write every pattern from scratch. Each mask has a fixed pattern for signs, commas, and decimal point. The exact set (M0 through M26) and their patterns are in the IBM DFSORT Application Programming Guide; below are a few commonly used ones.

Selected predefined edit masks
MaskDescriptionExample
M0Leading/trailing sign, leading zero suppression+01234 → 1234, -00001 → -1
M11Digits with leading zeros (all T)0001001234
M12Comma-separated thousands, leading sign+1234567 → 1,234,567
M2Commas and decimal point, trailing sign+123450 → 1,234.50
M4Leading sign, commas, decimal+0123456 → +1,234.56

M11 is often used for a simple digit string with leading zeros (all T positions). M12 gives comma-separated thousands with a leading sign (e.g. 1,234,567 or -12,345). M2 and M4 add a decimal point and commas. You specify the mask by name (e.g. M12) in the FIELDS= or BUILD= list instead of EDIT=(...). The output length of the edited field is determined by the mask or by LENGTH= when supported.

EDIT= and SIGNS=

When you use a custom pattern instead of a predefined mask, you code EDIT=(pattern). The pattern uses I, T, S, and literal characters as above. SIGNS=(x,y) tells DFSORT what to use for positive and negative: for example SIGNS=(,-) means positive is shown as blank (or no sign) and negative as minus. Some products allow SIGNS=(+,−) for an explicit plus and minus. The first value in the pair is for positive, the second for negative. This affects where S appears in the output.

Data Formats You Can Edit

Edit masks apply to numeric input fields. You must specify the correct format so DFSORT interprets the bytes before editing.

  • PD (packed decimal) — Most common. Stored as half-bytes (nibbles); length is the number of bytes (e.g. 4 bytes can hold 7 digits + sign). Edited to character with commas, sign, decimal point.
  • ZD (zoned decimal) — One digit per byte in EBCDIC (e.g. F1 F2 F3 for 123). Length is the number of bytes. Same edit patterns apply.
  • BI (binary) — Fullword or halfword binary. Can be edited with masks that expect a numeric value (e.g. M0, M11). Length is 2 or 4 bytes typically.

CH (character) is not a numeric format; do not use numeric edit masks on CH fields. For CH fields that contain digit characters, you would copy them as-is or use other transformation.

OUTREC Example: Edit a Zoned Decimal Field

Input: 80-byte fixed records; positions 1–39 are identification, positions 40–47 are an 8-byte zoned decimal "marks" field (e.g. 00000560). We want to copy 1–39 and output the marks in a readable format with commas and optional sign (e.g. M12 style).

text
1
2
SORT FIELDS=(1,5,CH,A) OUTREC FIELDS=(1,39,40,8,ZD,EDIT=(SII,III,IIT),SIGNS=(,-))

1,39 copies the first 39 bytes. 40,8,ZD takes the 8-byte zoned decimal at 40. EDIT=(SII,III,IIT) formats it: leading sign (S), then three I (leading zero suppression), comma, three I, comma, then IIT. SIGNS=(,-) means positive has no sign (or blank), negative has minus. The edited field replaces the raw 8 bytes in the output; total length depends on the pattern length. For positive 560, you might see "560" (leading zeros suppressed). Exact output length and placement depend on your DFSORT version; some allow LENGTH=n to fix the edited field length.

OUTREC Example: Predefined Mask M11

To format a packed decimal field with leading zeros (no commas, no decimal), use a mask like M11:

text
1
2
SORT FIELDS=COPY OUTREC FIELDS=(1,10,11,5,PD,M11,LENGTH=10)

Here 11,5,PD is a 5-byte packed decimal (up to 9 digits + sign). M11 formats it as digits with leading zeros. LENGTH=10 reserves 10 bytes for the edited result. Positions 1–10 are copied from input; then the 10-byte edited field is written. So the output has 20 bytes per record. Use M11 when you need a fixed-width numeric string (e.g. for a key or report column) without commas or decimal point.

Editing in INREC

The same EDIT=, SIGNS=, and predefined masks (M0M26) work in INREC. Use INREC when the edited value must be part of the record that the sort or INCLUDE/OMIT sees. For example, if you need to sort by a formatted amount (e.g. with commas and decimal) or filter with INCLUDE COND= on that formatted value, you must edit in INREC so that the reformatted record contains the edited field at a known position. If you only edit in OUTREC, the sort runs on the original (unedited) record. So: edit in INREC when the formatted value drives sort or filter; edit in OUTREC when you only need pretty output.

Length of the Edited Field

The length of the edited output is determined by the pattern or mask: each I, T, S, and literal character usually produces one byte. So EDIT=(SII,III,IIT) has a fixed length. Some DFSORT versions allow LENGTH=n to pad or truncate the edited field to n bytes. If the edited value is shorter than the space reserved, it may be right- or left-justified and padded with spaces depending on the product. Check your manual for LENGTH= and alignment.

Explain It Like I'm Five

Imagine the computer has a number written in a secret code (packed decimal): it saves space but nobody can read it. Editing is like a machine that takes that secret number and writes it on a label the way we write numbers: with commas (1,234), a dot for cents (12.50), and a minus when it's negative (-5). The pattern is the rule that says where to put the commas and the dot. So we tell the computer "use this pattern" and it prints the number so people can read it. We can do that before sorting (INREC) if we want to sort by that pretty number, or after (OUTREC) if we just want it pretty on the report.

Exercises

  1. Input has a 4-byte packed decimal amount at position 50. You want the output file to show it with commas and two decimal places. Do you use INREC or OUTREC? Why?
  2. What is the difference between I and T in an edit pattern? Give an example value that would look different with III vs TTT.
  3. What does SIGNS=(,-) mean for positive and negative values?
  4. Write an OUTREC FIELDS= that copies bytes 1–20 and edits the 5-byte PD field at 21 with the M12 mask. (Assume LENGTH= is supported for the edited field.)

Quiz

Test Your Knowledge

1. What does the pattern character T represent in a DFSORT edit mask?

  • Trailing sign
  • A significant digit displayed as 0–9
  • Tab character
  • Total length

2. When should you edit a numeric field in INREC instead of OUTREC?

  • Never; editing is only in OUTREC
  • When the edited value must be used for sorting or filtering (INREC runs before sort)
  • INREC is faster
  • Only for packed decimal

3. What does SIGNS=(,-) do in an EDIT specification?

  • Sets decimal and comma
  • Specifies how plus and minus are displayed (e.g. blank for plus, minus for negative)
  • Sort order
  • Field length

4. Which data format is most commonly edited with DFSORT edit masks?

  • Character (CH)
  • Packed decimal (PD)
  • Binary (BI) only
  • Fixed-point only

5. What is the difference between I and T in an edit pattern?

  • They are the same
  • I = leading insignificant digit (1–9 or blank for 0); T = significant digit (always 0–9)
  • I is for integer, T for total
  • Only T can have commas