TExcelTAD
Home › COBOL › COBOL Edited Pictures

COBOL Edited Pictures

Numbers such as 0001234.50 are fine for calculation but ugly in a report. Edited pictures describe how a number should look when printed: leading zeros replaced, commas inserted, a currency sign and a credit marker added. You MOVE a numeric value into an edited item and COBOL formats it.

An edited item is for display only: you cannot do arithmetic with it (you can, however, MOVE it back to a numeric item in GnuCOBOL, which de-edits it).

Editing symbols

Symbol Effect
Z Digit; a leading zero becomes a space
* Digit; a leading zero becomes * (cheque protection)
9 Digit, always printed
. Actual decimal point printed (aligns like V)
, Comma, printed only if a digit appears to its left
$ Currency sign; several $ make it float next to the first digit
+ / - Sign; - prints only for negatives, + always prints + or -. Several of them float
CR / DB Printed after negative values (credit / debit), spaces otherwise
B 0 / Insert a space, a zero or a slash

Zero suppression

cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ZERO-SUPPRESS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-AMOUNT      PIC 9(5)V99 VALUE 1234.5.
       01  WS-SMALL       PIC 9(5)V99 VALUE 0.07.
       01  ED-ZZZ         PIC ZZZZ9.99.
       01  ED-ALLZ        PIC ZZZZZ.ZZ.
       01  ED-COMMA       PIC ZZ,ZZ9.99.
       01  ED-STARS       PIC **,**9.99.
       PROCEDURE DIVISION.
           MOVE WS-AMOUNT TO ED-ZZZ ED-COMMA ED-STARS
           DISPLAY "[" ED-ZZZ "] [" ED-COMMA "] [" ED-STARS "]"
           MOVE WS-SMALL TO ED-ZZZ ED-COMMA ED-STARS
           DISPLAY "[" ED-ZZZ "] [" ED-COMMA "] [" ED-STARS "]"
           MOVE ZERO TO ED-ALLZ
           DISPLAY "All-Z picture with zero: [" ED-ALLZ "]"
           STOP RUN.
[ 1234.50] [ 1,234.50] [*1,234.50]
[    0.07] [     0.07] [*****0.07]
All-Z picture with zero: [        ]

Notes on the output:

  • The comma is suppressed together with the leading zeros when no digit stands to its left.
  • ZZZZ9.99 always keeps one digit before the point, so 0.07 prints as 0.07.
  • When every position is Z and the value is zero, the whole field becomes spaces.
  • Cheque protection with * stops anyone from writing extra digits in front of the amount.

Currency and floating symbols

A single $ prints in a fixed position. A string of $ signs floats: the sign moves right to sit immediately before the first significant digit. The same works with + and -.

cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. CURRENCY.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-A           PIC 9(5)V99 VALUE 1234.5.
       01  WS-B           PIC 9(5)V99 VALUE 8.25.
       01  ED-FIXED       PIC $ZZ,ZZ9.99.
       01  ED-FLOAT       PIC $$,$9.99.
       PROCEDURE DIVISION.
           MOVE WS-A TO ED-FIXED ED-FLOAT
           DISPLAY "[" ED-FIXED "] [" ED-FLOAT "]"
           MOVE WS-B TO ED-FIXED ED-FLOAT
           DISPLAY "[" ED-FIXED "] [" ED-FLOAT "]"
           STOP RUN.
[$ 1,234.50] [ $1,234.50]
[$     8.25] [     $8.25]

Signs: -, +, CR and DB

Accounting reports show negative amounts in different ways. The source item must be signed (S9) or the sign is lost before formatting.

cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SIGNS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-POS         PIC S9(4)V99 VALUE 250.00.
       01  WS-NEG         PIC S9(4)V99 VALUE -75.40.
       01  ED-MINUS       PIC -,--9.99.
       01  ED-PLUS        PIC +,++9.99.
       01  ED-TRAIL       PIC Z,ZZ9.99-.
       01  ED-CR          PIC Z,ZZ9.99CR.
       01  ED-DB          PIC Z,ZZ9.99DB.
       PROCEDURE DIVISION.
           MOVE WS-POS TO ED-MINUS ED-PLUS ED-TRAIL ED-CR ED-DB
           DISPLAY "[" ED-MINUS "][" ED-PLUS "][" ED-TRAIL "]["
                   ED-CR "][" ED-DB "]"
           MOVE WS-NEG TO ED-MINUS ED-PLUS ED-TRAIL ED-CR ED-DB
           DISPLAY "[" ED-MINUS "][" ED-PLUS "][" ED-TRAIL "]["
                   ED-CR "][" ED-DB "]"
           STOP RUN.
[  250.00][ +250.00][  250.00 ][  250.00  ][  250.00  ]
[  -75.40][  -75.40][   75.40-][   75.40CR][   75.40DB]

Insertion characters: dates, codes and phone numbers

/, B (blank) and 0 insert characters into a value. They are useful for dates stored as YYYYMMDD numbers and for codes:

cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. INSERTION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-DATE        PIC 9(8)    VALUE 20260315.
       01  ED-DATE        PIC 9999/99/99.
       01  WS-SORT-CODE   PIC 9(6)    VALUE 401276.
       01  ED-SORT-CODE   PIC 99B99B99.
       01  WS-THOUSANDS   PIC 9(3)    VALUE 125.
       01  ED-THOUSANDS   PIC ZZ9000.
       PROCEDURE DIVISION.
           MOVE WS-DATE TO ED-DATE
           MOVE WS-SORT-CODE TO ED-SORT-CODE
           MOVE WS-THOUSANDS TO ED-THOUSANDS
           DISPLAY "Date:      " ED-DATE
           DISPLAY "Sort code: " ED-SORT-CODE
           DISPLAY "x1000:     " ED-THOUSANDS
           STOP RUN.
Date:      2026/03/15
Sort code: 40 12 76
x1000:     125000

BLANK WHEN ZERO

The BLANK WHEN ZERO clause prints an edited item as all spaces when its value is zero, which keeps reports with many empty columns readable:

cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. BLANK-ZERO.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  ED-QTY         PIC ZZ9.99 BLANK WHEN ZERO.
       PROCEDURE DIVISION.
           MOVE 3.5 TO ED-QTY
           DISPLAY "[" ED-QTY "]"
           MOVE 0 TO ED-QTY
           DISPLAY "[" ED-QTY "]"
           STOP RUN.
[  3.50]
[      ]

Tip: Size edited pictures for the largest value plus all symbols. PIC $$,$9.99 is 10 characters but holds at most 5 integer digits, because the first $ is reserved for the sign itself.

Test yourself

What does PIC ZZZ9 show for the value 7?

  1. 0007
  2. 7
  3. 7
  4. ***7

Which picture prints CR after negative amounts?

  1. PIC Z,ZZ9.99CR
  2. PIC CRZ,ZZ9.99
  3. PIC S9(4)V99CR
  4. PIC -Z,ZZ9.99

Why might a negative value print without a minus sign in an edited picture?

  1. Edited pictures never show signs
  2. The source item was unsigned (no S), so the sign was already lost
  3. Because of BLANK WHEN ZERO
  4. Minus signs need DECIMAL-POINT IS COMMA