Microsoft KB Archive/62263

COBOL Cannot Pass Variable-Length Table

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

3.00 3.00a MS-DOS

Summary: In Microsoft COBOL versions 3.0 and 3.0a, there is a problem with passing variable-length tables through the LINKAGE SECTION to a subroutine. When trying to pass a variable-length table, you may get run-time error 153 (“subscript out of range”). A variable-length table is defined by the following syntax in WORKING-STORAGE: OCCURS 1 to n TIMES DEPENDING ON clause Microsoft has confirmed this to be a problem in Microsoft COBOL versions 3.0 and 3.0a. This problem has been corrected in Microsoft COBOL Professional Development System version 4.0.

More Information: The following two programs demonstrate this problem. Match01 and Match02 should be compiled and linked as follows: COBOL Match01; LINK Match01; COBOL Match02; LINK Match02;

Code Example
IDENTIFICATION DIVISION. PROGRAM-ID. MATCH01. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 REGION-COUNT                PIC 9999. 01 ENTRY-COUNT                 PIC 9999. 01 DICTIONARY-TABLE. 05 ONE-DICTIONARY-ENTRY    OCCURS 1 TO 2000 TIMES DEPENDING ON ENTRY-COUNT ASCENDING KEY IS LOOK-UP-WORD INDEXED BY WORD-INDEX. 10 A-LIST-OF-WORDS. 15 LOOK-UP-WORD         PIC X(15). 15 EXPANDED-WORD        PIC X(30). 01 REGIONAL-DICTIONARY-TABLE. 05 REGION-DICTIONARY-ENTRY OCCURS 1 TO 2000 TIMES DEPENDING ON REGION-COUNT ASCENDING KEY IS REGIONAL-WORD INDEXED BY REGION-INDEX. 10 A-LIST-OF-REGIONAL-WORDS. 15 REGIONAL-WORD        PIC X(15). 15 TRANSLATED-WORD      PIC X(30). 01 NAME-TO-EXPAND            PIC X(35). 01 RETURNED-EXPANSION        PIC X(60). PROCEDURE DIVISION. 0000-CONTROLLING-PARAGRAPH. MOVE 2000 TO ENTRY-COUNT. MOVE 2000 TO REGION-COUNT. CALL &quot;MATCH02&quot; USING REGION-COUNT ENTRY-COUNT DICTIONARY-TABLE REGIONAL-DICTIONARY-TABLE NAME-TO-EXPAND RETURNED-EXPANSION. STOP RUN. ——–x——–x———x———x———x——–x——— IDENTIFICATION DIVISION. PROGRAM-ID. MATCH02. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. LINKAGE SECTION. 01 REGION-COUNT PIC 9999. 01 ENTRY-COUNT PIC 9999. 01 DICTIONARY-TABLE. 05 DICTIONARY-ENTRIES OCCURS 1 TO 2000 TIMES DEPENDING ON ENTRY-COUNT ASCENDING KEY IS LOOK-UP-WORD INDEXED BY WORD-INDEX. 10 A-LIST-OF-WORDS. 15 LOOK-UP-WORD PIC X(15). 15 EXPANDED-WORD PIC X(30). 01 REGIONAL-DICTIONARY-TABLE. 05 REGIONAL-ENTRIES OCCURS 1 TO 2000 TIMES DEPENDING ON REGION-COUNT ASCENDING KEY IS REGIONAL-WORD INDEXED BY REGION-INDEX. 10 REGIONAL-WORD-LIST. 15 REGIONAL-WORD PIC X(15). 15 TRANSLATION PIC X(30). 01 NAME-TO-EXPAND PIC X(35). 01 RETURN-EXPANDED-NAME PIC X(60). PROCEDURE DIVISION USING REGION-COUNT ENTRY-COUNT DICTIONARY-TABLE REGIONAL-DICTIONARY-TABLE NAME-TO-EXPAND RETURN-EXPANDED-NAME. 0000-CONTROLLING-PARAGRAPH. DISPLAY “IN EXPANSION”. EXIT PROGRAM. ———-x————–x—————-x———————x– * This is the working version of the program. It simply * changes the variable length array to a fixed length array. IDENTIFICATION DIVISION. PROGRAM-ID. MATCH01. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 REGION-COUNT PIC 9999. 01 ENTRY-COUNT PIC 9999. 01 DICTIONARY-TABLE. * CHANGE THIS: 05 ONE-DICTIONARY-ENTRY OCCURS 1 TO 2000 TIMES * TO THIS: 05 ONE-DICTIONARY-ENTRY OCCURS 2000 TIMES * DELETE THIS: DEPENDING ON ENTRY-COUNT ASCENDING KEY IS LOOK-UP-WORD INDEXED BY WORD-INDEX. 10 A-LIST-OF-WORDS. 15 LOOK-UP-WORD PIC X(15). 15 EXPANDED-WORD PIC X(30). 01 REGIONAL-DICTIONARY-TABLE. * CHANGE THIS: 05 REGION-DICTIONARY-ENTRY OCCURS 1 TO 2000 TIMES * TO THIS: 05 REGION-DICTIONARY-ENTRY OCCURS 2000 TIMES * DELETE THIS: DEPENDING ON REGION-COUNT ASCENDING KEY IS REGIONAL-WORD INDEXED BY REGION-INDEX. 10 A-LIST-OF-REGIONAL-WORDS. 15 REGIONAL-WORD PIC X(15). 15 TRANSLATED-WORD PIC X(30). 01 NAME-TO-EXPAND PIC X(35). 01 RETURNED-EXPANSION PIC X(60). PROCEDURE DIVISION. 0000-CONTROLLING-PARAGRAPH. MOVE 2000 TO ENTRY-COUNT. MOVE 2000 TO REGION-COUNT. CALL “MATCH02” USING REGION-COUNT ENTRY-COUNT DICTIONARY-TABLE REGIONAL-DICTIONARY-TABLE NAME-TO-EXPAND RETURNED-EXPANSION. STOP RUN. ——–x——–x———–x———–x———x——–x—— * This is the working version of the program. It simply * changes the variable length array to a fixed length array. IDENTIFICATION DIVISION. PROGRAM-ID. MATCH02. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. LINKAGE SECTION. 01 REGION-COUNT PIC 9999. 01 ENTRY-COUNT PIC 9999. 01 DICTIONARY-TABLE. * CHANGE THIS: 05 DICTIONARY-ENTRIES OCCURS 1 TO 2000 TIMES * TO THIS: 05 DICTIONARY-ENTRIES OCCURS 2000 TIMES * DELETE THIS: DEPENDING ON ENTRY-COUNT ASCENDING KEY IS LOOK-UP-WORD INDEXED BY WORD-INDEX. 10 A-LIST-OF-WORDS. 15 LOOK-UP-WORD PIC X(15). 15 EXPANDED-WORD PIC X(30). 01 REGIONAL-DICTIONARY-TABLE. * CHANGE THIS: 05 REGIONAL-ENTRIES OCCURS 1 TO 2000 TIMES * TO THIS: 05 REGIONAL-ENTRIES OCCURS 2000 TIMES * DELETE THIS: DEPENDING ON REGION-COUNT ASCENDING KEY IS REGIONAL-WORD INDEXED BY REGION-INDEX. 10 REGIONAL-WORD-LIST. 15 REGIONAL-WORD PIC X(15). 15 TRANSLATION PIC X(30). 01 NAME-TO-EXPAND PIC X(35). 01 RETURN-EXPANDED-NAME PIC X(60). PROCEDURE DIVISION USING REGION-COUNT ENTRY-COUNT DICTIONARY-TABLE REGIONAL-DICTIONARY-TABLE NAME-TO-EXPAND RETURN-EXPANDED-NAME. 0000-CONTROLLING-PARAGRAPH. DISPLAY “IN EXPANSION”. EXIT PROGRAM.

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