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.
[!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.
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.
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.
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.
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.