Chapter 9. ITERATION: BEYOND THE BASIC PERFORM

CHAPTER OBJECTIVES

Upon completion of this chapter, you should be able to

  • Explain the term "iteration."

  • Describe and demonstrate the various formats of the PERFORM statement for iteration.

THE SIMPLE PERFORM REVIEWED

The simple PERFORM statement executes a specified routine from one or more points in a program. This topic was introduced earlier in the book but is discussed in more detail here. The format of the basic PERFORM statement is

Basic Instruction Format:

THE SIMPLE PERFORM REVIEWED

Examine the 000-MAIN-MODULE module in the following COBOL program excerpt.

THE SIMPLE PERFORM REVIEWED

The PERFORM statement in the 000-MAIN-MODULE will

  1. Branch from 000-MAIN-MODULE and execute all instructions in the 100-INITIALIZATION-RTN module.

  2. Transfer control back to the next instruction in sequence, after the PERFORM.

A simple PERFORM statement is used whenever a series of instructions in a particular paragraph is to be executed from a different location or locations in the program.

Another example of this is the reading of a record from the file that will control the main processing of the program. Most often, the READ operation is specified in more than one location in the program. In the example above, the PERFORM 23 0-READ-EMPLOYEE-RECORD-RTN module is executed from two different locations in the program. In ...

Get PROGRAMMING IN COBOL/400: 2nd Edition 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.