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.
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.
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.
| Character | Meaning | Example |
|---|---|---|
| I | Leading insignificant digit: displays 1–9 or blank for 0 (leading zero suppression) | III → " 5" for 5, "123" for 123 |
| T | Significant digit: always displays 0–9 | TTT → "005", "123" |
| S (before digits) | Leading sign: + or − (or blank) at the start | SII,III → "+1,234" or " 1,234" |
| S (after digits) | Trailing sign: + or − at the end | III,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).
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.
| Mask | Description | Example |
|---|---|---|
| M0 | Leading/trailing sign, leading zero suppression | +01234 → 1234, -00001 → -1 |
| M11 | Digits with leading zeros (all T) | 0001001234 |
| M12 | Comma-separated thousands, leading sign | +1234567 → 1,234,567 |
| M2 | Commas and decimal point, trailing sign | +123450 → 1,234.50 |
| M4 | Leading 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.
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.
Edit masks apply to numeric input fields. You must specify the correct format so DFSORT interprets the bytes before editing.
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.
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).
12SORT 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.
To format a packed decimal field with leading zeros (no commas, no decimal), use a mask like M11:
12SORT 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.
The same EDIT=, SIGNS=, and predefined masks (M0–M26) 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.
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.
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.
1. What does the pattern character T represent in a DFSORT edit mask?
2. When should you edit a numeric field in INREC instead of OUTREC?
3. What does SIGNS=(,-) do in an EDIT specification?
4. Which data format is most commonly edited with DFSORT edit masks?
5. What is the difference between I and T in an edit pattern?