Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 38 ยท Divisions and Data Description

REDEFINES, RENAMES and Level 88 Condition Names

Learn how REDEFINES gives one memory area several layouts, how RENAMES (level 66) regroups fields, and how level-88 condition names make flags and code checks readable.

Three data-division features let you look at the same bytes in different ways or give meaning to values. REDEFINES overlays one layout on another. RENAMES (level 66) makes a new name for a slice of a record. Level 88 condition names turn a cryptic test like IF STATUS-CODE = "A" into the readable IF ACCOUNT-ACTIVE. The last one is used in almost every real program.

REDEFINES

REDEFINES makes a second item share the same storage as the first. It is COBOL's way to treat one area as, say, a date text or three numbers, or to hold two record types in one buffer.

COBOL
       01 RAW-DATE            PIC 9(8) VALUE 20260115.
       01 DATE-PARTS REDEFINES RAW-DATE.
          05 YEAR-PART        PIC 9(4).
          05 MONTH-PART       PIC 9(2).
          05 DAY-PART         PIC 9(2).

DATE-PARTS occupies exactly the same eight bytes as RAW-DATE. After the VALUE, YEAR-PART is 2026, MONTH-PART is 01 and DAY-PART is 15. Change MONTH-PART and RAW-DATE changes too.

Rules:

  • REDEFINES immediately follows the item it redefines and has the same level number.
  • The redefining item may not be larger than the original (at level 01 it can be; at other levels it may not exceed it).
  • Neither may have an OCCURS clause at the same level.
  • Only the original item can have a VALUE (so VALUE does not appear on the redefining part, except for condition names).

A classic use is a file with several record types in one buffer:

COBOL
       01 INPUT-RECORD.
          05 REC-TYPE         PIC X.
          05 REC-BODY         PIC X(40).
       01 HEADER-REC REDEFINES INPUT-RECORD.
          05 FILLER           PIC X.
          05 HDR-BATCH-ID     PIC 9(6).
          05 HDR-RUN-DATE     PIC 9(8).
          05 FILLER           PIC X(26).
       01 DETAIL-REC REDEFINES INPUT-RECORD.
          05 FILLER           PIC X.
          05 DTL-ACCOUNT      PIC 9(10).
          05 DTL-AMOUNT       PIC S9(7)V99.
          05 FILLER           PIC X(21).

You read the record and look at REC-TYPE to decide which layout applies. COBOL does not stop you from reading the wrong view; reading a detail record as a header just gives nonsense, so always test the type first.

Python One buffer, several views (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

RENAMES (level 66)

RENAMES creates an alternative name for one field, or a range of consecutive fields, in a record. It is placed after all the entries of the record and uses level 66.

COBOL
       01 EMPLOYEE.
          05 EMP-ID           PIC 9(5).
          05 EMP-FIRST        PIC X(10).
          05 EMP-LAST         PIC X(15).
          05 EMP-DEPT         PIC X(4).
       66 EMP-FULL-NAME RENAMES EMP-FIRST THRU EMP-LAST.

EMP-FULL-NAME now refers to the 25 bytes covering first and last name, handled as alphanumeric. It is rarely used in new code because reference modification or a REDEFINES group does the same job more clearly.

Condition names (level 88)

A level-88 entry names a condition: a value or set of values of the item that comes just before it. Using it in an IF is clearer than comparing with a literal, and the meaning lives in one place.

COBOL
       01 ACCOUNT-STATUS      PIC X.
          88 ACCOUNT-ACTIVE   VALUE "A".
          88 ACCOUNT-CLOSED   VALUE "C".
          88 ACCOUNT-ON-HOLD  VALUE "H" "S".
       01 GRADE               PIC 99.
          88 PASSING          VALUE 50 THRU 100.
          88 FAILING          VALUE 0 THRU 49.
       01 END-OF-FILE-FLAG    PIC X VALUE "N".
          88 END-OF-FILE      VALUE "Y".
          88 MORE-RECORDS     VALUE "N".
COBOL
           IF ACCOUNT-ACTIVE
               PERFORM PROCESS-ACCOUNT
           END-IF

           SET END-OF-FILE TO TRUE
           PERFORM UNTIL END-OF-FILE
               ...
           END-PERFORM
  • VALUE can list several values ("H" "S") and ranges (50 THRU 100).
  • SET condition-name TO TRUE moves the first value of the 88 into the parent item, so the flag turns on without writing the literal.
  • SET condition-name TO FALSE works only if a WHEN SET TO FALSE IS value was declared (COBOL 2002).
  • Condition names can hang off numeric or alphanumeric items, including table elements.
Python Condition names as predicates (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Why level 88 matters

  • The code reads like a sentence: IF CUSTOMER-IS-VIP.
  • If the code for VIP changes from "V" to "1", you change one line.
  • It documents allowed values right where the field is defined.
  • Combined with EVALUATE and IF it makes control flow far easier to scan.

Common mistakes

  • Putting PIC on a level-88 entry (it has none; it has only VALUE).
  • Placing REDEFINES after other entries instead of right after the redefined item.
  • Giving a different size to a redefining elementary item and expecting a runtime error. COBOL checks the size at compile time but not that you used the right view.
  • Using the same literal in two 88 names on one item and getting surprising results from SET ... TO TRUE, which uses the first value listed.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does REDEFINES do?

    A REDEFINES item overlays the same bytes as the item it redefines. No copy is made.
  2. 2. Which level number is used for condition names?

    Level 88 defines conditions, level 66 is RENAMES and level 77 is a stand-alone elementary item.
  3. 3. What does SET END-OF-FILE TO TRUE do when END-OF-FILE is VALUE "Y"?

    SET condition TO TRUE stores the condition's (first) value into its parent field.
  4. 4. Which is a valid use of level 88?

    A condition name has no PIC. It only lists values (or ranges) of the item above it.

Summary

  • REDEFINES overlays another layout on the same storage; the original keeps the VALUE.
  • RENAMES (level 66) names a slice of consecutive fields; reference modification often replaces it.
  • Level 88 names values or ranges (VALUE "H" "S", 50 THRU 100) and SET ... TO TRUE turns them on.
  • Test the record type before choosing which redefined view to read.

Next: COPY and Copybooks