Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/38489

From BetaArchive Wiki

Examples of Subscripting Two-Dimensional Tables (Arrays)

PSS ID Number: Q38489 Article last modified on 04-20-1993

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

The information in this article applies to:
- Microsoft COBOL for MS-DOS and OS/2, versions 3.0 and 3.0a

Summary: The code examples below demonstrate correct syntax for using a two-dimensional table (that is, an array) in Microsoft COBOL versions 3.0 and 3.0a. This is standard ANSI COBOL syntax. Up to seven dimensions are allowed under the ANS85 directive; 16 dimensions are allowed, otherwise. Tables may be indexed instead of subscripted, and the OCCURS clause can be modified with an ASCENDING/DESCENDING clause and/or a DEPENDING ON clause. See Page 4-1 in the “Microsoft COBOL Compiler 3.0: Language Reference Manual” for details.

More Information:

Example 1

In the example below, the table is an array of five rows (occurs five times) by six columns (occurs six times). Each of the 30 (five times six) elements of the array has a PICTURE clause of S9(5)V99 as shown in the lowest level of the data item. The table is referenced by the name in the level below the last OCCURS clause. Subscripts may be any integer value 1 or higher. DATA DIVISION. WORKING-STORAGE SECTION. 01 TOP-LEVEL VALUE ZEROS. 05 ROW-OF-x OCCURS 5 TIMES. 10 COLUMN-OF-x OCCURS 6 TIMES. 15 TABLE-NAME PIC S9(5)V99. 01 ROW-SUBSCRIPT PIC 99 VALUE 2. 01 COL-SUBSCRIPT PIC 99 VALUE 3. PROCEDURE DIVISION. MAIN. MOVE +999 TO TABLE-NAME (ROW-SUBSCRIPT, COL-SUBSCRIPT). DISPLAY TABLE-NAME (ROW-SUBSCRIPT, COL-SUBSCRIPT). STOP RUN.

Example 2

This is an example of a loop construct (using nested PERFORM statements) that uses a two-dimensional table (array): DATA DIVISION. WORKING-STORAGE SECTION. 01 totals. 05 deptx OCCURS 20 TIMES. 10 areax OCCURS 10 TIMES PIC 999. 01 counter PIC 99. 01 step PIC 99. 01 screen-location. 05 vert PIC 99. 05 horiz PIC 99. SCREEN SECTION. 01 blank-screen. 05 BLANK SCREEN. PROCEDURE DIVISION. 000-main-paragraph. DISPLAY blank-screen. MOVE 0 TO counter. MOVE 1 TO vert. PERFORM 100-assign-deptx 20 TIMES. PERFORM 300-print-array. STOP RUN. 100-assign-deptx. MOVE 1 TO step. ADD 1 TO counter PERFORM 200-assign-areax 10 TIMES. 200-assign-areax. MOVE step TO areax(counter,step). ADD 1 TO step. 300-print-array. MOVE 0 TO counter. MOVE 1 TO step. PERFORM 400-inner-loop 20 TIMES. 400-inner-loop. ADD 1 TO counter. MOVE 1 TO step. ADD 1 TO vert. MOVE 1 to horiz. PERFORM 500-inner-inner-loop 10 TIMES. 500-inner-inner-loop. DISPLAY areax(counter,step) AT screen-location. ADD 1 TO step. ADD 4 TO horiz.

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.