COBOL Picture Clauses

The PICTURE (or PIC) clause is how you define the format and type of a data item in COBOL. It controls the length, whether the item is numeric or alphanumeric, where the decimal point is, whether it is signed, and for display fields how it looks (e.g. with commas, currency, or leading zeros suppressed). This page explains the main PICTURE symbols, the difference between storage and editing, and how to choose the right picture for your data.

Explain Like I'm Five: What Is a PICTURE?

A PICTURE is a short recipe that tells the computer what kind of data a box can hold and how big it is. "Nine" means a digit; "ex" means any letter or number; "vee" means where the dot goes in a number (like 12.34). So the picture is the shape of the data: how many characters, whether it's a number or text, and for numbers where the decimal point is. When you print the box, you can add a recipe for commas and dollar signs so it looks nice—that's the "editing" part of the picture.

Why PICTURE Matters

PICTURE determines how much storage the item uses, how the compiler interprets moves and arithmetic, and how the value is validated. A field with PIC 9(5) can only hold digits and can be used in ADD and COMPUTE. A field with PIC X(10) can hold any characters but is not used in arithmetic. A field with PIC 999V99 has an implied decimal point so that 12345 is treated as 123.45. Edited pictures (with Z, $, comma, etc.) are for display: they control how a number is shown (e.g. with leading spaces instead of zeros) but the field is not used in calculations. Getting the picture right avoids truncation, wrong decimal alignment, and invalid data.

Numeric Symbols: 9, S, V, P

Numeric data is defined with 9 for each digit position. You can write 9 repeated (9999) or use 9(4) for four nines. S makes the field signed so it can hold negative values; the sign is usually stored in the leftmost character (overpunched or in the high-order bit depending on USAGE). SIGN SEPARATE adds a leading character for the sign so the digit positions are unsigned. V is the assumed decimal point: it does not take a character position. So PIC 999V99 defines five digit positions with the decimal point between the third and fourth; the value 12345 represents 123.45. P is a scaling position: it represents a power of 10 and does not occupy storage. PIC 999PPP means three digit positions plus three implied zeros—so 123 represents 123000. P is often used for fixed-point scaling (e.g. interest rates stored as integers with implied decimals).

Numeric PICTURE symbols
SymbolMeaningStorageExample
9One numeric digit (0–9).One character position (or packed/binary per USAGE).PIC 9(4) = four-digit integer.
SSigned numeric. Value can be positive or negative.Sign in leftmost position (or SIGN SEPARATE adds one).PIC S9(5) = signed five-digit.
VAssumed decimal point. No storage; defines decimal position.None.PIC 999V99 = 3 integer, 2 decimal (e.g. 123.45).
PScaling position. Implied zeros (power of 10).None.PIC 999PPP = 123 means 123000.
cobol
1
2
3
4
01 WS-AMOUNT PIC 9(5)V99. *> 5 integer, 2 decimal 01 WS-QUANTITY PIC S9(4). *> Signed 4-digit 01 WS-RATE PIC 99V9999. *> 2 integer, 4 decimal (e.g. 0.1234) 01 WS-THOUSANDS PIC 999PPP. *> 123 stored = 123000

V and P do not add bytes. The number of bytes for a numeric field depends on the number of digit positions (9s) and the USAGE (DISPLAY, COMP, COMP-3, etc.). COMP and COMP-3 pack digits; DISPLAY uses one byte per character position (typically).

Alphanumeric and Alphabetic: X and A

X means any character: letters, digits, spaces, and symbols. PIC X(20) is a 20-character field suitable for names, codes, addresses, or any mixed text. A means alphabetic only: A–Z and space. Use A when the data must be letters only (e.g. a category code that is only letters). N is used in some compilers for national (DBCS or Unicode) characters. For most COBOL, X is the workhorse for text; A is for when you need to enforce or document alphabetic-only content. Both X and A use one byte per character in DISPLAY usage.

Alphanumeric/alphabetic symbols
SymbolMeaningStorageExample
XAny character (letter, digit, symbol, space).One byte per character.PIC X(30) = 30-character text.
AAlphabetic only (A–Z, space).One byte per character.PIC A(20) = 20 letters/spaces.
NNational (Unicode/DBCS in some compilers).Implementation-dependent.PIC N(10) = national (wide) characters.

Editing Characters

Editing characters change how a value is displayed; they do not change the stored value when used as input. They appear in the PICTURE of an edited (display) field. Z replaces leading zeros with spaces: PIC ZZZ9 displays 1 as " 1" and 0 as " 0". $ is the currency symbol; it can be fixed in one position (PIC $999.99) or floating (PIC $$$9.99) so the dollar sign appears next to the first significant digit. The comma (,) inserts commas in numeric output (e.g. 1,234,567). The period (.) is the explicit decimal point in the display. Minus (-) or CR (credit) and plus (+) show the sign. Once you use editing characters, the field is an edited numeric field: you use it for display (or move a numeric value into it for formatting), not in arithmetic. You move from a numeric field (PIC 9, S9, V, P) to an edited field for output.

Common editing characters
SymbolMeaningTypical use
ZLeading zeros replaced by spaces in display.Reports: PIC ZZZ9 shows 1 not 0001.
$Currency symbol. Fixed ($ in one position) or floating.PIC $999.99 or $$$9.99.
,Comma inserted in display.PIC 9,999,999.99 for thousands.
.Explicit decimal point in display.PIC 999.99.
-Minus or credit (CR) for negative.PIC ---9.99 or 999.99CR.
+Plus or minus sign in output.PIC +999.99.
cobol
1
2
3
4
5
6
01 WS-NUM PIC 9(5)V99. 01 WS-OUT PIC $$$,$$9.99. ... MOVE 12345.67 TO WS-NUM MOVE WS-NUM TO WS-OUT *> WS-OUT displays as $12,345.67 (floating $, comma, decimal)

V Versus P

V and P are both "invisible" in storage. V fixes the decimal point: 999V99 always has two decimal places. P represents scaling: 999PPP means the value is in thousands. So for V you think "digits to the right of the decimal"; for P you think "multiply by 10^n." When you MOVE or do arithmetic, the compiler aligns on the decimal point (V) or applies scaling (P). Choosing V is standard for amounts and rates; P is used when the application stores values in scaled form (e.g. integers representing basis points or thousands).

USAGE and PICTURE

USAGE (DISPLAY, COMP, COMP-3, BINARY, etc.) determines how the value is stored in memory. PICTURE still defines the logical size and decimal position. So you can have PIC S9(5)V99 COMP: five integer and two decimal places stored in binary form. The number of bytes for COMP depends on the compiler (e.g. 4 bytes for 5+2 digits). PIC S9(5)V99 COMP-3 might use 4 bytes (packed decimal). DISPLAY usage stores one byte per character position (for 9, X, A). So PICTURE and USAGE together define both the logical value and the physical representation.

Step-by-Step: Choosing a PICTURE for a Numeric Field

  1. Decide the maximum number of digits before and after the decimal (e.g. 7 integer, 2 decimal).
  2. Use 9 for each digit: PIC 9(7)V99. Add S if the value can be negative: PIC S9(7)V99.
  3. Choose USAGE: DISPLAY for screen/file I/O in character form, COMP or COMP-3 for arithmetic and storage efficiency.
  4. If the value is displayed, define a separate edited field (e.g. PIC Z(6)9.99 or $$$,$$9.99) and MOVE the numeric field to it before display.

Step-by-Step: Defining an Edited Output Field

  1. Define the source numeric field (e.g. PIC 9(5)V99 or S9(5)V99).
  2. Define the output field with editing: e.g. PIC Z(4)Z9.99 for leading zero suppression and two decimals, or PIC $ZZ,ZZ9.99 for currency with comma.
  3. In the procedure, MOVE the numeric field TO the edited field. The compiler converts and formats.
  4. Use the edited field only for display or report output; do not use it in ADD, SUBTRACT, or COMPUTE.

Best Practices

Test Your Knowledge

Test Your Knowledge

1. PIC 9(3)V99 defines a field that stores:

  • Three digits only
  • Five digits with decimal between positions 3 and 4
  • Two decimal places only
  • Alphanumeric

2. An edited PICTURE with Z and $ is used for:

  • Arithmetic
  • Display only (e.g. reports)
  • Binary storage
  • File keys

3. P (scaling position) in a PICTURE:

  • Adds storage
  • Represents implied zeros (no storage)
  • Is the decimal point
  • Is required for signed