Chapter 12. Array Processing and Table Handling

OBJECTIVES

To familiarize you with

  1. How to establish a series of items using an OCCURS clause.

  2. How to access and manipulate data stored in an array or table.

  3. The rules for using an OCCURS clause in the DATA DIVISION.

  4. The use of a SEARCH or SEARCH ALL for a table look-up.

AN INTRODUCTION TO SINGLE-LEVEL OCCURS CLAUSES

Why OCCURS Clauses Are Used

We use an OCCURS clause in COBOL to indicate the repeated occurrence of fields with the same format. We will focus first on some uses of an OCCURS clause:

Using an OCCURS to Define a Series of Input Fields Each with the Same Format

Defining Fields with an OCCURS Clause

Example

Suppose we have one 72-character input record that consists of 24 hourly temperature fields. Each field is three positions long and indicates the temperature for a given city at a particular hour. Using traditional methods, coding the input record with 24 independent hourly fields would prove cumbersome:

01           TEMP-REC.
      05  ONE-AM       PIC S9(3).
      05  TWO-AM       PIC S9(3).
      .                .
      .                .
      .                .
      05  MIDNIGHT     PIC S9(3).

24 entries

We use the S in the PIC clause for cities in which ...

Get COBOL for the 21st Century now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.