Microsoft KB Archive/40550
The DEPENDING ON Clause Always Allocates the Maximum Elements
PSS ID Number: Q40550 Article last modified on 04-20-1993
3.00 | 3.00 MS-DOS | OS/2
|The information in this article applies to:|
|- Microsoft COBOL for MS-DOS and OS/2, version 3.0|
Summary: Microsoft COBOL Version 3.0 will always allocate the maximum number of elements needed for an array. A block of memory sufficient to hold the entire array will be allocated despite the presence of a DEPENDING ON clause or the ODOSLIDE compiler directive. The DEPENDING ON clause is designed to provide the ability to change the size of an array, giving the means to create a “dynamic” table which could be redimensioned to manage memory. However, in the COBOL Version 3.0 compiler, the size of a table will not change when the data item in the DEPENDING ON clause is changed. Microsoft has tested and verified this problem with COBOL Version 3.0. This problem has been corrected in COBOL Version 3.0a.
More Information: The ODOSLIDE directive is used to provide the ability of having these dynamic tables. However, despite the ODOSLIDE directive, the maximum amount for the table will always be allocated, and subordinate items in the record do not change position and are not corrupted if the value in the DEPENDING ON variable is changed. On Page 4-3 of the “Microsoft COBOL Version 3.0: Language Reference Manual,” SYNTAX RULE #7 states that if the ODOSLIDE compiler directive is used, data items that are in the same record as the array will change position if the value of the item in the DEPENDING ON clause is changed. The rule warns that these subordinate items may be corrupted, implying that the table actually changes size and that subordinate items in the record actually “slide” or change position – thus “ODOSLIDE”. The rule also states that if NOODOSLIDE is used, the maximum number of items will be allocated for a table. Compile and LINK the following code example program without a COBOL.DIR file: $set nobound $set ans85 $set odoslide identification division. program-id. cobarray. environment division. data division. working-storage section. 01 string-array. 05 NumberOfElements pic 99. 05 array pic x(5) occurs 1 to 20 times depending on NumberOfElements. 05 my-name pic x(5). 01 array-index pic 99. procedure division. main. move 10 to NumberOfElements. move 10 to array-index. move “hello” to array(array-index). move “Steve” to my-name. * This should place “hello” in array element 10 * and my name in element “11” just past the end. * however, my-name is always in the next position * past the end of the maximum size of the array–21. * This should corrupt MY-NAME by expanding the array. move 13 to NumberOfElements. * This shows that MY-NAME is in position 21. move 21 to array-index. display array(array-index). stop run.
Additional reference words: 3.00 Copyright Microsoft Corporation 1993.