Perform varying best examples explained in this post. These are top ideas to work with COBOL Tables or Arrays.
1). How to Use OCCURS depending ON. The best example to create a variable array:
01 ORG-LIMIT PIC 99 COMP VALUE 50. 01 DIVISION-NAME-TABLE. 05 DIVISION-ENTRY OCCURS 1 TO 50 TIMES DEPENDING ON ORG-LIMIT INDEXED BY DIV-IX. 10 DIVISION-CODE PIC X(5). 10 DIVISION-NAME PIC X(30).
2). How to Use Perform VARYING…AFTER in Multidimensional Tables
The AFTER clause of the PERFORM…The VARYING statement was designed specifically to support multidimensional tables in COBOL. It pre-dates the inline PERFORM statement (which was added with the 1985 Standard):
a). How to Use Perform…Varying
PERFORM VARYING ROW-NR FROM 3 BY 2 UNTIL ROW-NR > 9 PERFORM VARYING COL-NR FROM 12 BY 2 UNTIL COL-NR > 18 ADD 1 TO CTR MOVE CTR TO SCREEN-CHAR (ROW-NR COL-NR).
b). How to Use Perform…Varying…After
PERFORM VARYING ROW-NR FROM 3 BY 2 UNTIL ROW-NR > 9 AFTER COL-NR FROM 12 BY 2 UNTIL COL-NR > 18 ADD 1 TO CTR MOVE CTR TO SCREEN-CHAR (ROW-NR COL-NR).
In the above logic ROW-NR and COL-NR are two indexed/subscripts referencing two arrays. So, the above PERFORM statement work for multi dimensional Table.
3). How to initialize or increment or decrement of an Index
SET index TO positive integer
Example: SET IX-1 to 1; (For initialization)
SET IX-1 UP BY 1; (For increment) SET IX-1 DOWN BY 1; (For decrement)
How to initialize or increment or decrement of a Subscript:
Examples:
MOVE 1 TO SUB-1 (For initialization) ADD 1 TO SUB-1 (For increment) SUBTRACT 1 FROM SUB-1 (For decrement)
Related Posts