DISPLAY is the default USAGE in COBOL when no explicit USAGE is specified. It stores data in a human-readable character format, with each character or digit occupying one byte of storage.
12345678910111201 EMPLOYEE-RECORD. 05 EMPLOYEE-ID PIC 9(5) USAGE DISPLAY. 05 EMPLOYEE-NAME PIC X(30) USAGE DISPLAY. 05 DEPARTMENT-CODE PIC 99 USAGE IS DISPLAY. 05 SALARY PIC 9(7)V99 USAGE DISPLAY. *> Since DISPLAY is the default, these are equivalent to the above: 01 EMPLOYEE-RECORD-EQUIV. 05 EMPLOYEE-ID PIC 9(5). 05 EMPLOYEE-NAME PIC X(30). 05 DEPARTMENT-CODE PIC 99. 05 SALARY PIC 9(7)V99.
These examples show explicit and implicit DISPLAY usage for different data types.
Key characteristics of DISPLAY usage:
Note: For numeric fields with DISPLAY usage, sign information (for PIC S9...) is typically stored as an "overpunch" character in the rightmost digit position. This means that the last digit and the sign are combined into a single character, which can be confusing when examining raw data.
COMPUTATIONAL (or COMP for short) usage types store numeric data in binary format, which is more efficient for arithmetic operations. COBOL provides several variants of the COMPUTATIONAL usage with different characteristics.
123456701 CALCULATION-FIELDS. 05 TOTAL-AMOUNT PIC 9(9)V99 USAGE COMPUTATIONAL. 05 COUNTER PIC 9(5) USAGE COMP. 05 RATE-PERCENT PIC 9(3)V9(2) USAGE IS COMP. 05 FLOAT-VALUE PIC 9(5)V9(2) USAGE COMP-1. 05 DOUBLE-VALUE PIC 9(10)V9(5) USAGE COMP-2. 05 SMALL-INTEGER PIC S9(4) USAGE COMP-5.
These examples show different COMPUTATIONAL usage variants for numeric data.
Common COMPUTATIONAL variants:
Important: The exact implementation of COMP variants can vary between COBOL compilers. Always check your compiler's documentation for specific details about size, alignment, and behavior.
Basic COMP (or COMP-4) allocates binary storage based on the number of digits in the PICTURE clause:
Advantages of COMPUTATIONAL usage:
Disadvantages of COMPUTATIONAL usage:
PACKED-DECIMAL (often equivalent to COMP-3) is a hybrid storage format that balances storage efficiency and computational performance. It's especially popular on mainframe systems with hardware support for packed decimal operations.
1234501 FINANCE-FIELDS. 05 ACCOUNT-BALANCE PIC S9(13)V99 USAGE PACKED-DECIMAL. 05 TRANSACTION-AMOUNT PIC S9(7)V99 USAGE COMP-3. 05 INTEREST-RATE PIC 9(3)V9(5) USAGE IS PACKED-DECIMAL. 05 CUSTOMER-BALANCE PIC S9(11)V99 COMP-3.
These examples show PACKED-DECIMAL and equivalent COMP-3 usage for financial data.
Key characteristics of PACKED-DECIMAL:
For a field defined as PIC S9(5) USAGE PACKED-DECIMAL
with a value of +12345:
For a negative value -12345:
Note: PACKED-DECIMAL is particularly well-suited for financial applications on mainframes. IBM mainframes have specialized hardware instructions for packed decimal arithmetic, making this format very efficient for financial calculations where exact decimal precision is required.
The BINARY usage and its variants store numeric data in native binary format. These usage types are often used for efficient arithmetic operations and interfacing with other programming languages.
1234501 BINARY-DATA-ITEMS. 05 ITEM-COUNT PIC 9(4) USAGE BINARY. 05 RECORD-SIZE PIC 9(8) USAGE BINARY-LONG. 05 FLAG-VALUE PIC 9(2) USAGE BINARY-SHORT. 05 LARGE-COUNTER PIC 9(16) USAGE BINARY SYNC.
These examples show different BINARY usage variants for numeric data.
BINARY usage variants:
Key characteristics of BINARY usage:
Important: When using BINARY usage, be aware of the maximum values that can be stored. For example, BINARY-SHORT can only store values up to 32,767 (for signed) or 65,535 (for unsigned). Attempting to store larger values may result in truncation or unexpected behavior.
Modern COBOL provides several specialized USAGE types for specific purposes, such as memory addressing, function references, and object-oriented programming.
123456701 SPECIAL-USAGES. 05 MEMORY-ADDRESS USAGE POINTER. 05 PROCEDURE-ADDRESS USAGE PROCEDURE-POINTER. 05 FUNCTION-ADDRESS USAGE FUNCTION-POINTER. 05 OBJECT-REFERENCE USAGE OBJECT REFERENCE. 05 STRING-HANDLE USAGE DISPLAY-1. 05 NATIONAL-STRING USAGE NATIONAL.
These examples show special USAGE types for various advanced purposes.
Common special USAGE types:
12345678910111213WORKING-STORAGE SECTION. 01 BLOCK-SIZE PIC 9(8) COMP. 01 MEMORY-BLOCK USAGE POINTER. PROCEDURE DIVISION. SET BLOCK-SIZE TO 1024 CALL "GETMAIN" USING BLOCK-SIZE MEMORY-BLOCK *> Use the allocated memory *> Free the memory when done CALL "FREEMAIN" USING MEMORY-BLOCK
This example shows how POINTER usage might be used with dynamic memory allocation on a mainframe system.
Key points about special USAGE types:
Note: Special USAGE types are primarily used in modern COBOL applications, especially those that interface with other systems or use object-oriented features. These USAGE types are less common in traditional legacy COBOL programs.
Selecting the appropriate USAGE clause for your data items is an important design decision that affects performance, storage requirements, and compatibility. Here are some guidelines for choosing the right USAGE.
Data Type | Recommended USAGE | Reason |
---|---|---|
Input/Output fields | DISPLAY | Compatible with external data formats, human-readable |
Calculation-intensive numerics | COMP, BINARY | Best performance for arithmetic operations |
Financial data | PACKED-DECIMAL, COMP-3 | Exact decimal precision, efficient storage, good mainframe performance |
Index values, counters | BINARY, COMP-5 | Efficient for loop processing |
Floating-point calculations | COMP-1, COMP-2 | Required for floating-point operations |
Memory addressing | POINTER | Required for dynamic memory handling |
Unicode text | NATIONAL | Proper handling of international character sets |
Considerations for USAGE selection:
Compare storage requirements
Create a program that defines the same numeric value (e.g., 9999999999) using different USAGE clauses and determine how much storage each requires.
Performance comparison
Write a program that performs the same calculation (e.g., a loop with many additions) using fields with different USAGE clauses and compare the execution time.
Design a financial record
Create a complete financial transaction record structure, choosing appropriate USAGE clauses for each field based on its purpose and requirements.
POINTER usage experiment
Write a simple program that uses POINTER usage to allocate and work with dynamic memory.
Mixed USAGE operations
Experiment with arithmetic operations involving fields with different USAGE clauses to observe how COBOL handles the conversions.
1. What is the default USAGE for data items in COBOL?
2. Which USAGE type stores numeric data in the form that humans can read directly?
3. What is the main advantage of using COMP or COMPUTATIONAL usage?
4. Which USAGE is generally synonymous with COMPUTATIONAL-3 in most COBOL implementations?
5. What type of data would you typically store with USAGE POINTER?
Techniques for optimizing data storage in COBOL programs
How computers represent numeric data internally
Understanding memory allocation and management in computing
Optimizing COBOL program performance
How data is shared between different systems and programs