Outline Perform Varying Example


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

Code -

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

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

       PROCEDURE DIVISION. 

           DISPLAY "Before PERFORM VARYING".
           PERFORM 1000-ITERATION
              THRU 1000-EXIT
           VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 6.
           DISPLAY "After PERFORM VARYING".

           STOP RUN.

       1000-ITERATION.
           DISPLAY "WS-I: " WS-I.
       1000-EXIT.
           EXIT.

Output -

Before PERFORM VARYING
WS-I: 1
WS-I: 2
WS-I: 3
WS-I: 4
WS-I: 5
WS-I: 6
After PERFORM VARYING 

Explaining Example -

In the above example:

  • It is a outline PEFORM VARYING loop that iterates the loop until WS-I greater than 6.
  • It displays the iteration number, increment will be done by PERFORM and no special increment is required.