Outline Perform Times Example


Scenario - Displaying loop iterations using outline PERFORM..TIMES.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. PERFOTIM.
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-I         PIC 9(1) VALUE 1.

       PROCEDURE DIVISION.
           DISPLAY "Before outline PERFORM...TIMES".
           PERFORM 1000-CALCULATE
              THRU 1000-EXIT
                 6 TIMES.
           DISPLAY "After outline PERFORM...TIMES". 
           STOP RUN.

       1000-CALCULATE.
           DISPLAY "Iteration: " WS-I.
           COMPUTE WS-I = WS-I + 1.
       1000-EXIT.
           EXIT.

Output -

Before Inline PERFORM...TIMES
Iteration: 1
Iteration: 2
Iteration: 3
Iteration: 4
Iteration: 5
Iteration: 6
After Inline PERFORM...TIMES

Explaining Example -

In the above example:

  • It is a outline PERFORM that iterates 1000-CALCULATE paragraph 6 times.
  • It displays the iteration number each time before incrementing it.