The PICTURE clause (often abbreviated as PIC) is one of the most fundamental elements in COBOL data definition. It defines the format and size of a data item, specifying its data type, length, and how it should be displayed or interpreted.
12345605 EMPLOYEE-ID PIC 9(5). 05 EMPLOYEE-NAME PIC X(30). 05 HOURLY-RATE PIC 9(3)V99. 05 HIRE-DATE PIC 9(8). 05 DEPARTMENT-CODE PIC AA9. 05 TAX-AMOUNT PIC $Z,ZZ9.99.
These examples show various PICTURE clause formats used to define different types of data.
The PICTURE clause serves several important purposes:
The PICTURE clause consists of the keyword PIC or PICTURE followed by a character string that defines the data characteristics. The character string can contain:
Note: The PICTURE clause only applies to elementary items, not group items. A group item inherits its characteristics from its constituent elementary items.
Numeric PICTURE specifications are used to define fields that contain numeric data and can be used in arithmetic operations. Several special characters are used to define various aspects of numeric data.
123456705 WHOLE-NUMBER PIC 9(5). *> 5-digit whole number 05 DECIMAL-NUMBER PIC 9(3)V99. *> 3 digits before and 2 after decimal 05 SIGNED-NUMBER PIC S9(7). *> 7-digit signed number 05 NEGATIVE-NUMBER PIC S9(5)V99. *> Signed with 2 decimal places 05 SCALED-NUMBER PIC 9(5)P(2). *> Multiplied by 100 05 P-SCALED-NUMBER PIC P(2)9(5). *> Divided by 100 05 LARGE-AMOUNT PIC 9(10)V99. *> 10 digits with 2 decimal places
These examples show different numeric PICTURE clauses using various numeric symbols.
Key numeric PICTURE symbols:
Behavior of numeric fields:
Alphanumeric PICTURE specifications define fields that can contain letters, digits, and special characters. These fields are used for text data that isn't used in arithmetic operations.
123456705 CUSTOMER-NAME PIC X(30). *> Any 30 characters 05 PRODUCT-CODE PIC X(10). *> 10-character code 05 ADDRESS-LINE PIC X(50). *> 50-character address 05 LAST-NAME PIC A(20). *> 20 alphabetic characters 05 STATE-CODE PIC AA. *> 2-letter state code 05 ALPHANUMERIC-CODE PIC AAA99. *> 3 letters followed by 2 digits 05 MIXED-CODE PIC A(3)X(5). *> 3 letters followed by 5 any chars
These examples show different alphanumeric PICTURE clauses for text and code data.
Key alphanumeric PICTURE symbols:
Important: When '9' is used in a field with 'A' or 'X', it loses its numeric properties—the field becomes alphanumeric and cannot be used in arithmetic operations. For example, PIC A9 defines a 2-character alphanumeric field where the first position must be alphabetic and the second must be a digit.
Behavior of alphanumeric fields:
Editing characters allow you to format numeric data for display or reporting. They define how numbers will appear when used in output operations, controlling aspects like leading zero suppression, insertion of separators, and currency symbols.
123456705 AMOUNT-Z PIC Z,ZZ9.99. *> Leading zero suppression 05 AMOUNT-DOLLAR PIC $,$$9.99. *> Currency symbol 05 PHONE-NUMBER PIC 999B999B9999. *> Space insertion 05 DASH-NUMBER PIC 999-999-9999. *> Dash insertion 05 CR-DR-AMOUNT PIC 9(6).99CR. *> Credit notation 05 PLUS-MINUS-AMT PIC +9(6).99. *> Explicit sign 05 STARRED-CHECK-AMT PIC $**,***,**9.99. *> Check protection
These examples show different editing characters used for formatted display of numeric data.
Common editing characters:
Note: Fields with editing characters are treated as alphanumeric fields and cannot be used in arithmetic operations. They are typically used for displaying results rather than for computation.
Key points about edited numeric fields:
Let's see some practical examples of how PICTURE clauses are used in real COBOL programs for different scenarios.
1234567891011121314151617181920212201 EMPLOYEE-RECORD. 05 EMP-ID PIC 9(5). 05 EMP-NAME. 10 LAST-NAME PIC X(20). 10 FIRST-NAME PIC X(15). 10 MIDDLE-INIT PIC X. 05 EMP-ADDRESS. 10 STREET PIC X(30). 10 CITY PIC X(20). 10 STATE PIC XX. 10 ZIP-CODE PIC 9(5)X(4). 05 EMP-DOB. 10 DOB-YEAR PIC 9(4). 10 DOB-MONTH PIC 99. 10 DOB-DAY PIC 99. 05 EMP-HIRE-DATE PIC 9(8). 05 EMP-SALARY PIC 9(7)V99. 05 EMP-DEPARTMENT PIC 9(3). 05 EMP-STATUS PIC X. 88 EMP-ACTIVE VALUE 'A'. 88 EMP-TERMINATED VALUE 'T'. 88 EMP-LEAVE VALUE 'L'.
This example shows various PICTURE clauses used in an employee record structure.
123456789101101 FINANCIAL-REPORT-LINE. 05 FILLER PIC X(5) VALUE SPACES. 05 ACCOUNT-NUMBER-OUT PIC X(10). 05 FILLER PIC X(2) VALUE SPACES. 05 ACCOUNT-NAME-OUT PIC X(20). 05 FILLER PIC X(2) VALUE SPACES. 05 PREVIOUS-BALANCE-OUT PIC $$$,$$$,$$9.99-. 05 FILLER PIC X(2) VALUE SPACES. 05 CURRENT-BALANCE-OUT PIC $$$,$$$,$$9.99-. 05 FILLER PIC X(2) VALUE SPACES. 05 PERCENT-CHANGE-OUT PIC ---9.99%.
This example shows how PICTURE clauses with editing characters are used in a report line.
1234567891011121314151617181920212201 CUSTOMER-INPUT-RECORD. 05 CUST-ID-IN PIC X(8). 05 CUST-NAME-IN PIC X(30). 05 CUST-PHONE-IN PIC X(12). 05 CUST-BALANCE-IN PIC X(10). 01 VALIDATED-CUSTOMER-DATA. 05 CUST-ID PIC X(8). 05 CUST-NAME PIC X(30). 05 CUST-PHONE. 10 AREA-CODE PIC 9(3). 10 PHONE-PREFIX PIC 9(3). 10 PHONE-SUFFIX PIC 9(4). 05 CUST-BALANCE PIC S9(8)V99. 01 ERROR-FLAGS. 05 ID-ERROR-FLAG PIC X VALUE 'N'. 88 ID-ERROR VALUE 'Y'. 05 PHONE-ERROR-FLAG PIC X VALUE 'N'. 88 PHONE-ERROR VALUE 'Y'. 05 BALANCE-ERROR-FLAG PIC X VALUE 'N'. 88 BALANCE-ERROR VALUE 'Y'.
This example shows how PICTURE clauses are used in data validation scenarios.
Best practices for using PICTURE clauses:
Define PICTURE clauses for a customer record
Create appropriate PICTURE clauses for a customer record that includes customer ID, name, address, phone number, email, account balance, and credit limit.
Design a financial report line
Create a report line structure with appropriate edited numeric fields to display account numbers, descriptions, and monetary values with proper formatting.
Work with decimal point alignment
Write a program that demonstrates decimal point alignment when moving values between numeric fields with different PICTURE clauses (different numbers of decimal positions).
Experiment with editing characters
Create a series of PICTURE clauses using different editing characters to format the same numeric value (e.g., 12345.67) in various ways.
Use the P symbol for scaling
Demonstrate the use of the P symbol for scaling by creating fields that automatically multiply or divide values by powers of 10.
1. Which PICTURE symbol is used for decimal point alignment in numeric fields?
2. What does PIC X(10) specify?
3. Which PICTURE character is used to represent a sign position in a numeric field?
4. What does the editing character Z do in a PICTURE clause?
5. Which PICTURE specification would correctly define a field for a monetary amount like $1,234.56?
Understanding the various data types available in COBOL
How COBOL allocates memory for different data structures
Techniques for formatting data in COBOL programs
Creating formatted reports in COBOL
How COBOL handles numeric calculations