COBOL PICTURE Clause – Quick Reference

The PICTURE (PIC) clause defines the format of a data item: its length, type (numeric, alphanumeric, alphabetic), decimal position, sign, and for edited fields how it appears when displayed. This page is a quick reference to the main PICTURE characters and how they affect storage and display.

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

A PICTURE is a recipe that says "this box holds this many digits" or "this many letters" or "digits with a decimal point here." The recipe uses symbols: 9 for a digit, X for any character, A for a letter, V for where the decimal point is, and so on. Some symbols (like Z or $) are for how the value looks when you print it (e.g. no leading zeros, or a dollar sign).

Basic PICTURE Characters

These characters define the type and size of the data. They correspond to actual storage (except V and P, which are positional).

Main PICTURE characters
CharMeaningExampleStorage
9One numeric digit (0–9).PIC 9(4) = four digits.One byte per digit (or USAGE COMP).
XAny character (alphanumeric).PIC X(20) = 20 characters.One byte per character.
AAlphabetic (A–Z, space only).PIC A(10) = 10 letters/spaces.One byte per character.
VAssumed decimal point (no storage).PIC 999V99 = 123.45 stored as 12345.No extra byte.
SSign (positive/negative).PIC S999 = signed 3-digit.Usually in leftmost digit unless SIGN SEPARATE.
PScaling (implied zeros).PIC 999PPP = thousands (123 = 123000).No extra bytes.

9 is used for numeric data that may be used in arithmetic. X is for any character and is the usual choice for names, codes, and IDs. A restricts to letters and space. V does not take a character position; it marks the assumed decimal location (e.g. 999V99 is five digits with the decimal between the third and fourth). S makes the field signed; the sign is typically encoded in the leftmost character. P indicates scaling: P to the right multiplies (999P = 3 digits × 10); P to the left divides (P999 = 1/1000 of 3 digits).

Repetition and Parentheses

You can repeat a character by writing it in parentheses: 9(5) means five 9s (same as 99999), X(20) means 20 Xs. So PIC 9(6) is a six-digit numeric field, and PIC X(30) is 30 characters of any type. Repetition applies to a single character; for mixed pictures you write them in sequence (e.g. PIC 9(4)V99 for four integer and two decimal places).

cobol
1
2
3
4
5
6
01 SAMPLE-FIELDS. 05 NUM-FIELD PIC 9(5). *> 5 digits 05 AMT-FIELD PIC 9(5)V99. *> 5 integer, 2 decimal (assumed) 05 NAME-FIELD PIC X(30). *> 30 characters 05 CODE-FIELD PIC A(5). *> 5 letters or spaces 05 SIGNED-NUM PIC S9(4). *> signed 4-digit

Editing Characters

Editing characters change how a value is displayed (or how it is moved into an edited field). They are used in receiving fields for output or for MOVE to a report field. They do not change the internal value in a numeric sending field; they define the layout of the edited result.

Common editing characters
CharMeaningExample
ZSuppress leading zeros (show space).PIC ZZZ9.
$Floating or fixed dollar sign.PIC $$$9.99 or $ZZZ9.99.
,Comma (inserted in output).PIC 9,999.99.
.Explicit decimal point in display.PIC 999.99.
-Minus sign or credit indicator.PIC ---9.99.
+Plus or minus in output.PIC +999.99.

Z suppresses leading zeros (replaced by space). $ can be fixed in one position or float so one $ appears left of the first digit. Comma and period insert punctuation. + and - show sign. The exact behavior (floating $, blank when zero, etc.) depends on the compiler. Use edited fields for display and report output; use numeric (9, V, S) fields for computation.

V vs P: Assumed Decimal and Scaling

V (assumed decimal point) fixes where the decimal point is. PIC 999V99 always has three digits before and two after the decimal; the value 12345 represents 123.45. P (scaling position) multiplies or divides by a power of 10. PIC 999PPP has three digit positions but the value is interpreted as multiplied by 1000 (123 stored means 123000). P does not add storage; it changes the magnitude. Use V for normal decimal numbers; use P when you need a fixed-point scale (e.g. thousands) without storing the trailing zeros.

USAGE and PICTURE

USAGE (e.g. DISPLAY, COMP, COMP-3) affects how the value is stored in memory (character, binary, packed decimal). PICTURE still defines the logical size and type. For example PIC S9(5)V99 COMP-3 is a packed decimal signed number with five integer and two decimal places. The number of bytes used depends on USAGE, not on the number of 9s in the same way as DISPLAY. When you use COMP or COMP-3, the PICTURE describes the numeric range and decimal position; storage is determined by the implementation.

Step-by-Step: Choosing a PICTURE

  1. Decide the maximum length and whether the field is numeric, alphabetic, or alphanumeric.
  2. For numeric: use 9(n) for integers, 9(n)V9(m) for decimals, and S if the value can be negative.
  3. For text: use X(n) for general text, A(n) if only letters and space are allowed.
  4. For display (reports): use an edited picture with Z, $, comma, period, or sign as needed.

Best Practices

Test Your Knowledge

Test Your Knowledge

1. Which PICTURE character is used for a field that can contain letters and digits?

  • 9
  • A
  • X
  • V

2. In PIC 999V99, what does V represent?

  • A character position
  • The assumed decimal point
  • A sign
  • Alphabetic

3. PIC ZZZ9 is typically used for:

  • Storing numbers
  • Displaying numbers with leading zeros suppressed
  • Alphabetic data
  • Signed numbers