Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 38 ยท Divisions and Data Description

PICTURE Clauses: 9, X, A, V, S and P

Master the COBOL PIC clause: numeric 9, alphanumeric X, alphabetic A, implied decimal V, sign S, scaling P, repeat counts, sizes and what MOVE does to over-long values.

The PICTURE (or PIC) clause describes what one elementary item may contain and how many characters it takes. Where other languages say int or string, COBOL draws a picture of the data: 9(5) for five digits, X(20) for twenty characters. This is the most important clause in the data division. Get it right and arithmetic, comparisons and file layouts follow.

The basic symbols

Symbol Meaning Example
9 One decimal digit PIC 9(4) holds 0000 to 9999
X Any character (alphanumeric) PIC X(10) holds up to 10 characters
A Letter or space only PIC A(15) for alphabetic names
V Implied decimal point (takes no storage) PIC 9(3)V99 stores 12345 meaning 123.45
S Sign (takes no storage by default) PIC S9(5) may be negative
P Scaling position (assumed zero) PIC 9(3)PP stores 123 meaning 12300

A repeat count in parentheses is shorthand: 9(5) equals 99999 and X(20) equals twenty X symbols.

Numeric items

COBOL
       01 QUANTITY     PIC 9(3).
       01 PRICE        PIC 9(4)V99.
       01 BALANCE      PIC S9(7)V99.
       01 PERCENT      PIC V99.
  • QUANTITY holds integers 0 to 999.
  • PRICE stores six digits and the decimal point is implied: the stored digits 001999 mean 19.99. No dot is stored, which is why DISPLAY PRICE prints 001999.
  • BALANCE is signed. A signed USAGE DISPLAY item stores its sign inside the last digit (an "overpunch") unless you say SIGN IS SEPARATE.
  • PERCENT is V99: only decimals, such as .08.

A numeric item holds only digits (and a sign). It can be used in arithmetic. Numeric edited pictures such as ZZ9.99 add a real decimal point, commas and blanks for printing and cannot be used as arithmetic sources; see MOVE and edited pictures.

The maximum is 18 digits in COBOL-85 (31 on IBM and in GnuCOBOL, 38 in COBOL 2002).

Alphanumeric and alphabetic

COBOL
       01 CITY         PIC X(20).
       01 INITIALS     PIC A(3).
       01 PRODUCT-CODE PIC X(8).

X accepts letters, digits, punctuation and spaces: anything. Use it for names, codes, addresses and for identifiers made of digits that you never calculate with (phone numbers, postal codes, account numbers). A accepts only letters and spaces, and is seldom used in practice because real names contain hyphens and apostrophes.

Size on disk versus size in memory

For USAGE DISPLAY (the default) each position is one byte. PIC S9(7)V99 is 9 bytes: S and V do not count. The size matters for records and files, because record layouts must match exactly byte for byte. Other usages (see usage and value) pack numbers into fewer bytes.

What MOVE does when values do not fit

When you MOVE a value to a field, COBOL aligns and truncates by type, and silently:

  • Numeric: aligned on the decimal point. Extra high-order (left) digits are lost; extra low-order (right) decimals are dropped (truncated, not rounded).
  • Alphanumeric: left-justified. Too long: right side cut off. Too short: padded with spaces on the right.
COBOL
       01 BIG    PIC 9(5)V99 VALUE 12345.67.
       01 SMALL  PIC 9(3)V9.
           MOVE BIG TO SMALL

SMALL becomes 345.6, because the leftmost digits (12) vanish and the final 7 is dropped.

Python MOVE alignment and truncation (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Sizes at a glance (Python stand-in)

Python Picture size calculator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Choosing the right picture

  • Will you do arithmetic with it? Use 9, with V for decimals and S if it can go negative.
  • Is it an identifier made of digits (ZIP code, phone, account number)? Use X, so leading zeros survive and nobody tries to add it.
  • Make it large enough for the biggest value you will ever store; undersized fields silently overflow.
  • Money: S9(n)V99, never a floating-point usage.

Common mistakes

  • Expecting DISPLAY of a V field to show a decimal point. It does not; use an edited picture.
  • Mixing X and 9 in one picture to do arithmetic (it becomes alphanumeric).
  • Too few digits: PIC 99 cannot hold 100.
  • Forgetting S and then wondering why a subtraction result loses its minus sign.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How many bytes does PIC S9(5)V99 take with the default USAGE DISPLAY?

    Seven digit positions. S and V take no storage by default.
  2. 2. A field PIC 9(3)V9 receives the value 12345.67 by MOVE. What does it hold?

    The two high-order integer digits are lost and the extra decimal is truncated (not rounded), leaving 345.6.
  3. 3. Which picture is best for a postal code such as 02134?

    You never calculate with a postal code and PIC X keeps leading zeros. Numeric fields are for arithmetic.
  4. 4. What does the V in PIC 9(3)V99 do?

    V is an implied decimal point. The digits are stored without any point.

Summary

  • 9 digit, X any character, A letter, V implied point, S sign, P scaling; (n) repeats.
  • V and S take no storage by default, so size = number of 9, X, A positions.
  • MOVE aligns numbers on the decimal point and truncates silently; text is left-justified and padded or cut on the right.
  • Use X for identifiers, 9 for values used in arithmetic.

Next: USAGE and VALUE: DISPLAY, COMP and COMP-3