Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

COBOL  Module 2 – Data definitions: PICTURE, levels, MOVE rules and edited output

Condition names (88), REDEFINES and RENAMES

Name the values of a COBOL item with level-88 condition names, set them with SET, lay record layouts over one area with REDEFINES, and read RENAMES.

  • Intermediate
  • 15 minutes
  • Examples run with GnuCOBOL 3.2 and Python 3.14.8
  • By MySmartCoPilot
Free lesson, Pro answers: 15 minutes
Free: the whole lesson. With a pass: the model answers to its 2 interview questions.

What you will learn

  • Name values, value lists and ranges of an item with level-88 condition names
  • Set and test condition names, including SET ... TO FALSE
  • Describe variant record layouts with REDEFINES and a record-type byte
  • Recognise level-66 RENAMES entries in old copybooks and say which bytes each one names

Before you start

What you’ll learn · Before you start

What you will learn

  • Name values, value lists and ranges of an item with level-88 condition names
  • Set and test condition names, including SET ... TO FALSE
  • Describe variant record layouts with REDEFINES and a record-type byte
  • Recognise level-66 RENAMES entries in old copybooks and say which bytes each one names

Before you start

On this page

An account status byte holds A, D, C or W, and the test IF ACCT-STATUS = “A” OR ACCT-STATUS = “D” means “open” in forty places of a program, until a new code arrives and someone has to find all forty. A level-88 condition name gives that test one name, written once, next to the data it tests.

Below you will name single values, lists and ranges with condition names and test them, set them with SET … TO TRUE and TO FALSE, lay three record layouts over one area with REDEFINES and choose among them by a type byte, and read the level-66 RENAMES entries that old copybooks still carry.

A condition name stands for values of the item above it

A condition name: A level-88 entry that names a value, a list of values or a THRU range of the item above it, so that IF ACCT-OPEN tests that item against them. is a level-88 entry under a data item, its conditional variable: The data item a level-88 condition name belongs to: the item whose value the condition tests and SET ... TO TRUE changes.. Its VALUE clause lists the values it stands for: one value, several, or a range written with THRU. IBM’s reference calls a condition name “an abbreviation for the relation condition”, and the condition is true when the variable equals one of its values or “falls within the ranges, including the end values”. This program names the codes of an account status and the buckets of days past due:

status88.cob: condition names for codes and for ranges COB · status88.cob
       IDENTIFICATION DIVISION.
       PROGRAM-ID. STATUS88.
      * Condition names for an account status code and for days past
      * due: single values, lists and THRU ranges.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  ACCT-STATUS      PIC X.
           88  ACCT-OPEN        VALUE "A" "D".
           88  ACCT-CLOSED      VALUE "C" "W".
           88  ACCT-VALID       VALUE "A" "C" "D" "W".
       01  DAYS-PAST-DUE    PIC 9(3).
           88  DPD-NONE         VALUE 0.
           88  DPD-UP-TO-30     VALUE 1 THRU 30.
           88  DPD-31-TO-90     VALUE 31 THRU 90.
           88  DPD-OVER-90      VALUE 91 THRU 999.
       PROCEDURE DIVISION.
           MOVE "D" TO ACCT-STATUS
           PERFORM SHOW-STATUS
           MOVE "W" TO ACCT-STATUS
           PERFORM SHOW-STATUS
           MOVE "Q" TO ACCT-STATUS
           PERFORM SHOW-STATUS
           MOVE 0 TO DAYS-PAST-DUE
           PERFORM SHOW-BUCKET
           MOVE 17 TO DAYS-PAST-DUE
           PERFORM SHOW-BUCKET
           MOVE 90 TO DAYS-PAST-DUE
           PERFORM SHOW-BUCKET
           MOVE 120 TO DAYS-PAST-DUE
           PERFORM SHOW-BUCKET
           STOP RUN.
       SHOW-STATUS.
           IF NOT ACCT-VALID
               DISPLAY "status " ACCT-STATUS ": not a valid code"
           ELSE
               IF ACCT-OPEN
                   DISPLAY "status " ACCT-STATUS ": open"
               ELSE
                   DISPLAY "status " ACCT-STATUS ": closed"
               END-IF
           END-IF.
       SHOW-BUCKET.
           EVALUATE TRUE
               WHEN DPD-NONE
                   DISPLAY DAYS-PAST-DUE " days: no dues"
               WHEN DPD-UP-TO-30
                   DISPLAY DAYS-PAST-DUE " days: 1 to 30"
               WHEN DPD-31-TO-90
                   DISPLAY DAYS-PAST-DUE " days: 31 to 90"
               WHEN DPD-OVER-90
                   DISPLAY DAYS-PAST-DUE " days: over 90"
           END-EVALUATE.
Three status codes and four day counts Python · status88_session.py
from session import files, run

# Condition names in IF and EVALUATE: a status code against its lists, and days past due against THRU ranges.
files("status88.cob")
run("""
cobc -x status88.cob && ./status88
""")

Output

$ cobc -x status88.cob && ./status88
status D: open
status W: closed
status Q: not a valid code
000 days: no dues
017 days: 1 to 30
090 days: 31 to 90
120 days: over 90

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 status88_session.py

Each test reads as what it means. IF NOT ACCT-VALID caught Q, a code that none of A, C, D and W matches, before IF ACCT-OPEN decided between open and closed for D and W. EVALUATE TRUE, a statement of the control-flow lessons, picks the first WHEN whose condition is true, and the four condition names put 0, 17, 90 and 120 days into their buckets; 90 counted as 31 to 90 because a range includes its end values.

Condition name Its VALUE clause It replaces the test
ACCT-OPEN "A" "D" ACCT-STATUS = "A" OR ACCT-STATUS = "D"
ACCT-CLOSED "C" "W" ACCT-STATUS = "C" OR ACCT-STATUS = "W"
DPD-UP-TO-30 1 THRU 30 DAYS-PAST-DUE >= 1 AND DAYS-PAST-DUE <= 30
DPD-OVER-90 91 THRU 999 DAYS-PAST-DUE >= 91 AND DAYS-PAST-DUE <= 999

When a new code arrives, say P for an account waiting to be closed, it goes into the VALUE clause of each condition name it belongs to, and every IF ACCT-CLOSED in the program follows without a change.

Testing the codes themselves

Wrong: IF ACCT-STATUS = “A” OR ACCT-STATUS = “D” wherever the program asks whether an account is open, so a new code means a search through every program. Right: one 88-level name per meaning, ACCT-OPEN, and IF ACCT-OPEN everywhere.

SET stores a value of the condition name, and FALSE needs its own

A condition name can also be set. SET ACCT-CLOSED TO TRUE stores a value of ACCT-CLOSED in ACCT-STATUS; with a list there is a choice, and IBM’s rule is that the variable “is set equal to the first literal”. Setting one false needs a value for false, and IBM requires a WHEN SET TO FALSE phrase on the 88-level entry for it. This program sets an account status and an end-of-file flag, and a second program sets a condition name false that has no such phrase:

setflags.cob: SET ... TO TRUE and SET ... TO FALSE COB · setflags.cob
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SETFLAGS.
      * SET ... TO TRUE stores a value of the condition name; SET ...
      * TO FALSE stores the value of its WHEN SET TO FALSE phrase.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  ACCT-STATUS      PIC X        VALUE "A".
           88  ACCT-OPEN        VALUE "A" "D".
           88  ACCT-CLOSED      VALUE "C" "W".
       01  EOF-FLAG         PIC X        VALUE "N".
           88  END-OF-FILE      VALUE "Y" WHEN SET TO FALSE "N".
       PROCEDURE DIVISION.
           DISPLAY "ACCT-STATUS starts as        " ACCT-STATUS
           SET ACCT-CLOSED TO TRUE
           DISPLAY "after SET ACCT-CLOSED TRUE   " ACCT-STATUS
           SET ACCT-OPEN TO TRUE
           DISPLAY "after SET ACCT-OPEN TRUE     " ACCT-STATUS
           SET END-OF-FILE TO TRUE
           DISPLAY "after SET END-OF-FILE TRUE   " EOF-FLAG
           SET END-OF-FILE TO FALSE
           DISPLAY "after SET END-OF-FILE FALSE  " EOF-FLAG
           STOP RUN.
The bytes each SET leaves, and a SET that does not compile Python · setflags_session.py
from session import files, run

# What SET ... TO TRUE and SET ... TO FALSE store, and SET ... TO FALSE where no false value is given.
files("setflags.cob", "setfalse.cob")
run("""
cobc -x setflags.cob && ./setflags
!cobc -x setfalse.cob
""")

Output

$ cobc -x setflags.cob && ./setflags
ACCT-STATUS starts as        A
after SET ACCT-CLOSED TRUE   C
after SET ACCT-OPEN TRUE     A
after SET END-OF-FILE TRUE   Y
after SET END-OF-FILE FALSE  N
$ cobc -x setfalse.cob
setfalse.cob:9: error: field does not have a FALSE clause
    7 |            88  ACCT-CLOSED      VALUE "C" "W".
    8 |        PROCEDURE DIVISION.
    9 >            SET ACCT-CLOSED TO FALSE
   10 |            DISPLAY ACCT-STATUS
   11 |            STOP RUN.
[exit status 1]

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 setflags_session.py

Each SET left one byte behind. Step through them in order:

Interactive · stage by stage What each SET statement of setflags.cob stores Step down the column. Each stage is one SET statement, and its second line is the byte it leaves behind.
What each SET statement of setflags.cob stores, step 5 of 5. Showing At the start, ACCT-CLOSED TO TRUE, ACCT-OPEN TO TRUE, END-OF-FILE TO TRUE, END-OF-FILE TO FALSE. In focus: END-OF-FILE TO FALSE.At the startACCT-STATUS VALUE "A"ACCT-CLOSED TO TRUESET stores C, first of C, WACCT-OPEN TO TRUESET stores A, first of A, DEND-OF-FILE TO TRUESET stores Y in EOF-FLAGEND-OF-FILE TO FALSESET stores N in EOF-FLAG

The drawing shows the whole scene; its 5 steps are listed below.

Every step as text
  1. The starting value. ACCT-STATUS starts with its VALUE, A, so ACCT-OPEN is true, because A is one of its values A and D.
  2. SET to a list. ACCT-CLOSED has two values, C and W. SET ACCT-CLOSED TO TRUE has to store one of them, and IBM's rule is the first literal, so ACCT-STATUS becomes C.
  3. SET back to open. SET ACCT-OPEN TO TRUE stores A, the first of A and D. The code says what it means, the account is open, and the 88-level entry decides which byte that is.
  4. A flag set true. END-OF-FILE has one value, Y, so SET END-OF-FILE TO TRUE stores Y in EOF-FLAG.
  5. A flag set false. SET END-OF-FILE TO FALSE works because the entry says WHEN SET TO FALSE "N", and N is stored. ACCT-CLOSED has no such phrase, so setfalse.cob, which sets it false, did not compile.

SET ACCT-CLOSED TO TRUE stored C, not W, and SET ACCT-OPEN TO TRUE stored A, not D: the first value is always the one stored, so put the most usual code first. END-OF-FILE became Y and then N, the value its WHEN SET TO FALSE phrase names. setfalse.cob did not compile, field does not have a FALSE clause, because nothing tells the compiler which byte false should store: any value but C and W would make ACCT-CLOSED false.

Key idea

Set flags with SET … TO TRUE rather than MOVE, so the code names the meaning and the 88-level entry decides the byte, and give every condition name that is ever set false a WHEN SET TO FALSE value.

Checkpoint

Check: Condition names, lists and ranges · SET ... TO TRUE and TO FALSE

  1. Question 1 of 2 DAYS-PAST-DUE holds 90. Which condition name of status88.cob is true?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: DPD-31-TO-90

    IBM's reference says the condition is true when the variable falls within the range, including the end values, so 90 is in 31 THRU 90 and 91 would be in 91 THRU 999.

  2. Question 2 of 2 ACCT-CLOSED is an 88 with VALUE "C" "W". What does SET ACCT-CLOSED TO TRUE store in ACCT-STATUS?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: C

    SET ACCT-CLOSED TO TRUE left C in ACCT-STATUS, the first of C and W, which is why the most usual code belongs at the front of the list.

REDEFINES lays several layouts over the same bytes

A file often holds records of several kinds in one layout of bytes: a header, details and a trailer, told apart by a type byte at the front. The REDEFINES: A clause that describes the storage of an earlier item a second way, so the same bytes can be read as different fields. Nothing checks which description fits the data. clause describes the same storage a second and a third time; IBM’s reference says it lets “different data description entries … describe the same computer storage area”. Here a 19-byte body is described as a header, as a detail and as a trailer, and condition names on the type byte choose which description to read:

records.cob: three layouts over one record body COB · records.cob
       IDENTIFICATION DIVISION.
       PROGRAM-ID. RECORDS1.
      * One 20-byte record area, three layouts over the same bytes,
      * chosen by the record-type byte.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  TXN-REC.
           05  REC-TYPE         PIC X.
               88  IS-HEADER        VALUE "H".
               88  IS-DETAIL        VALUE "D".
               88  IS-TRAILER       VALUE "T".
           05  REC-BODY         PIC X(19).
           05  HEADER-BODY      REDEFINES REC-BODY.
               10  BRANCH-CODE  PIC X(4).
               10  BATCH-NO     PIC 9(6).
               10  FILLER       PIC X(9).
           05  DETAIL-BODY      REDEFINES REC-BODY.
               10  ACCT-NO      PIC X(6).
               10  DR-CR        PIC X.
               10  AMOUNT       PIC 9(7)V99.
               10  FILLER       PIC X(3).
           05  TRAILER-BODY     REDEFINES REC-BODY.
               10  REC-COUNT    PIC 9(5).
               10  TOTAL-AMT    PIC 9(9)V99.
               10  FILLER       PIC X(3).
       PROCEDURE DIVISION.
           MOVE "H0042000117" TO TXN-REC
           PERFORM SHOW-RECORD
           MOVE "DAC0417D000250000" TO TXN-REC
           PERFORM SHOW-RECORD
           MOVE "DAC0532C000012550" TO TXN-REC
           PERFORM SHOW-RECORD
           MOVE "T0000200000262550" TO TXN-REC
           PERFORM SHOW-RECORD
           MOVE "Q1234" TO TXN-REC
           PERFORM SHOW-RECORD
           MOVE "H0042000117" TO TXN-REC
           DISPLAY "the header read through DETAIL-BODY:"
           DISPLAY "  ACCT-NO [" ACCT-NO "] DR-CR [" DR-CR
                   "] AMOUNT [" AMOUNT "]"
           STOP RUN.
       SHOW-RECORD.
           EVALUATE TRUE
               WHEN IS-HEADER
                   DISPLAY "header   branch " BRANCH-CODE
                           ", batch " BATCH-NO
               WHEN IS-DETAIL
                   DISPLAY "detail   " ACCT-NO " " DR-CR " " AMOUNT
               WHEN IS-TRAILER
                   DISPLAY "trailer  " REC-COUNT " records, total "
                           TOTAL-AMT
               WHEN OTHER
                   DISPLAY "rejected record type [" REC-TYPE "]"
           END-EVALUATE.
Five records, and a header read through the wrong layout Python · records_session.py
from session import files, run

# Three layouts over one record area, picked by the record-type byte, and a header read through the detail layout.
files("records.cob")
run("""
cobc -x records.cob && ./records
""")

Output

$ cobc -x records.cob && ./records
header   branch 0042, batch 000117
detail   AC0417 D 0002500.00
detail   AC0532 C 0000125.50
trailer  00002 records, total 000002625.50
rejected record type [Q]
the header read through DETAIL-BODY:
  ACCT-NO [004200] DR-CR [0] AMOUNT [117    .00]

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 records_session.py

The program read each record through the layout its type byte named, rejected the type Q, and the trailer’s total, 2625.50, matched its two details. Step through the records and the layout each one chose:

Interactive · step by step One record area, three layouts, chosen by the type byte Step through the records of records.cob. The type byte picks a layout; nothing stops the program reading another.
One record area, three layouts, chosen by the type byte, step 7 of 7. Showing TXN-REC, 20 bytes, REC-TYPE, byte 1, REC-BODY, bytes 2-20, HEADER-BODY (branch 0042, batch 000117), DETAIL-BODY (ACCT-NO 004200: wrong view), TRAILER-BODY (00002 records, 2625.50). In focus: DETAIL-BODY.TXN-REC, 20 bytesREC-TYPE, byte 1REC-BODY, bytes 2-20HEADER-BODYbranch 0042, batch 000117DETAIL-BODYACCT-NO 004200: wrong viewTRAILER-BODY00002 records, 2625.50

The drawing shows the whole scene; its 7 steps are listed below.

Every step as text
  1. The record area. TXN-REC is 20 bytes, a type byte and a 19-byte body. HEADER-BODY, DETAIL-BODY and TRAILER-BODY each REDEFINE the body, so all three describe the same 19 bytes.
  2. A header. The first record starts with H, so IS-HEADER is true and the program reads the body as HEADER-BODY, branch 0042 and batch 000117.
  3. A debit. The next record starts with D, so the body is read as DETAIL-BODY, account AC0417, D for a debit and 0002500.00.
  4. A credit. Another D record, read the same way, account AC0532, C for a credit, 0000125.50. The same 19 bytes now hold a different account.
  5. The trailer. T picks TRAILER-BODY, 00002 records and a total of 000002625.50, which is 2500.00 + 125.50, the two details.
  6. An unknown type. The fifth record starts with Q, which no condition name of REC-TYPE names, so WHEN OTHER rejects it instead of reading it through any layout.
  7. The wrong layout. Read through DETAIL-BODY, the header gives ACCT-NO 004200 and an AMOUNT made of 117 and spaces. The bytes are the header's; nothing checks which layout they belong to, and no error comes.

The last lines show what REDEFINES does not do. Read through DETAIL-BODY, the header gave ACCT-NO 004200 and an AMOUNT made of the digits 117 and spaces, and no error came: the bytes do not know which layout wrote them. A REDEFINES is only as safe as the test of the type byte in front of it. IBM also bars VALUE clauses from a redefining entry and everything under it, so a layout over shared bytes never starts with values of its own.

A layout larger than the area it redefines

IBM’s reference lets the redefining item “occupy more storage than the redefined item”. GnuCOBOL 3.2 refuses that below level 01 by default, and accepts it with a warning under -std=ibm, so a copybook that compiles on z/OS can fail here. The session below shows both.

larger.cob: a layout one byte longer than its area COB · larger.cob
       IDENTIFICATION DIVISION.
       PROGRAM-ID. LARGER.
      * A layout one byte longer than the area it redefines.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  TXN-REC.
           05  REC-TYPE         PIC X.
           05  REC-BODY         PIC X(19).
           05  DETAIL-BODY      REDEFINES REC-BODY.
               10  ACCT-NO      PIC X(6).
               10  DR-CR        PIC X.
               10  AMOUNT       PIC 9(9)V99.
               10  FILLER       PIC X(2).
       PROCEDURE DIVISION.
           DISPLAY FUNCTION BYTE-LENGTH(DETAIL-BODY)
           STOP RUN.
The default dialect, then the IBM dialect Python · larger_session.py
from session import files, run

# A redefining layout larger than the item it redefines: GnuCOBOL's default dialect, then its IBM dialect.
files("larger.cob")
run("""
!cobc -x larger.cob
cobc -x -std=ibm larger.cob 2>&1 | grep 'larger.cob' && ./larger
""")

Output

$ cobc -x larger.cob
larger.cob:9: error: larger REDEFINES used
    7 |            05  REC-TYPE         PIC X.
    8 |            05  REC-BODY         PIC X(19).
    9 >            05  DETAIL-BODY      REDEFINES REC-BODY.
   10 |                10  ACCT-NO      PIC X(6).
   11 |                10  DR-CR        PIC X.
larger.cob:9: note: size of 'DETAIL-BODY' larger than size of 'REC-BODY' [-Wdialect]
[exit status 1]
$ cobc -x -std=ibm larger.cob 2>&1 | grep 'larger.cob' && ./larger
larger.cob:9: warning: larger REDEFINES used [-Wdialect]
larger.cob:9: note: size of 'DETAIL-BODY' larger than size of 'REC-BODY' [-Wdialect]
20

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 larger_session.py

The default build stopped with larger REDEFINES used; the -std=ibm build warned and ran, and BYTE-LENGTH reported 20 bytes for a layout over 19. GnuCOBOL’s NEWS for 3.2 adds -Wlarger-01-redefines for the one larger REDEFINES the standard itself allows, at level 01.

Key idea

REDEFINES gives the same bytes several layouts, and nothing checks which one fits: test the type byte with a condition name before you read any of them.

RENAMES gives a run of items another name

Old copybooks sometimes end a record with level-66 entries. A RENAMES: A level-66 entry that gives a new name to one elementary item or to a run of consecutive items of a record. It is written after the record's last entry. entry names one elementary item again, or a run of consecutive items with THRU, without changing the record: IBM’s reference calls these “alternative and possibly overlapping groupings of elementary data items”. The entries “must immediately follow the last data description entry” of their record, and they may not rename an 01, 77, 88 or 66 entry. Here an address record gets a name for its first two items together:

renames.cob: two level-66 entries after an address record COB · renames.cob
       IDENTIFICATION DIVISION.
       PROGRAM-ID. RENAMES1.
      * Level 66: new names for one item and for a run of items.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  ADDR-REC.
           05  HOUSE-NO         PIC X(6)     VALUE "12-B".
           05  STREET           PIC X(12)    VALUE "MG ROAD".
           05  CITY             PIC X(10)    VALUE "PUNE".
           05  POST-CODE        PIC X(6)     VALUE "411001".
       66  STREET-LINE      RENAMES HOUSE-NO THRU STREET.
       66  TOWN             RENAMES CITY.
       PROCEDURE DIVISION.
           DISPLAY "STREET-LINE [" STREET-LINE "] "
                   FUNCTION BYTE-LENGTH(STREET-LINE) " bytes"
           DISPLAY "TOWN        [" TOWN "]"
           MOVE SPACES TO STREET-LINE
           DISPLAY "ADDR-REC    [" ADDR-REC "]"
           STOP RUN.
Reading and writing through a RENAMES name Python · renames_session.py
from session import files, run

# Level-66 names over an address record, and a MOVE through one of them.
files("renames.cob")
run("""
cobc -x renames.cob && ./renames
""")

Output

$ cobc -x renames.cob && ./renames
STREET-LINE [12-B  MG ROAD     ] 18 bytes
TOWN        [PUNE      ]
ADDR-REC    [                  PUNE      411001]

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 renames_session.py

Level-66 name Renames Bytes of ADDR-REC
STREET-LINE HOUSE-NO THRU STREET 1-18, 18 bytes
TOWN CITY 19-28, 10 bytes

STREET-LINE is 18 bytes, the 6 of HOUSE-NO and the 12 of STREET, and it behaves like a group of the two: MOVE SPACES TO STREET-LINE cleared both and left CITY and POST-CODE alone. New code gets the same effect by making the two items a group with a level number of its own. RENAMES is worth recognising for the day a shared copybook cannot change its layout and a program still needs a name for part of it.

Checkpoint

Check: REDEFINES and the record-type byte · Level-66 RENAMES

  1. Question 1 of 2 records.cob moved a header record into TXN-REC and displayed it through DETAIL-BODY. What happened?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: It printed wrong data, ACCT-NO 004200 and an amount of 117 and spaces, with no error

    REDEFINES describes storage; it does not track what is in it. A condition name on the type byte, tested before any layout is read, is what keeps the layouts apart.

  2. Question 2 of 2 HOUSE-NO is PIC X(6) and STREET is PIC X(12). How many bytes does STREET-LINE, which RENAMES HOUSE-NO THRU STREET, name?

    Type a number.

    Show the answer: Question 2 of 2

    Answer: 18 bytes

    A RENAMES with THRU names the storage from the first item through the last, here 6 + 12 = 18 bytes, which is what BYTE-LENGTH printed.

Practise: read the conditions and the layouts

Each question below names a condition, a SET or a layout from this lesson’s programs. Answer from the code, then compare with what the run printed; each choice explains where a wrong reading goes astray:

Practice that adapts to you

Practise this lesson

12 questions about 4 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 12 What does IF ACCT-OPEN test, when ACCT-OPEN is an 88 under ACCT-STATUS with VALUE "A" "D"?

    Choose one answer.

    Show the answer: Question 1 of 12

    Answer: Whether ACCT-STATUS holds A or D

    The 88-level entry stores nothing. It gives a name to values of its conditional variable, so IF ACCT-OPEN reads as the business rule and the codes stay in one place.

  2. Question 2 of 12 ACCT-STATUS receives Q. Which line did status88.cob print?

    Choose one answer.

    Show the answer: Question 2 of 12

    Answer: status Q: not a valid code

    A condition name that lists every valid code turns a check for bad data into one readable test, IF NOT ACCT-VALID.

  3. Question 3 of 12 A new status P, an account waiting to be closed, counts as closed. What is the smallest change that keeps every IF ACCT-CLOSED right?

    Choose one answer.

    Show the answer: Question 3 of 12

    Answer: Add "P" to the VALUE clauses of ACCT-CLOSED and ACCT-VALID

    With condition names, a new code is a change in one place, the VALUE clauses: here ACCT-CLOSED and ACCT-VALID, the list of every valid code. A separate name for the new code can be added too, for tests that must tell it apart.

  4. Question 4 of 12 A condition name has VALUE "A" "D". Which value does SET ... TO TRUE store?

    Choose one answer.

    Show the answer: Question 4 of 12

    Answer: A, the first one

    SET ACCT-OPEN TO TRUE stored A in setflags.cob. Put the code a program should store first in the list.

  5. Question 5 of 12 Why did setfalse.cob, which runs SET ACCT-CLOSED TO FALSE, not compile?

    Choose one answer.

    Show the answer: Question 5 of 12

    Answer: ACCT-CLOSED has no WHEN SET TO FALSE phrase, so there is no value for false

    Setting a condition true has an obvious value, its first; setting it false does not, so the 88-level entry must name it with WHEN SET TO FALSE.

  6. Question 6 of 12 A program marks the end of its input with MOVE "Y" TO EOF-FLAG in six places. Why replace them with SET END-OF-FILE TO TRUE?

    Choose one answer.

    Show the answer: Question 6 of 12

    Answer: The code then names the meaning, and the byte is decided in one place, the 88-level entry

    MOVE "Y" puts a code into the procedure; SET END-OF-FILE TO TRUE says what is meant and lets the data division decide the code.

  7. Question 7 of 12 What does REDEFINES do?

    Choose one answer.

    Show the answer: Question 7 of 12

    Answer: It describes the same storage again, with a different layout

    REDEFINES gives one area several descriptions. The program decides which one to read, usually from a type byte.

  8. Question 8 of 12 The trailer of records.cob said 00002 records and a total of 2625.50. What does that total check?

    Choose one answer.

    Show the answer: Question 8 of 12

    Answer: That the details read add up, 2500.00 + 125.50

    Header, detail and trailer records are a batch pattern: the trailer's count and total let the program check what it read, which a later lesson on control totals builds on.

  9. Question 9 of 12 A copybook from z/OS has a 05-level layout one byte larger than the area it redefines. What does GnuCOBOL 3.2 do with it?

    Choose one answer.

    Show the answer: Question 9 of 12

    Answer: It refuses it in the default dialect and accepts it with a warning under -std=ibm

    IBM allows a redefining item larger than its area; GnuCOBOL's default dialect does not, below level 01. Building shared copybooks under the dialect of their target finds such differences early.

  10. Question 10 of 12 Which level number does a RENAMES entry use, and where does it go?

    Choose one answer.

    Show the answer: Question 10 of 12

    Answer: Level 66, right after the last entry of its record

    renames.cob put its two 66-level entries right after POST-CODE, the last entry of ADDR-REC.

  11. Question 11 of 12 What did MOVE SPACES TO STREET-LINE change in ADDR-REC?

    Choose one answer.

    Show the answer: Question 11 of 12

    Answer: HOUSE-NO and STREET, the 18 bytes STREET-LINE names

    A RENAMES name is another way into the same bytes: writing through it changes the items it names, and only them.

  12. Question 12 of 12 A colleague writes 66 WHOLE-REC RENAMES ADDR-REC to get a second name for the whole record. What is wrong?

    Choose one answer.

    Show the answer: Question 12 of 12

    Answer: RENAMES cannot rename an 01-level entry; the record already has its name

    RENAMES regroups items inside a record. A second name for a whole record is better given by REDEFINES at level 01 or simply not needed.

Add a record type

Add a layout to records.cob for a type R, a reversal, with an account number and an amount, and a condition name IS-REVERSAL on REC-TYPE. Add a WHEN for it, move a record such as RAC0417000025000 into TXN-REC, and build it with cobc -x records.cob && ./records: the Q record must still be rejected.

Interview questions

Warm-up (fresher to 2–5 years): what is a level-88 condition name, and what does SET … TO TRUE store?

A condition name is a level-88 entry that gives a name to one value, a list of values or a THRU range of the data item above it, so IF ACCT-OPEN means that ACCT-STATUS holds one of the values of ACCT-OPEN. It makes a test read as its meaning and keeps the codes in one place, so a new code is added to one VALUE clause instead of every IF. SET ACCT-OPEN TO TRUE stores a value in the variable, and when the condition name lists several values it stores the first one: ACCT-OPEN with VALUE “A” “D” stores A. SET … TO FALSE needs a WHEN SET TO FALSE phrase on the 88-level entry, which names the value to store; without it, GnuCOBOL refused the program with field does not have a FALSE clause.

Two questions apply these ideas to batch work: totals that drift without an error, and a status code that many programs test. Decide your first move before you read each first step:

Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.

  1. Mid to senior

    A batch program reads a file of header, detail and trailer records through REDEFINES. Its control totals no longer match the trailer, yet no record is rejected and nothing fails. How do you find the cause, and how do you make the program fail loudly next time?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Mid to senior

    A new account status, F for frozen, must count as open in most checks but block withdrawals. The status field is tested in 40 programs. How do condition names help, what can still go wrong, and how do you roll the change out?

    Model answer, Pro. First step and follow-ups

Organisations named on this page

This page is MySmartCoPilot’s own and has no connection with IBM or the GnuCOBOL project. It quotes IBM’s Language Reference on condition names, REDEFINES and RENAMES, and shows what GnuCOBOL 3.2 printed.

Flashcards · 8 cards

Recall it, then check

Say the answer to yourself before you look: recalling it is what makes it stick.

  1. What is a level-88 condition name?

    An entry under a data item that names one of its values, a list of them or a THRU range. IF ACCT-OPEN is true when ACCT-STATUS holds any value listed for ACCT-OPEN.

  2. Does a THRU range of a condition name include its end values?

    Yes. With VALUE 31 THRU 90, a count of exactly 90 makes the condition true.

  3. ACCT-OPEN has VALUE "A" "D". What does SET ACCT-OPEN TO TRUE store?

    A, the first value listed. Put the most usual code first.

  4. Why might SET END-OF-FILE TO FALSE fail to compile?

    Setting a condition name false needs a WHEN SET TO FALSE phrase on its 88-level entry to name the value to store. Without one, GnuCOBOL refuses with "field does not have a FALSE clause".

  5. What does REDEFINES do?

    It describes the same storage again with another layout, such as a header, a detail and a trailer view of one record body. A redefining entry and everything under it may have no VALUE clause.

  6. What happens when a record is read through the wrong REDEFINES layout?

    Nothing warns you: the bytes do not know which layout wrote them, so the fields simply hold wrong data. Test the type byte, best with a condition name, before reading any layout.

  7. Does GnuCOBOL accept a REDEFINES larger than the area it redefines?

    Not below level 01 in its default dialect, which stops with "larger REDEFINES used". Under -std=ibm it warns and compiles, as IBM's compiler allows it.

  8. What is a level-66 RENAMES entry?

    Another name for one elementary item, or for a run of consecutive items with THRU, written after the last entry of its record. STREET-LINE RENAMES HOUSE-NO THRU STREET behaves like a group of the two.

Key takeaways

  • A level-88 condition name stands for one value, a list or a THRU range of its variable, ends included, so IF ACCT-OPEN replaces the comparisons with A and D and a new code changes one VALUE clause.
  • SET … TO TRUE stores the first value of a condition name, C for ACCT-CLOSED, and SET … TO FALSE stores the value of its WHEN SET TO FALSE phrase, which must be there.
  • REDEFINES describes the same bytes several ways, with a type byte to choose the layout; a record read through the wrong layout gives wrong data without an error.
  • GnuCOBOL refuses a REDEFINES larger than its area below level 01 by default, while IBM’s compiler allows it.
  • A level-66 RENAMES entry names an item, or a run of items with THRU, after the record’s last entry, as STREET-LINE named HOUSE-NO and STREET.

Terms in this lesson

condition name
A level-88 entry that names a value, a list of values or a THRU range of the item above it, so that IF ACCT-OPEN tests that item against them.
conditional variable
The data item a level-88 condition name belongs to: the item whose value the condition tests and SET ... TO TRUE changes.
REDEFINES
A clause that describes the storage of an earlier item a second way, so the same bytes can be read as different fields. Nothing checks which description fits the data.
RENAMES
A level-66 entry that gives a new name to one elementary item or to a run of consecutive items of a record. It is written after the record's last entry.

References

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.