MainframeMaster

Edit Masks in DFSORT

An edit mask in DFSORT is a pattern that turns internal numeric values—packed decimal (PD), zoned decimal (ZD), or binary (BI)—into readable text. Internal formats are compact and sort correctly but look like garbage when printed; edit masks let you insert commas, decimal points, signs, and control leading zero suppression so output appears as "1,234.56" or "-12,345". You can define your own pattern with EDIT=(pattern) or use predefined masks M0 through M26. This page covers the pattern characters (I, T, S), literals, the SIGNS= parameter, how to choose and use predefined masks, and where to apply editing (INREC vs OUTREC).

OUTREC Processing
Progress0 of 0 lessons

What Is an Edit Mask?

An edit mask is a template that describes how each digit and the sign of a number should appear in the output. The input is a numeric field in PD, ZD, or BI format; the output is a character string with optional commas, decimal point, sign, and either leading zero suppression (blanks instead of zeros) or all digits shown. You use edit masks in INREC or OUTREC by specifying the field with its position, length, format, and either EDIT=(pattern) or a predefined mask name (e.g. M12). The result is a fixed-length character field that you can place in the output record alongside other fields.

Pattern Characters: I, T, S, and Literals

The EDIT= pattern is a string of characters. Each character has a specific meaning:

Edit pattern characters
CharacterMeaningEffect
ILeading insignificant digitDisplays 1–9 as the digit; displays blank when the digit is a leading zero. Used for digits where leading zeros should be suppressed.
TSignificant digitAlways displays the digit 0–9. No suppression; used for digits that must always appear (e.g. after decimal point or in fixed-width output).
SSign positionS before digits = leading sign; S after digits = trailing sign. The actual character (+ - blank CR DB) is controlled by SIGNS=.
LiteralsComma, period, space, etc.Any other character in the pattern is output as-is. Use for thousands separators, decimal point, hyphens, or spaces.

I (leading insignificant digit): Used for digit positions where leading zeros should not be shown. If the digit is 0 and all digits to its left are also 0 (or there are none), the output is a blank. Otherwise the digit 1–9 is displayed. So "II,III" for 00123 becomes " 123" (two leading zeros as blanks), and for 12345 becomes "12,345".

T (significant digit): The digit is always displayed as 0–9. No suppression. Use T for digits that must always appear, such as those after a decimal point or when you need a fixed-width numeric field (e.g. M11 uses all T’s).

S (sign): One S represents one sign position. If S appears before the digit positions, the sign is leading (e.g. +1234 or -1234). If S appears after the digits, the sign is trailing (e.g. 1234+ or 1234-). The actual character (plus, minus, blank, or in some masks CR/DB for credit/debit) is controlled by SIGNS=.

Literals: Any character that is not I, T, or S is output as-is. Common literals are comma (thousands separator), period (decimal point), space, hyphen, or parentheses. So EDIT=(SII,III.IIT) has a leading S, then I’s and a comma, then I’s, period, then I and T’s—producing output like " 1,234.56" or "-1,234.56".

SIGNS=(lp, ln, tp, tn)

SIGNS= specifies the character to use for each sign position. The four values are: lp = leading positive, ln = leading negative, tp = trailing positive, tn = trailing negative. You can omit values you do not use; omitted positions often default to blank or product-specific behavior.

  • SIGNS=(,-) — Leading sign: blank for positive, minus for negative. Common for amounts.
  • SIGNS=(+,−) — Leading plus and minus.
  • SIGNS=(,,+,-) — Trailing sign: plus for positive, minus for negative.
  • SIGNS=(,(,,,) — Parentheses for negative (accounting style); positive can be blank or plus depending on product.

The number of S characters in the pattern must match how many sign positions you use (leading and/or trailing). Some predefined masks (e.g. M3) use CR (credit) and DB (debit) for the sign; those are built into the mask.

Predefined Masks M0 Through M26

IBM DFSORT provides 27 predefined edit masks, M0 through M26. Each has a fixed pattern and length. Using a mask name (e.g. M12) is equivalent to using the corresponding EDIT= pattern; it saves you from writing long patterns and ensures a standard layout.

Selected predefined masks (see product manual for full list)
MaskPurposeExample output
M0Leading zero suppression, trailing sign1234 or -1
M1All digits with trailing sign00123- or 00123+
M2Commas and decimal, trailing sign1,234.50 or 0.20-
M3Commas, decimal, CR/DB12.34CR or 1,234.56
M4Leading sign, commas, decimal+1,234.56 or -12,345.67
M11All digits, no suppression0001001234
M12Leading sign, comma thousands1,234,567 or -12,345
M18Leading sign, commas, decimal (no leading zero on first group)1,234.56 or -12,345.67

M0 uses leading zero suppression and a trailing sign; good for compact signed numbers. M1 shows all digits with trailing sign. M2 and M4 add commas and decimal point; M4 has a leading sign. M3 uses CR (credit) and DB (debit) for the sign. M11 is all T’s—no suppression, so leading zeros are kept (e.g. 0001001234). M12 is commonly used for report amounts: leading sign and comma-separated thousands. M18 is similar to M4 but with a slightly different pattern (e.g. no leading zero in the first group). Masks like M6, M7, M8, M9 are for date/time (hyphens, colons, slashes). Your DFSORT manual lists the exact pattern and output length for each mask.

Syntax in OUTREC and INREC

In OUTREC FIELDS= or BUILD= (and similarly in INREC), specify the numeric field with position, length, format, and either EDIT= or a mask:

text
1
OUTREC FIELDS=(1,10,3X,11,4,PD,EDIT=(SII,III.IIT),SIGNS=(,-))

Here 11,4,PD is the field at position 11, length 4, packed decimal. EDIT=(SII,III.IIT) formats it with leading sign, commas, and decimal; SIGNS=(,-) uses blank for positive and minus for negative. The edited field has a length equal to the number of characters in the pattern (including literals). You can use a predefined mask in place of EDIT=:

text
1
OUTREC FIELDS=(1,10,3X,11,4,PD,M12)

Some products support LENGTH=n on the edited field to pad or truncate the result to n bytes; check your manual.

Choosing INREC vs OUTREC for Edit Masks

Use INREC when the formatted value must participate in the sort or in INCLUDE/OMIT—for example, if you sort by the display value or filter on a string like "1,234". Use OUTREC when you want the sort to use the internal numeric value and only the final written record should show the formatted number. For most report jobs, editing in OUTREC is preferred: sort order stays numeric and the output is human-readable.

Example: Zoned Decimal with M11

Edit a 5-byte zoned decimal at position 11 with M11 (all digits, no suppression), and make the edited field 10 bytes (e.g. with LENGTH=10 if supported):

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

The first 10 bytes are copied; then the field at 11,5,ZD is edited with M11. The result shows all digits including leading zeros. LENGTH=10 is product-dependent; omit it if your DFSORT version does not support it—the length will then be the mask’s natural length.

Example: Packed Decimal with Custom EDIT=

Format a 4-byte packed decimal at position 15 with leading sign, comma, and two decimal places:

text
1
OUTREC FIELDS=(1,14,15,4,PD,EDIT=(SII,III.IIT),SIGNS=(,-))

The pattern (SII,III.IIT) is 12 characters, so the output record has 14 + 12 = 26 bytes for this portion. Ensure SORTOUT LRECL is at least the total length of all fields in FIELDS=.

Explain It Like I'm Five

Imagine you have a secret number written in code (like 0123456). Grown-ups want to see it on a sign with commas and a minus sign if it’s negative, like "-12,345". The edit mask is the rule that says: "Put a minus here if the number is negative, then show the digits with a comma every three, and use a blank instead of a zero at the start." So the computer follows the mask and turns the secret number into the pretty sign. I means "if this is a leading zero, show a blank;" T means "always show this digit;" and S is where the plus or minus goes.

Exercises

  1. Write an EDIT= pattern for a number with leading sign, two digits before the decimal, and two after (e.g. +12.34). Use I and T appropriately. Where would you put S?
  2. What is the difference between M11 and M12? When would you choose one over the other?
  3. If your pattern is EDIT=(II,III.IIT) with no S, how does the sign appear? What if the value is negative?
  4. For SIGNS=(,,+,-), where do the plus and minus appear—before or after the digits?

Quiz

Test Your Knowledge

1. What does the I character represent in an EDIT= pattern?

  • A literal character
  • A significant digit always shown as 0–9
  • A leading insignificant digit: 1–9 or blank for leading zero
  • The sign position

2. What is the difference between I and T in an edit mask?

  • They are the same
  • I suppresses leading zeros (blank); T always shows the digit 0–9
  • T is for sign
  • I is for trailing sign

3. Where does S go for a leading sign vs trailing sign?

  • S is always trailing
  • S before the digits = leading sign; S after the digits = trailing sign
  • S is always leading
  • S is only in predefined masks

4. What does the predefined mask M11 typically do?

  • Comma-separated thousands with sign
  • All digits shown with no suppression (leading zeros kept)
  • Date format
  • CR/DB for credit/debit

5. Which parameter controls the character used for positive and negative signs?

  • EDIT=
  • SIGNS=(leading_positive, leading_negative, trailing_positive, trailing_negative)
  • MASK=
  • FORMAT=