Chapter 15. SINGLE-LEVEL ARRAYS AND TABLES

CHAPTER OBJECTIVES

Upon completion of this chapter, you should be able to

  • Establish a series of items using an OCCURS clause.

  • Access and manipulate data stored in an array or table.

  • Explain the rules for using an OCCURS clause in the DATA DIVISION.

  • Explain and demonstrate how an index or subscript is used with an array.

  • Demonstrate the use of a SEARCH and SEARCH ALL for a table look-up.

AN INTRODUCTION TO SINGLE-LEVEL OCCURS CLAUSES

WHY OCCURS CLAUSES ARE USED

We use an OCCURS clause to indicate the repeated occurrence of fields with the same format. Some of the uses of an OCCURS clause include:

  1. Defining a series of input or output fields, each with the same format.

  2. Defining a series of totals in WORKING-STORAGE to which amounts are added. After all data is accumulated, the totals can be printed.

  3. Defining a table in WORKING-STORAGE to be accessed by each input record. With a table, we use the contents of some input field to "look up" the required data in the table.

DEFINING FIELDS WITH AN OCCURS CLAUSE

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, defining the input record with 24 independent hourly fields would prove cumbersome:

DEFINING FIELDS WITH AN OCCURS CLAUSE

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

Get PROGRAMMING IN COBOL/400: 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.