REDEFINES
A COBOL clause that gives a second description to the same piece of memory, so the same bytes can be read in different ways.
Also written REDEFINES clause
REDEFINES lets two data descriptions share the same storage. The second description does not get new memory. It is another way of looking at the bytes the first one already uses.
A common use is a date. One field describes it as eight digits, and a redefinition describes the same eight bytes as a four-digit year, a two-digit month and a two-digit day. Moving a value into either description changes both, because they are the same memory.
Another common use is a file with several kinds of record. The first bytes say the record type, and each type has its own layout that redefines the same area. The program checks the type, then reads the fields of the right layout.
COBOL does no checking or conversion between the descriptions. If the bytes contain text and the program reads them through a numeric description, it gets nonsense or an S0C7 abend. When you see REDEFINES in a copybook, find out which condition tells the program which layout to use.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- DATA DIVISIONThe part of a COBOL program that declares every record layout and variable it will use.
- Level numberThe two-digit number in front of a COBOL data item that shows how fields nest inside a record.
- PICTURE clauseThe COBOL declaration that says what kind of data a field holds and how long it is, written as PIC.
- CopybookA shared block of COBOL declarations kept in a library and included into programs, so a record layout is defined once.
- WORKING-STORAGEThe section of a COBOL program that declares its internal variables: counters, totals, flags and work areas.