COBOL: Nested PERFORM VARYING

In Cobol, to perform loops you will use PERFORM VARYING. The perform within the perform you can say Nested Perform. You need Perform Varying to get data from two dimensional array. Here are my the best examples for Perform varying.

Ex:

PERFORM 200-MAJOR-RTN VARYING CTR1 FROM 1 BY 1 UNTIL CTR1 > 10     
PERFORM 300-CALC-RTN VARYING CTR2 FROM 1 BY 1 UNTIL CTR2 > 20

You can find very intersting things in this book-Buy Today . First inner loop will execute and later Outer loop will execute.

Alternative way is, in simple Perform:

PERFORM CTR1 FROM 1 BY 1 UNTIL CTR1 > 10
AFTER CTR2 FROM 1 BY 1 UNTIL CTR2 > 20
....
....
END-PERFORM

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.