Data Types & PICTURE Clauses
COBOL Fundamentals
Chapter 3 · Data Types & PICTURE Clauses
Chapter 2's own 01 WS-GREETING PIC X(20) VALUE "HELLO, COBOL". line already used three real pieces this chapter covers properly: a level number, a PICTURE clause, and a VALUE clause. Chapter 1 also already traced the PICTURE clause's own real origin to COMTRAN — this chapter shows exactly what it can express, and one real, easy-to-miss detail about how COBOL actually stores the numbers behind it.
Level Numbers: Building Hierarchical Records
COBOL data items are organized hierarchically using real, numbered levels — an item with a higher level number is subordinate to an item with a lower one.
| Level | Real Meaning |
|---|---|
| 01 | Begins a record definition — the top of a hierarchy |
| 05, 10, 15… | Nested subordinate items underneath an 01 (or another subordinate level) |
| 77 | A standalone field with no subordinate items at all |
| 88 | A condition name — a real, named shortcut for testing whether another field holds a specific value, covered fully in Chapter 5 |
The Real PICTURE Clause Symbols
| Symbol | Real Meaning |
|---|---|
| 9 | A decimal digit (0–9) |
| X | Any character — alphanumeric |
| A | Alphabetic characters only (letters or spaces) |
| V | The implied decimal point's location — not actually stored |
| S | Marks the item as signed (positive or negative) |
A count like 9(5) means "five real occurrences of 9" — five digits — the same shorthand Chapter 2's own X(20) already used for twenty characters.
A Real, Easy-to-Miss Detail: The Implied Decimal Point
Take PIC 9(5)V9(2) — a real, valid field with 5 digits before the decimal and 2 after, 7 digits total. Storing the value 12345.67 in it does not store a decimal point character anywhere.
1234567 — seven raw digits, no decimal point. The V only tells COBOL where the decimal point belongs when the value is interpreted or displayed; it never occupies real, physical storage space of its own.
USAGE Clauses: How Data Is Actually Stored
A field's USAGE clause controls its real, physical storage format — separate from what its PICTURE clause describes.
| Usage | Real Storage Format | Why It's Used |
|---|---|---|
| DISPLAY (default) | One byte per character/digit, human-readable | Simple, but real, genuinely wasteful for large numeric fields |
| COMP / COMPUTATIONAL | Often equivalent to native binary storage | Real, faster arithmetic and more compact storage |
| COMP-3 / PACKED-DECIMAL | Packed binary-coded decimal — two digits per byte | Real mainframe storage efficiency, still extremely common in legacy business data |
On real mainframes, where storage space directly affected cost, COMP-3 in particular became genuinely standard for business numeric fields — expect to see it constantly once Chapter 8 starts reading real file records.
Putting It Together
One 01-level record, three real subordinate 05-level fields: a plain numeric ID, a text name, and a signed, two-decimal-place balance stored efficiently as packed decimal — a real, small-scale preview of exactly the kind of record layout Chapter 8's own file-handling material builds on directly.
Hands-On Exercises
Using this chapter's own real material, explain in your own words what the raw stored digits would be for the value 4210.5 in a field defined as PIC 9(5)V9(1), and why a decimal point never appears among those stored digits.
A colleague says, "COMP-3 and PIC are basically the same kind of thing — they both describe a field's data type." Using this chapter's own real material, explain in your own words why this isn't accurate.
📄 View solutionUsing this chapter's own real worked WS-CUSTOMER-RECORD example, explain in your own words the real hierarchical relationship between the 01-level item and each of the three 05-level items beneath it.
📄 View solutionChapter 3 Quick Reference
- Level numbers: 01 (record) → 05/10/15… (subordinate) · 77 (standalone) · 88 (condition name, Chapter 5)
- PICTURE symbols: 9 (digit) · X (any character) · A (alphabetic) · V (implied decimal, not stored) · S (signed)
- Real gotcha:
PIC 9(5)V9(2)holding 12345.67 stores just1234567— no decimal point character, ever - USAGE: DISPLAY (default, human-readable) · COMP/COMPUTATIONAL (binary) · COMP-3/PACKED-DECIMAL (packed BCD, real mainframe storage efficiency)