PICTURE clause
The PIC that says what kind of data a field holds and how long it is.
Also written PIC, picture
Why it matters. Every amount, name and date in a COBOL program has a picture. It decides how the field is stored, and how it prints.
See it
X means any character. 20 means 20 positions.
Syntax
level name PIC picture [USAGE usage] [VALUE literal].
- 9
- A digit.
- X
- Any character.
- A
- A letter or space.
- S
- A sign. The number can be negative.
- V
- An implied decimal point. It takes no space.
- Z
- A digit, with a leading zero shown as a space.
- , and .
- Printed comma and decimal point, in edited fields.
- 9(5)
- A count in brackets repeats the symbol.
Try it PIC
- 1
In the program EDIT, WS-BAL holds 1200.50 for calculation. Declare WS-OUT, the field that prints it: up to 5 digits with a comma, and 2 decimals. Blank out leading zeros.
COBOL 01 WS-OUT PIC ZZ,ZZ9.99. - 2
Run EDIT.
RUNCOBOL 'ZB0001.DEV.COBOL(EDIT)'
Remember
- 9 is a digit. X is any character. S makes a number signed. V is a decimal point you cannot see, and it takes no space.
- Z hides leading zeros. Use it for printing, not for calculating.
- PIC 9(5)V99 holds 7 digits. 2 of them come after the point.
The usual mistake
PIC 9(5).99 for a field you add to
A point you can see makes the field an edited field. It is for printing. COBOL will not use it in a sum.
PIC 9(5)V99 to calculate, then MOVE it to an edited field to print
On real z/OS
MF/OS prints the standard edit patterns correctly. Its output uses ASCII-style characters where real z/OS uses EBCDIC.
Where can I practise PICTURE clause?
Right here, at ZedBank. You take a junior job at a simulated bank and use PICTURE clause in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- DATA DIVISIONThe part of a COBOL program that declares every record layout and variable it will use.
- WORKING-STORAGEThe section of a COBOL program that declares its internal variables: counters, totals, flags and work areas.
- Packed decimalA compact way of storing numbers, two digits per byte, used heavily for amounts in business records.
- Level numberThe two-digit number in front of a COBOL data item that shows how fields nest inside a record.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.