Chapter 3: Key Takeaways -- Data Types, Variables, and the PICTURE Clause

Chapter Summary

Chapter 3 introduces COBOL's unique data description system, centered on the PICTURE clause -- a compact, character-by-character specification language that defines the type, size, format, and display characteristics of every data item. Unlike modern languages that use simple type keywords (int, string, float), COBOL requires programmers to describe data at a granular level. A declaration like PIC S9(7)V99 COMP-3 encodes that a field is signed, has seven integer digits and two decimal places, and is stored in packed-decimal format -- all in a single clause. This approach gives programmers explicit control over data representation, which is essential in business systems where financial precision, fixed-length records, and formatted reports are paramount.

The chapter covers three fundamental data classes: alphabetic (PIC A), alphanumeric (PIC X), and numeric (PIC 9). Numeric fields introduce the V symbol for implied decimal points, the S symbol for signs, and the P symbol for decimal scaling. The USAGE clause controls how data is physically stored in memory: DISPLAY (one byte per character, the default), COMP/BINARY (pure binary integers), COMP-3/PACKED-DECIMAL (two digits per byte, the standard for financial data), and COMP-1/COMP-2 (floating point, never for money). Understanding the interplay between PICTURE and USAGE is critical for writing correct, efficient COBOL programs.

The chapter also covers numeric editing pictures for formatted output (Z for zero suppression, $ for currency, comma and period insertion, CR/DB for accounting notation), figurative constants (ZEROS, SPACES, HIGH-VALUES, LOW-VALUES), the VALUE clause for initialization, condition names (88-level), REDEFINES for alternative storage views, the JUSTIFIED clause, BLANK WHEN ZERO, and the differences between EBCDIC and ASCII character encoding. Together, these features make COBOL's DATA DIVISION one of the most expressive data-description systems ever created.

Key Concepts

  • The PICTURE clause (PIC) defines data character by character: 9 for numeric digits, X for any character, A for alphabetic characters only.
  • V marks the implied decimal point in numeric fields. It does not occupy storage -- it tells the compiler where to align decimals during arithmetic.
  • S indicates a signed numeric field that can hold positive or negative values. It must appear as the leftmost character in the PIC string. Without S, a field silently loses negative signs.
  • Elementary items have a PIC clause and hold actual data. Group items have no PIC clause and serve as containers for subordinate items.
  • Level numbers define the data hierarchy: 01 (record level, Area A), 02-49 (subordinates, Area B), 66 (RENAMES), 77 (independent items, Area A), 88 (condition names).
  • The convention of using levels 01/05/10/15 (increments of 5) leaves room to insert new hierarchy levels without renumbering existing code.
  • USAGE DISPLAY stores one byte per digit/character (default). USAGE COMP stores binary integers (2, 4, or 8 bytes). USAGE COMP-3 stores packed decimal (two digits per byte plus sign nibble).
  • COMP-3 is the preferred USAGE for financial data: exact decimal representation, compact storage, and hardware-accelerated arithmetic on IBM mainframes.
  • COMP-1 and COMP-2 are floating-point types that must never be used for financial calculations because binary floating point cannot exactly represent many decimal fractions.
  • Edited PICTURE clauses (Z, *, $, comma, period, +, -, CR, DB, B, 0, /) format numeric data for human-readable output. Edited fields cannot participate in arithmetic.
  • Figurative constants (ZEROS, SPACES, HIGH-VALUES, LOW-VALUES, QUOTES, ALL) automatically expand to fill the receiving field's size.
  • The VALUE clause initializes data items at program load time. On group items, VALUE treats the entire group as a single alphanumeric literal.
  • Level 88 condition names associate meaningful names with specific values, enabling self-documenting code like IF ACCOUNT-IS-ACTIVE instead of IF WS-STATUS = "A".
  • REDEFINES allows two or more data descriptions to share the same storage, useful for date field parsing, multi-format records, and table initialization.
  • The SIGN clause controls where and how the sign is stored: TRAILING (default), LEADING, or SEPARATE CHARACTER.

Common Pitfalls

  • Forgetting the S for sign. Subtracting a larger number from a smaller one and storing in an unsigned field silently loses the negative sign, producing an incorrect positive value.
  • Confusing V (implied decimal) with period (actual decimal point). PIC 9(5)V99 is a numeric field for arithmetic. PIC 9(5).99 is a numeric-edited field for display only -- you cannot perform arithmetic on it.
  • Insufficient field size causing silent truncation. If a multiplication result exceeds the receiving field's integer digits, the high-order digits are silently dropped. A PIC 9(3)V99 field storing 1599.00 becomes 599.00.
  • Performing arithmetic on edited fields. Edited fields (those with Z, $, commas, etc.) are for output only. Attempting arithmetic on them causes a compile error.
  • Assuming PIC X fields have null terminators. COBOL does not use null-terminated strings. A PIC X(10) field is always exactly 10 bytes, padded with spaces. There is no trailing null.
  • Mixing USAGE types in arithmetic without considering conversion overhead. When operands have different USAGEs, the compiler generates implicit conversion code. For performance, use the same USAGE for all operands in a single arithmetic statement.
  • Using two-digit years in date fields. Always use PIC 9(4) for year fields. Two-digit years were a central cause of the Y2K crisis.
  • Applying VALUE to a group item and expecting subordinate VALUE clauses to work. A VALUE on a group item overrides all subordinate VALUE clauses. Choose one approach or the other.

Quick Reference

Data Classes:
  PIC A(n)        Alphabetic (letters and spaces only)
  PIC X(n)        Alphanumeric (any character)
  PIC 9(n)        Numeric (digits 0-9)

Numeric Modifiers:
  S               Sign (must be leftmost): PIC S9(5)V99
  V               Implied decimal point:   PIC 9(5)V99
  P               Decimal scaling:         PIC 9(3)P(4)

USAGE Clause:
  DISPLAY         1 byte per digit (default)
  COMP / BINARY   2, 4, or 8 bytes (binary integer)
  COMP-3          Packed decimal: bytes = (digits + 1) / 2
  COMP-1          4-byte single-precision float (no PIC)
  COMP-2          8-byte double-precision float (no PIC)

Common Editing Pictures:
  PIC ZZZ,ZZ9.99           Zero-suppressed with commas
  PIC $$$,$$$,$$9.99        Floating dollar sign
  PIC **,***,**9.99         Check protection (asterisks)
  PIC -(6)9.99              Floating minus sign
  PIC 99/99/9999            Date with slashes

Figurative Constants:
  ZEROS / ZEROES / ZERO     Numeric zero or "0" characters
  SPACES / SPACE            Space characters
  HIGH-VALUES / HIGH-VALUE  X"FF" (highest character)
  LOW-VALUES / LOW-VALUE    X"00" (null character)
  ALL "literal"             Repeated literal

Condition Names (88-Level):
  01  WS-STATUS  PIC X.
      88  ACTIVE   VALUE "A".
      88  CLOSED   VALUE "C".
      88  VALID    VALUE "A" "C".
  SET ACTIVE TO TRUE.       Moves "A" to WS-STATUS
  IF ACTIVE ...             Tests WS-STATUS = "A"

REDEFINES:
  01  WS-DATE-NUM  PIC 9(8).
  01  WS-DATE-PARTS REDEFINES WS-DATE-NUM.
      05  WS-YEAR  PIC 9(4).
      05  WS-MONTH PIC 9(2).
      05  WS-DAY   PIC 9(2).

What's Next

Chapter 4 explores the WORKING-STORAGE and LOCAL-STORAGE sections in depth -- the practical home for all the data definitions learned in this chapter. You will learn professional conventions for organizing WORKING-STORAGE (constants, flags, counters, accumulators, work fields, display fields), the INITIALIZE statement for safely resetting mixed-type records, advanced REDEFINES patterns like table initialization and multi-format records, and the critical difference between WORKING-STORAGE (values persist between calls) and LOCAL-STORAGE (values reinitialize on each call).