COBOLintermediate

REDEFINES Clause

Understand how REDEFINES lets multiple data descriptions share the same storage location and why this is both powerful and risky.

REDEFINES allows a data item to occupy the exact same memory location as a previously defined item, giving COBOL a form of union-like overlay without any type system enforcement. It's a distinctly mainframe-flavored concept that trips up developers coming from languages with strict typing, and interviewers use it to test whether you grasp that COBOL storage is really just a byte layout with named views over it.

REDEFINES is like a single sheet of graph paper viewed through two different stencils — one stencil reads it as a bar chart, the other as a table of numbers, but it's the same ink on the same paper the whole time.

Key Concepts

1
The classic use case is a record that can arrive in more than one physical layout depending on a type code — for example, a transaction file where record type '01' has one field structure and type '02' has a different one, both the same overall length but sliced differently. Rather than declaring two separate 01-level record areas and copying bytes between them, you REDEFINES the second layout directly over the first's storage, and the program picks which 'view' to use based on the type code, without any data movement at all.
2
Because REDEFINES creates an alias rather than a copy, changes made through one name are immediately visible through the other name, and the two definitions do not need to be the same overall length (the redefining item just can't extend past the parent's allocated storage in most implementations, though it can be shorter). This is exactly the same storage-sharing idea as a C union, minus any compiler-enforced discriminator — the programmer alone is responsible for interpreting the bytes correctly based on context, usually a preceding type-code field.
3
A favorite interview scenario is asking you to explain what happens when a program reads a COMP-3 field through a REDEFINES that was declared as PIC X — the answer is that you'll see the raw packed-decimal bytes as unreadable characters, because REDEFINES doesn't convert data, it just changes how the same bytes are described and displayed.