24 min read

> "Data is the center of the COBOL universe. Where other languages define variables with type keywords, COBOL describes data with a miniature formatting language embedded right inside the variable declaration."

Chapter 3: Data Types, Variables, and the PICTURE Clause

"Data is the center of the COBOL universe. Where other languages define variables with type keywords, COBOL describes data with a miniature formatting language embedded right inside the variable declaration."


3.1 Introduction: COBOL's Unique Approach to Data

Every programming language must answer a fundamental question: how do you describe the shape of your data? Most modern languages answer with type keywords -- int, float, string, boolean. You declare a variable, assign it a type, and the compiler takes care of the rest. COBOL answers this question in a radically different way, one that has no true parallel in any other mainstream language.

In COBOL, you do not simply say "this is an integer" or "this is a string." Instead, you describe your data character by character using the PICTURE clause (often written as PIC), a compact data-description language that specifies not just the type of data, but its exact size, format, and display characteristics. Consider this declaration:

       01  WS-SALARY             PIC S9(7)V99 COMP-3.

This single line tells the compiler that WS-SALARY is a signed numeric field with seven integer digits and two decimal places, stored internally in packed-decimal format. Compare that to a Java declaration like BigDecimal salary -- the COBOL version encodes far more information in the declaration itself.

This approach was not accidental. COBOL was designed in 1959 for business data processing, where the precise representation of financial amounts, dates, identifiers, and formatted reports was paramount. The PICTURE clause gave business programmers a way to define data layouts that mapped directly to punched cards, printed reports, and fixed-length file records. More than six decades later, this design remains one of COBOL's greatest strengths -- and one of the first things that surprises programmers coming from other languages.

In this chapter, we will explore every facet of COBOL's data definition system: the PICTURE clause and all its symbols, the hierarchical level-number system, the USAGE clause for controlling internal representation, figurative constants, condition names, and the many supporting clauses that make COBOL's DATA DIVISION one of the most expressive data-description systems ever created.


3.2 Elementary Items and Group Items

COBOL organizes data into a hierarchy using level numbers. Every data item in the DATA DIVISION has a level number that determines its position in the hierarchy.

3.2.1 Elementary Items

An elementary item is a data item that is not further subdivided. It must have a PICTURE clause (with a few exceptions we will cover later). Elementary items are the leaves of the data hierarchy -- they actually hold data.

       01  WS-CUSTOMER-NAME       PIC X(30).
       01  WS-ACCOUNT-BALANCE     PIC S9(9)V99.
       01  WS-STATUS-CODE         PIC X(1).

3.2.2 Group Items

A group item is a data item that contains subordinate items. It does not have a PICTURE clause. When you reference a group item as a whole, COBOL treats it as an alphanumeric field whose size is the sum of all its subordinate elementary items.

       01  WS-CUSTOMER-RECORD.
           05  WS-CUST-ID         PIC 9(8).
           05  WS-CUST-NAME       PIC X(30).
           05  WS-CUST-BALANCE    PIC S9(9)V99.

Here, WS-CUSTOMER-RECORD is a group item (level 01, no PIC clause). Its subordinate items are at level 05. The total size of the group is 8 + 30 + 11 = 49 bytes (in DISPLAY usage).

3.2.3 Level Numbers 01 Through 49

Level numbers from 01 to 49 define the hierarchy of group and elementary items. The rules are straightforward:

  • Level 01 always begins a new record. It must start in Area A (columns 8-11 in fixed format).
  • Levels 02 through 49 define subordinate items. A higher level number indicates a deeper nesting within the hierarchy.
  • Level numbers need not be consecutive. The common convention is to use increments of 5 (01, 05, 10, 15, 20) so that new levels can be inserted later without renumbering.
       01  WS-EMPLOYEE-RECORD.
           05  WS-EMP-ID          PIC 9(6).
           05  WS-EMP-NAME.
               10  WS-EMP-FIRST   PIC X(15).
               10  WS-EMP-MIDDLE  PIC X(1).
               10  WS-EMP-LAST    PIC X(20).
           05  WS-EMP-ADDRESS.
               10  WS-EMP-STREET  PIC X(30).
               10  WS-EMP-CITY    PIC X(20).
               10  WS-EMP-STATE   PIC X(2).
               10  WS-EMP-ZIP     PIC 9(5).

In this example, WS-EMP-NAME and WS-EMP-ADDRESS are group items at level 05 that contain elementary items at level 10. You can reference any level in the hierarchy: WS-EMPLOYEE-RECORD gives you the entire record, WS-EMP-NAME gives you just the 36-byte name portion, and WS-EMP-FIRST gives you the 15-byte first name.

3.2.4 FILLER

The reserved word FILLER (or simply an unnamed item in COBOL-85 and later) declares a data item that occupies space but cannot be individually referenced. It is commonly used for padding, formatting report lines, or reserving space for future expansion.

       01  WS-REPORT-LINE.
           05  FILLER             PIC X(5)  VALUE SPACES.
           05  WS-RPT-NAME        PIC X(20).
           05  FILLER             PIC X(3)  VALUE SPACES.
           05  WS-RPT-AMOUNT      PIC $$$,$$9.99.
           05  FILLER             PIC X(5)  VALUE SPACES.

3.3 The Three Data Classes

COBOL classifies data items into three fundamental classes based on the characters used in their PICTURE clauses.

3.3.1 Alphabetic (PIC A)

PIC A defines a field that can contain only letters (A through Z, uppercase and lowercase) and spaces. Each A in the picture represents one character position.

       01  WS-FIRST-NAME          PIC A(15).
       01  WS-CITY                PIC A(20).

Alphabetic fields are rarely used in modern COBOL because PIC X (alphanumeric) is more flexible and covers the same use cases. However, PIC A provides implicit data validation -- the compiler may warn or the runtime may reject non-alphabetic data moved to a PIC A field.

3.3.2 Alphanumeric (PIC X)

PIC X defines a field that can contain any character in the character set -- letters, digits, special characters, and spaces. It is the most commonly used data class for non-numeric data.

       01  WS-CUSTOMER-NAME       PIC X(30).
       01  WS-ADDRESS-LINE        PIC X(50).
       01  WS-PHONE-NUMBER        PIC X(12).
       01  WS-PART-CODE           PIC X(10).

Alphanumeric fields are left-justified and padded with trailing spaces when a shorter value is moved in. When a longer value is moved in, it is truncated on the right.

3.3.3 Numeric (PIC 9)

PIC 9 defines a field that can contain digits 0 through 9. Numeric fields can be used in arithmetic operations, which is the crucial distinction from alphanumeric fields.

       01  WS-QUANTITY            PIC 9(5).
       01  WS-UNIT-PRICE          PIC 9(5)V99.
       01  WS-BALANCE             PIC S9(9)V99.

Numeric fields have several additional PICTURE symbols available (S, V, P) that we will explore in the next section.

Summary of Data Classes:

Symbol Class Valid Content Common Use
A Alphabetic Letters (A-Z, a-z) and spaces Names (rarely used)
X Alphanumeric Any character General text, identifiers
9 Numeric Digits 0-9 Amounts, counts, codes

3.4 The PICTURE Clause Character by Character

The PICTURE clause is the heart of COBOL's data definition system. Let us examine every PICTURE symbol in detail.

3.4.1 The 9 Symbol (Numeric Digit)

Each 9 represents one decimal digit position (0-9). This is the fundamental numeric PICTURE character.

       01  WS-COUNT              PIC 9.           *> 1 digit: 0-9
       01  WS-YEAR               PIC 9(4).        *> 4 digits: 0000-9999
       01  WS-AMOUNT             PIC 9(7).        *> 7 digits: 0000000-9999999

3.4.2 The X Symbol (Alphanumeric Character)

Each X represents one character position that can hold any character.

       01  WS-CODE               PIC X.           *> 1 character
       01  WS-NAME               PIC X(30).       *> 30 characters

3.4.3 The A Symbol (Alphabetic Character)

Each A represents one character position that can hold only letters and spaces.

       01  WS-INITIAL            PIC A.           *> 1 letter/space
       01  WS-SURNAME            PIC A(25).       *> 25 letters/spaces

3.4.4 The V Symbol (Implied Decimal Point)

V marks the position of an assumed (implied) decimal point within a numeric field. It does not occupy any storage -- it is a conceptual marker that tells the compiler where to align decimal positions during arithmetic.

       01  WS-PRICE              PIC 9(5)V99.
      *    Storage: 7 bytes (NOT 8 -- V takes no space)
      *    Value 12345.67 is stored as: 1234567
      *    The compiler knows the decimal is between position 5 and 6

The V is essential for financial arithmetic. Without it, the compiler would treat PIC 9(7) as a whole number and could not properly align decimal places in ADD, SUBTRACT, MULTIPLY, and DIVIDE operations.

Important: Only one V is allowed per PICTURE clause. It can appear anywhere within the numeric portion of the picture.

       01  WS-RATE               PIC V9(4).       *> .0000 to .9999
       01  WS-DOLLARS             PIC 9(7)V99.    *> 0000000.00 to 9999999.99
       01  WS-PRECISE            PIC 9(3)V9(6).   *> 000.000000 to 999.999999

3.4.5 The S Symbol (Sign)

S indicates that the numeric field can hold a positive or negative value. Without S, a field is unsigned and can hold only zero and positive values.

       01  WS-BALANCE            PIC S9(9)V99.    *> -999999999.99 to +999999999.99
       01  WS-TEMPERATURE        PIC S9(3).       *> -999 to +999

Critical Rule: The S must appear as the leftmost character in the PICTURE string. You cannot write PIC 9(5)S -- it must be PIC S9(5).

Warning about sign loss: If you perform arithmetic that produces a negative result and store it in an unsigned field (without S), the sign is silently lost. The absolute value is stored. This is one of the most common bugs in COBOL programs.

      * DANGEROUS: sign loss
       01  WS-UNSIGNED           PIC 9(5).
       SUBTRACT 100 FROM 50 GIVING WS-UNSIGNED
      * WS-UNSIGNED now contains 00050, not -00050!
      * The negative sign is lost because there is no S.

Best practice: Always use PIC S9 for any field that might hold a negative value, especially intermediate arithmetic results.

3.4.6 The P Symbol (Decimal Scaling Position)

P represents a decimal digit position that is not stored but is assumed to be zero. It is used to represent very large or very small numbers without storing all the zeros.

       01  WS-MILLIONS           PIC 9(3)P(4).
      *    Value 123 represents 1,230,000
      *    Storage: 3 bytes (only the significant digits)
      *    The four P's represent four assumed trailing zeros

       01  WS-TINY               PIC P(3)9(2).
      *    Value 45 represents 0.00045
      *    Storage: 2 bytes
      *    The three P's represent three assumed leading decimal zeros

The P symbol is rarely used in new code but appears in legacy programs. Understanding it is important for maintenance work.

3.4.7 Repetition Notation

The parenthetical repetition notation (n) is a shorthand for repeating a PICTURE character. These are equivalent:

Longhand Shorthand
PIC 99999 PIC 9(5)
PIC XXXXXXXXXX PIC X(10)
PIC AAA PIC A(3)
PIC S99999V99 PIC S9(5)V9(2) or PIC S9(5)V99

The shorthand notation is almost universally preferred because it is more readable, especially for large fields. PIC X(80) is far clearer than eighty consecutive X's.

You can mix notations: PIC 9(5)V99 uses repetition for the integer part and longhand for the decimal part. Both forms are acceptable.


3.5 Signed Numbers: The SIGN Clause

The default behavior for signed numeric fields is to embed the sign in the zone bits of a digit. On EBCDIC systems, the zone of the trailing digit is overwritten: C for positive, D for negative. On ASCII systems, similar encoding occurs but with different bit patterns.

The SIGN clause gives you explicit control over where and how the sign is stored.

3.5.1 SIGN IS TRAILING (Default)

       01  WS-AMT                PIC S9(5) SIGN IS TRAILING.
      *    Sign is embedded in the last digit. Storage: 5 bytes.
      *    This is the default behavior.

3.5.2 SIGN IS LEADING

       01  WS-AMT                PIC S9(5) SIGN IS LEADING.
      *    Sign is embedded in the first digit. Storage: 5 bytes.

3.5.3 SIGN IS TRAILING SEPARATE CHARACTER

       01  WS-AMT                PIC S9(5)
                                 SIGN IS TRAILING SEPARATE CHARACTER.
      *    Sign is stored as a separate + or - byte AFTER the digits.
      *    Storage: 6 bytes (5 digits + 1 sign byte).

3.5.4 SIGN IS LEADING SEPARATE CHARACTER

       01  WS-AMT                PIC S9(5)
                                 SIGN IS LEADING SEPARATE CHARACTER.
      *    Sign is stored as a separate + or - byte BEFORE the digits.
      *    Storage: 6 bytes (1 sign byte + 5 digits).

The SEPARATE CHARACTER option increases storage by one byte but makes the sign human-readable in dumps and data files. It is sometimes required when interfacing with external systems that expect an explicit sign character.

Storage Summary for PIC S9(5):

SIGN Clause Storage Sign Location
TRAILING (default) 5 bytes Embedded in last digit's zone
LEADING 5 bytes Embedded in first digit's zone
TRAILING SEPARATE 6 bytes Separate + or - after digits
LEADING SEPARATE 6 bytes Separate + or - before digits

3.6 The USAGE Clause

While the PICTURE clause defines the logical representation of data (how many digits, where the decimal goes, etc.), the USAGE clause defines the physical representation -- how the data is actually stored in memory.

3.6.1 USAGE DISPLAY (Default)

If you do not specify a USAGE clause, the default is DISPLAY. Each digit or character occupies one byte, using the character encoding of the platform (EBCDIC on mainframes, ASCII on PCs and Unix).

       01  WS-AMOUNT             PIC 9(7)V99.
      *    Equivalent to: PIC 9(7)V99 USAGE DISPLAY.
      *    Storage: 9 bytes (one byte per digit position)
      *    Value 1234567.89 stored as characters: "123456789"

DISPLAY usage is human-readable in memory dumps and file listings. It is the default for fields that will be written to reports or flat files.

3.6.2 USAGE BINARY (COMP)

Binary usage stores numeric values as pure binary integers. The storage size depends on the number of digits in the PICTURE clause:

PIC Digits Storage Type Maximum Value
1-4 2 bytes Halfword 9,999
5-9 4 bytes Fullword 999,999,999
10-18 8 bytes Doubleword 18 digits
       01  WS-COUNT              PIC S9(4) COMP.
      *    Storage: 2 bytes (halfword)
      *    Range: -9999 to +9999

       01  WS-TOTAL              PIC S9(9) COMP.
      *    Storage: 4 bytes (fullword)
      *    Range: -999,999,999 to +999,999,999

       01  WS-BIG-NUM            PIC S9(18) COMP.
      *    Storage: 8 bytes (doubleword)

BINARY and COMP are synonymous in most COBOL compilers. Binary is efficient for counters, subscripts, and loop control variables because the hardware can perform binary arithmetic directly.

Important: When a BINARY/COMP field has an implied decimal (V), the decimal position is still tracked by the compiler, but the value is stored as a scaled integer. For example, PIC S9(5)V99 COMP stores the value 12345.67 as the binary integer 1234567 in a fullword, and the compiler adjusts for the two decimal places during arithmetic.

3.6.3 USAGE PACKED-DECIMAL (COMP-3)

Packed-decimal storage encodes two decimal digits per byte using Binary-Coded Decimal (BCD). The rightmost half-byte (nibble) stores the sign: C for positive, D for negative, F for unsigned.

Storage formula: bytes = (number of digits + 1) / 2, rounded up.

PIC S9(5) COMP-3:
  Value: +12345
  Storage: 3 bytes
  Hex:  01 23 4C
        ^^ ^^ ^^
        |  |  |+-- C = positive sign
        |  |  +--- digit 4 and 5
        |  +------ digit 2 and 3
        +--------- digit 0 (leading zero) and digit 1

PIC S9(5) COMP-3:
  Value: -12345
  Hex:  01 23 4D   (D = negative sign)

PIC S9(7)V99 COMP-3:
  Value: 1234567.89
  Storage: 5 bytes  (9 digits + 1 sign = 10 nibbles = 5 bytes)
  Hex:  01 23 45 67 8C

Packed-decimal storage size reference:

PICTURE Total Digits Nibbles (digits + sign) Bytes
S9(3) 3 4 2
S9(5) 5 6 3
S9(7) 7 8 4
S9(7)V99 9 10 5
S9(9)V99 11 12 6
S9(13)V99 15 16 8
S9(15) 15 16 8
S9(17)V99 19 20 10

COMP-3 is the preferred usage for financial data in COBOL programs. It offers several advantages:

  1. Exact decimal arithmetic. Unlike floating-point, packed-decimal never introduces rounding errors for decimal values. The value 0.10 is stored exactly as 01 0C, not as an approximation.
  2. Compact storage. COMP-3 uses roughly half the storage of DISPLAY for numeric fields.
  3. Hardware support. IBM mainframes have dedicated hardware instructions for packed-decimal arithmetic, making COMP-3 operations very efficient on those platforms.
  4. No conversion needed for arithmetic. When all operands in an arithmetic statement are COMP-3, no conversion overhead is incurred.

3.6.4 USAGE COMP-1 (Single-Precision Floating Point)

COMP-1 stores data in single-precision floating-point format (4 bytes). It provides approximately 7 significant digits. No PICTURE clause is allowed with COMP-1.

       01  WS-FLOAT-VAL          COMP-1 VALUE 3.14159.
      *    Storage: 4 bytes (IEEE 754 single precision)

3.6.5 USAGE COMP-2 (Double-Precision Floating Point)

COMP-2 stores data in double-precision floating-point format (8 bytes). It provides approximately 15-16 significant digits. No PICTURE clause is allowed with COMP-2.

       01  WS-DOUBLE-VAL         COMP-2 VALUE 3.14159265358979.
      *    Storage: 8 bytes (IEEE 754 double precision)

Warning: Floating-point types (COMP-1 and COMP-2) should never be used for financial calculations. Binary floating point cannot exactly represent many decimal fractions (like 0.1), leading to rounding errors that accumulate over many operations. Always use COMP-3 (packed decimal) for money.

3.6.6 USAGE COMP-5 (Native Binary)

COMP-5 is similar to COMP/BINARY but allows the stored value to exceed the range implied by the PICTURE clause. The PIC determines the storage size (2, 4, or 8 bytes), but the maximum value is the full range of that binary size.

       01  WS-NATIVE-VAL         PIC S9(4) COMP-5.
      *    Storage: 2 bytes
      *    PIC S9(4) implies max 9999, but COMP-5 allows
      *    the full halfword range: -32768 to +32767

COMP-5 is primarily used for interfacing with non-COBOL programs (C, assembler) where native binary values may exceed the COBOL PIC range.

3.6.7 USAGE INDEX

INDEX usage defines an item used for table indexing. It typically occupies 4 bytes and contains a byte displacement rather than an occurrence number. INDEX items are covered in detail in the chapter on tables and arrays.

       01  WS-INDEX-ITEM         USAGE INDEX.

3.6.8 Storage Size Comparison

Here is a comprehensive comparison of storage for the same logical value across different USAGEs:

Value: 12345 (5 digits)

USAGE      PIC        Storage   Hex Representation
--------   --------   -------   ------------------
DISPLAY    9(5)       5 bytes   F1 F2 F3 F4 F5  (EBCDIC)
                                31 32 33 34 35  (ASCII)
BINARY     9(5)       4 bytes   00 00 30 39
COMP-3     9(5)       3 bytes   01 23 4F

Value: -12345.67 (signed, 5 integer + 2 decimal digits)

USAGE      PIC           Storage   Notes
--------   -----------   -------   -----
DISPLAY    S9(5)V99      7 bytes   1 byte per digit, sign in zone
BINARY     S9(5)V99      4 bytes   Fullword (scaled integer)
COMP-3     S9(5)V99      4 bytes   (7 digits + sign = 8 nibbles)

3.7 Numeric Editing Pictures

Numeric editing PICTURE characters are used to format numeric data for display or printing. When you move a numeric value to an edited field, COBOL automatically inserts commas, decimal points, dollar signs, and other formatting characters.

Critical rule: Edited fields are for output only. You cannot perform arithmetic on them. The standard pattern is to keep your working data in numeric fields (PIC 9 with appropriate USAGE) and MOVE to edited fields only for display.

3.7.1 Zero Suppression (Z)

Z replaces leading zeros with spaces. Once a significant (non-zero) digit is encountered, the remaining digits display normally.

       01  WS-EDITED             PIC Z(6)9.99.
      *    Value 1234.56  displays as: "   1234.56"
      *    Value    0.50  displays as: "      0.50"
      *    Value    0.00  displays as: "      0.00"

If all digit positions use Z (including after the decimal point), a zero value produces an all-spaces result:

       01  WS-ALL-Z              PIC Z(6).ZZ.
      *    Value 0.00 displays as: "         " (all spaces)

3.7.2 Check Protection (*)

* (asterisk) replaces leading zeros with asterisks. It works exactly like Z but uses * instead of spaces. This is used on checks (cheques) to prevent amount alteration.

       01  WS-CHECK-AMT          PIC **,***,**9.99.
      *    Value 1234.56 displays as: "***1,234.56"
      *    Value    0.50 displays as: "********0.50"

3.7.3 Currency Sign ($)

The dollar sign can be used in two ways:

Fixed dollar sign: A single $ at the beginning of the picture. It always appears in the same position regardless of the value.

       01  WS-FIXED-DOLLAR       PIC $Z(5)9.99.
      *    Value 1234.56 displays as: "$  1234.56"
      *    Value    0.50 displays as: "$     0.50"
      *    The $ is always at the left edge.

Floating dollar sign: Multiple $` symbols that act like `Z` but place the `$ immediately before the first significant digit.

       01  WS-FLOAT-DOLLAR       PIC $$$,$$$,MATH2,MATH3$,$$9.99.
       ADD 100 TO WS-DISPLAY-AMT.    *> COMPILE ERROR!
      *    Edited fields cannot participate in arithmetic.
      *    Keep a separate numeric field for calculations.
```

### 3.19.7 Assuming PIC X Fields Have a Null Terminator

COBOL does not use null-terminated strings. A PIC X(10) field is always exactly 10 bytes, padded with spaces. There is no null terminator. This is a common mistake for programmers coming from C or Java.

---

## 3.20 Storage Layout Diagrams

Understanding how data is physically stored helps with debugging and file design. Here are text-based storage layout diagrams for common scenarios.

### 3.20.1 Group Item Layout

```
WS-EMPLOYEE-RECORD (112 bytes total)
+--------+---------------+--+--------------------+
| EMP-ID | EMP-FIRST     |MI| EMP-LAST           |
| 9(6)   | X(15)         |X | X(20)              |
| 6 bytes| 15 bytes      |1 | 20 bytes           |
+--------+---------------+--+--------------------+
|  Offset 0   |   Offset 6        |  Offset 22    |
                    (WS-EMP-NAME: 36 bytes)

+------------------------------+--------------------+--+-----+
| EMP-STREET                   | EMP-CITY           |ST| ZIP |
| X(30)                        | X(20)              |X2| 9(5)|
| 30 bytes                     | 20 bytes           |2 | 5   |
+------------------------------+--------------------+--+-----+
|  Offset 42                            (WS-EMP-ADDRESS: 57 bytes)

+-----------+----+
| SALARY    |DEPT|
| S9(7)V99  |X(4)|
| 9 bytes   |4 b |
+-----------+----+
|Offset 99  |108 |
```

### 3.20.2 COMP-3 Storage Layout

```
PIC S9(5) COMP-3, Value = +12345
  Byte 0    Byte 1    Byte 2
 +--------+--------+--------+
 | 0 | 1  | 2 | 3  | 4 | C  |
 +--------+--------+--------+
  nibble    nibble    nibble
  0   1     2   3     4  sign
                      (C=positive)

PIC S9(7)V99 COMP-3, Value = -1234567.89
  Byte 0    Byte 1    Byte 2    Byte 3    Byte 4
 +--------+--------+--------+--------+--------+
 | 0 | 1  | 2 | 3  | 4 | 5  | 6 | 7  | 8 | D  |
 +--------+--------+--------+--------+--------+
  The V (implied decimal) is between positions 7 and 8
  but does not appear in storage. D = negative.
```

### 3.20.3 COMP/BINARY Storage Layout

```
PIC S9(4) COMP, Value = 1234
  Byte 0    Byte 1
 +--------+--------+
 | 04     | D2     |    (0x04D2 = 1234 decimal)
 +--------+--------+
  Halfword (2 bytes), big-endian

PIC S9(7) COMP, Value = 1234567
  Byte 0    Byte 1    Byte 2    Byte 3
 +--------+--------+--------+--------+
 | 00     | 12     | D6     | 87     |  (0x0012D687)
 +--------+--------+--------+--------+
  Fullword (4 bytes), big-endian
```

---

## 3.21 Fixed-Format and Free-Format Examples

Throughout this chapter, all examples have used **fixed format** (the traditional COBOL format with column-sensitive layout). Here is a summary of how data definitions look in both formats.

### 3.21.1 Fixed Format (Traditional)

In fixed format, code must adhere to specific column positions:
- Columns 1-6: Sequence number area (optional)
- Column 7: Indicator area (* for comments, - for continuation)
- Columns 8-11: Area A (level numbers 01, 77, 66 must begin here)
- Columns 12-72: Area B (all other code)
- Columns 73-80: Identification area (optional)

```cobol
       01  WS-CUSTOMER-RECORD.
           05  WS-CUST-ID        PIC 9(8).
           05  WS-CUST-NAME      PIC X(30).
           05  WS-CUST-BALANCE   PIC S9(9)V99 COMP-3.
```

### 3.21.2 Free Format (Modern)

Free format removes column restrictions. Level numbers, names, and clauses can appear anywhere on the line. Comments use `*>` instead of `*` in column 7.

```cobol
01 WS-CUSTOMER-RECORD.
   05 WS-CUST-ID      PIC 9(8).
   05 WS-CUST-NAME    PIC X(30).
   05 WS-CUST-BALANCE PIC S9(9)V99 COMP-3.
*> This is a free-format comment
```

Free format is supported by GnuCOBOL (with `-free` flag), Micro Focus, and most modern COBOL compilers. The code examples in this textbook use fixed format because it remains the dominant format in production mainframe COBOL code.

---

## 3.22 Putting It All Together: A Complete DATA DIVISION Example

Here is a comprehensive DATA DIVISION that demonstrates many of the concepts covered in this chapter:

```cobol
       DATA DIVISION.
       WORKING-STORAGE SECTION.

      *--- Independent items ---
       77  WS-LINE-COUNT         PIC 9(3)       VALUE ZERO.
       77  WS-PAGE-NUMBER        PIC 9(4)       VALUE 1.

      *--- Processing flags ---
       01  WS-EOF-FLAG           PIC X(1)       VALUE "N".
           88  END-OF-FILE       VALUE "Y".
           88  NOT-END-OF-FILE   VALUE "N".

      *--- Customer record structure ---
       01  WS-CUSTOMER-RECORD.
           05  WS-CUST-ID        PIC 9(8).
           05  WS-CUST-NAME.
               10  WS-CUST-LAST  PIC X(25).
               10  WS-CUST-FIRST PIC X(20).
               10  WS-CUST-MI    PIC X(1).
           05  WS-CUST-BALANCE   PIC S9(9)V99   COMP-3.
           05  WS-CUST-STATUS    PIC X(1).
               88  CUST-ACTIVE   VALUE "A".
               88  CUST-CLOSED   VALUE "C".
               88  CUST-VALID    VALUE "A" "C".
           05  WS-CUST-OPEN-DATE.
               10  WS-OPEN-YYYY  PIC 9(4).
               10  WS-OPEN-MM    PIC 9(2).
               10  WS-OPEN-DD    PIC 9(2).
           66  WS-CUST-FULL-NAME RENAMES WS-CUST-LAST
                                 THRU WS-CUST-MI.

      *--- Report output line ---
       01  WS-REPORT-LINE.
           05  FILLER            PIC X(3)       VALUE SPACES.
           05  WS-RPT-ID         PIC 9(8).
           05  FILLER            PIC X(2)       VALUE SPACES.
           05  WS-RPT-NAME       PIC X(25).
           05  FILLER            PIC X(2)       VALUE SPACES.
           05  WS-RPT-BALANCE    PIC -$$$,$$$,$$9.99.
           05  FILLER            PIC X(2)       VALUE SPACES.
           05  WS-RPT-STATUS     PIC X(6).
           05  FILLER            PIC X(2)       VALUE SPACES.
           05  WS-RPT-DATE       PIC 99/99/9999.

      *--- Accumulators ---
       01  WS-TOTALS.
           05  WS-TOTAL-BALANCE  PIC S9(13)V99  COMP-3
                                 VALUE ZERO.
           05  WS-RECORD-COUNT   PIC S9(7)      COMP
                                 VALUE ZERO.

This example demonstrates level numbers (01, 05, 10, 66, 77), all three data classes (9, X, A by implication), signed and unsigned numeric fields, implied decimal points, COMP-3 and COMP usage, condition names (88 levels), RENAMES (66), FILLER, VALUE clauses, figurative constants, and edited output fields. It represents the kind of DATA DIVISION you will find in real production COBOL programs.


3.23 Chapter Summary

COBOL's data definition system, centered on the PICTURE clause, is unlike anything in modern programming languages. It provides a character-by-character specification language for data that encodes type, size, format, and display characteristics in a single compact clause. The hierarchical level-number system organizes data into records and subfields, while the USAGE clause controls how data is physically represented in memory. Together with figurative constants, condition names, REDEFINES, and the many supporting clauses, COBOL's DATA DIVISION provides one of the most thorough and expressive data-description systems ever created -- a design that has served the world's most critical financial and business systems for over sixty years.


Proceed to the Exercises to practice writing PICTURE clauses, or explore the Case Studies to see these concepts applied to real-world banking system design.