COBOL by Example: Editing Masks
Formatting numeric output with PIC editing characters for presentation, using Z for zero suppression to replace leading zeros with spaces, implementing check protection with asterisk fill, displaying signs with plus and minus, and separating data storage from display formatting.
Code
IDENTIFICATION DIVISION.
PROGRAM-ID. MASKS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RAW-NUM PIC 9(5)V99 VALUE 01234.50.
01 MASK-Z PIC ZZZZZ.99.
01 MASK-STAR PIC *****.99.
01 MASK-PLUS PIC +++++.99.
PROCEDURE DIVISION.
MOVE RAW-NUM TO MASK-Z.
DISPLAY "Zero Suppress: " MASK-Z.
MOVE RAW-NUM TO MASK-STAR.
DISPLAY "Check Protect: " MASK-STAR.
MOVE -123.45 TO MASK-PLUS.
DISPLAY "Signed: " MASK-PLUS.
STOP RUN.Explanation
Editing masks are used to present data in a human-readable format. They are defined in the PIC clause of the destination variable. When you move a numeric value into an edited field, COBOL automatically formats it according to the mask.
Common editing characters include Z for zero suppression (replacing leading zeros with spaces), * for check protection (filling leading zeros with asterisks), and + or - for sign control. You can also insert static characters like commas, decimals, and currency symbols.
This feature is heavily used in report generation and UI display. It separates the raw data storage (which should be pure numeric) from its presentation, allowing for easy localization and formatting changes without altering the underlying logic.
Z: Zero suppression. Replaces leading zeros with spaces.*: Check protection. Replaces leading zeros with asterisks.+/-: Sign control. Displays a plus or minus sign.

