COBOL PERFORM WITH TEST AFTER
PERFORM WITH TEST AFTER UNTIL
The following COBOL program depicts the use of
PERFORM WITH TEST AFTER UNTIL
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM017.
AUTHOR. MAINFRAMEWIZARD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-SUB PIC 9 VALUE ZEROS.
PROCEDURE DIVISION.
10000-MAIN-PARA.
MOVE 5 TO WS-SUB.
PERFORM 20000-FIRST-PARA WITH TEST AFTER UNTIL WS-SUB=5
DISPLAY 'PARA NAME IS 10000-FIRST-PARA'
STOP RUN.
20000-FIRST-PARA.
DISPLAY 'VALUE OF WS-SUB IS = ' WS-SUB.
ADD +1 TO WS-SUB.
The ouput of the above COBOL program is
VALUE OF WS-SUB IS = 5
VALUE OF WS-SUB IS = 6
VALUE OF WS-SUB IS = 7
VALUE OF WS-SUB IS = 8
VALUE OF WS-SUB IS = 9
VALUE OF WS-SUB IS = 0
VALUE OF WS-SUB IS = 1
VALUE OF WS-SUB IS = 2
VALUE OF WS-SUB IS = 3
VALUE OF WS-SUB IS = 4
PARA NAME IS 10000-FIRST-PARA
Note:- Here since WS-SUB is a single byte (defined as PIC 9) so once the value
is reached to 10 it could store only the zero in it (since numeric moves are right
justfied before decimal). Thus the value is again incremented from zero and thus ends the
loop.
Imagine what would happen in the above case if WS-SUB is defined as PIC 99 ??
Would it loop forever? ...Try it yourself