RENAMES and USAGE

COBOL COBOL 2014 (ISO/IEC 1989:2014), built with GnuCOBOL 3.x ยท โœ“ verified by execution on 2026-08-16

REDEFINES in the previous lesson let you lay a second description over the same storage. RENAMES does something narrower and easier to miss: it regroups fields that already exist, drawing a bracket around a run of adjacent items that the original layout never grouped together. Nothing is overlaid and nothing is copied โ€” you are naming a span.

USAGE is the other half of this lesson and answers a different question entirely: not how memory is labelled, but how a number is physically encoded in it. Together they are how you take a record layout inherited from a legacy system and work with it on your own terms, without touching a byte of the data.

The RENAMES Clause

The RENAMES clause allows you to create an alternative, overlapping grouping of elementary items that were not originally grouped together. It acts like a conceptual lens over existing memory, without allocating any new space or physically copying the data. This is extremely useful when you are reading in a flat file record from a legacy system, and you need to process parts of the data independently, while also having a shorthand to refer to the combined structure.

Unlike REDEFINES, which completely replaces the underlying data definition with a new one of the same size, RENAMES simply provides a second name for a sequential span of fields that already exist.

To use RENAMES, you declare a special level 66 item immediately following the record it belongs to. Level 66 is reserved exclusively for this purpose in the COBOL standard.

cobol โœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. BasicRenames.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  FULL-DATE.
           05  YEAR-PART   PIC X(4) VALUE "2026".
           05  MONTH-PART  PIC X(2) VALUE "08".
           05  DAY-PART    PIC X(2) VALUE "10".
       66  YEAR-MONTH RENAMES YEAR-PART THRU MONTH-PART.
       PROCEDURE DIVISION.
           DISPLAY "Full Date: " FULL-DATE.
           DISPLAY "Year-Month: " YEAR-MONTH.
           STOP RUN.
Output
Full Date: 20260810
Year-Month: 202608

Overlapping Ranges

The true power of RENAMES comes with the THRU keyword. You can span multiple adjacent fields to create a single logical unit.

cobol โœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. OverlapRenames.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  EMPLOYEE-RECORD.
           05  FIRST-NAME   PIC X(10) VALUE "ALICE     ".
           05  MIDDLE-INIT  PIC X(1)  VALUE "M".
           05  LAST-NAME    PIC X(10) VALUE "SMITH     ".
       66  FIRST-AND-MID RENAMES FIRST-NAME THRU MIDDLE-INIT.
       66  MID-AND-LAST  RENAMES MIDDLE-INIT THRU LAST-NAME.
       PROCEDURE DIVISION.
           DISPLAY "First + Mid: " FIRST-AND-MID.
           DISPLAY "Mid + Last : " MID-AND-LAST.
           STOP RUN.
Output
First + Mid: ALICE     M
Mid + Last : MSMITH

[!CAUTION] Level-66 items cannot contain PICTURE, USAGE, or VALUE clauses. They simply inherit the properties of the underlying data they rename.

The USAGE Clause

While PICTURE dictates how data is formatted and presented, the USAGE clause dictates how it is stored in physical memory on the mainframe. This is a critical distinction that affects both memory efficiency and CPU performance.

If you omit the USAGE clause entirely, COBOL implicitly assumes USAGE DISPLAY. This means every single digit or character takes exactly one full byte of storage in EBCDIC (or ASCII). This format is fantastic for printing human-readable reports, but it is highly inefficient for mathematical calculations because the CPU must convert the text string into a binary number, perform the math, and then convert it back.

cobol โœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. UsageExample.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  DISPLAY-NUM PIC 9(4) USAGE DISPLAY VALUE 1234.
       01  COMP-NUM    PIC 9(4) USAGE COMP    VALUE 1234.
       PROCEDURE DIVISION.
           DISPLAY 'DISPLAY Num: ' DISPLAY-NUM.
           DISPLAY 'COMP Num: ' COMP-NUM.
           STOP RUN.
Output
DISPLAY Num: 1234
COMP Num: 1234

Binary Storage

To save space and speed up calculations, you can declare numeric fields as USAGE COMP (Computational) or USAGE BINARY. These formats store numbers in pure binary rather than text characters, just like an int in C or Java.

cobol โœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ErrorRenames.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  DATA-REC.
           05  ITEM-A PIC X(5) VALUE "HELLO".
       66  RENAME-A RENAMES ITEM-A.
       PROCEDURE DIVISION.
           DISPLAY RENAME-A.
           STOP RUN.
Output
HELLO

Packed Decimal (COMP-3)

One of COBOLโ€™s most famous features is USAGE COMP-3, or packed decimal. Instead of storing one digit per byte, it packs two digits into each byte, leaving a half-byte (nibble) at the very end for the plus or minus sign. This is incredibly efficient for exact financial arithmetic.

cobol โœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. Comp3Example.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  PACKED-NUM  PIC 9(5) USAGE COMP-3 VALUE 12345.
       PROCEDURE DIVISION.
           DISPLAY "Packed decimal (COMP-3): " PACKED-NUM.
           STOP RUN.
Output
Packed decimal (COMP-3): 12345
USAGE DISPLAY vs COMP-3 PIC 9(4) USAGE DISPLAY (Value 1234) 1 2 3 4 4 bytes PIC 9(4) USAGE COMP-3 (Value 1234) 0 1 2 3 4 + 3 bytes (Packed)
Predict the output cobol

Read the code. What exactly will it print? Commit to an answer before you look.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. PredictRenames.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  ACCOUNT-RECORD.
           05  FIRST-NAME PIC X(5) VALUE "ALICE".
           05  LAST-NAME  PIC X(5) VALUE "SMITH".
       66  FULL-NAME RENAMES FIRST-NAME THRU LAST-NAME.
       PROCEDURE DIVISION.
           DISPLAY FULL-NAME.
           STOP RUN.
Output
ALICESMITH

Check yourself

Which statement is true regarding the RENAMES clause?

Reveal answer

It creates a new grouping name that maps to the exact same physical memory as the items it references. โ€” RENAMES simply provides an alternative name for an existing portion of a record. It does not allocate any new storage or move any data.

What happens when you declare a variable with USAGE COMP instead of USAGE DISPLAY?

Reveal answer

The variable uses binary storage, which can save space depending on its PICTURE clause length. โ€” USAGE COMP uses binary format, so a PIC 9(4) might only take 2 bytes instead of 4 bytes in USAGE DISPLAY. It often saves space and makes arithmetic faster.

Which of the following is an invalid rule for a level-66 item?

Reveal answer

It can contain a PICTURE, USAGE, or VALUE clause. โ€” Level-66 items merely redefine the layout of existing items, so they cannot contain PICTURE, USAGE, or VALUE clauses.

Challenges

Challenge 1 +20 XP

Define a packed decimal (COMP-3) field named POPULATION with PIC 9(8) initialized to 1500000.

cobol โœ“ solution verified at build time

COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the fixed code should be, then open the solution and compare. The expected output below is real โ€” it came from compiling the solution with GnuCOBOL when this page was built.

  • Test 1 โ€” expects "REGION: XY"
Need a hint? (โˆ’25% XP)

Use USAGE COMP-3 for packed decimal.

Show solution (0 XP)
IDENTIFICATION DIVISION.
PROGRAM-ID. Chal1Sol.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  CENSUS-DATA.
    05  REGION-CODE PIC X(2) VALUE "XY".
    05  POPULATION  PIC 9(8) USAGE COMP-3 VALUE 1500000.
PROCEDURE DIVISION.
    DISPLAY "REGION: " REGION-CODE
    STOP RUN.

Challenge 2 +20 XP

Create a level 66 item named COMBINED-FIELD that RENAMES FIELD1 THRU FIELD2.

cobol โœ“ solution verified at build time

COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the fixed code should be, then open the solution and compare. The expected output below is real โ€” it came from compiling the solution with GnuCOBOL when this page was built.

  • Test 1 โ€” expects "XYZ123"
Need a hint? (โˆ’25% XP)

66 COMBINED-FIELD RENAMES FIELD1 THRU FIELD2.

Show solution (0 XP)
IDENTIFICATION DIVISION.
PROGRAM-ID. Chal2Sol.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  RAW-DATA.
    05  FIELD1 PIC X(3) VALUE "XYZ".
    05  FIELD2 PIC X(3) VALUE "123".
66  COMBINED-FIELD RENAMES FIELD1 THRU FIELD2.
PROCEDURE DIVISION.
    DISPLAY COMBINED-FIELD
    STOP RUN.

๐Ÿž Bug Hunt +25 XP

This developer correctly used the `THRU` clause to span multiple fields, but they received a syntax error about an `unexpected PICTURE`. Level-66 items are special: they only describe a new grouping name for existing memory, so they cannot define their own data types or values. Remove the invalid clause to fix the compilation.

This code runs. It just does the wrong thing. Read it, find the defect, fix it โ€” the tests below decide when you are right.

cobol โœ“ solution verified at build time

COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the fixed code should be, then open the solution and compare. The expected output below is real โ€” it came from compiling the solution with GnuCOBOL when this page was built.

  • Test 1 โ€” expects "XYZ123\n"
Need a hint? (โˆ’25% XP)

Remove the `PIC X(6)` clause from the `66` level item.

Show solution (0 XP)
IDENTIFICATION DIVISION.
PROGRAM-ID. BUG2.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  RAW-DATA.
    05  FIELD1 PIC X(3) VALUE "XYZ".
    05  FIELD2 PIC X(3) VALUE "123".
66  COMBINED-FIELD RENAMES FIELD1 THRU FIELD2.
PROCEDURE DIVISION.
    DISPLAY COMBINED-FIELD.
    STOP RUN.