Microsoft KB Archive/60853

Can’t Pass Data by Value with Nested Programs

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

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

Summary: In Microsoft COBOL versions 3.0 and 3.0a, a data item is passed to called programs by value (not reference) if it is defined in the WORKING-STORAGE SECTION (as opposed to the LINKAGE SECTION) of the called program. However, this method does not work when calling nested programs. In this case, the data items are treated as local WORKING-STORAGE variables of the called program. Microsoft has confirmed this to be a problem in Microsoft COBOL Compiler versions 3.0 and 3.0a for MS-DOS and MS OS/2. When the following code (MAIN2.CBL) is compiled with Microsoft COBOL Professional Development System version 4.0, the following error message occurs: 21 PROCEDURE DIVISION USING DATA-ITEM. * 343-S*********************************   Should be declared in LINKAGE SECTION This error will prevent you from encountering the problem described because the code will not compile. Microsoft has confirmed this to be a problem in version 4.0. We are researching this problem and will post new information here as it becomes available.

More Information: If the program being called and the program doing the calling are linked together as separate .OBJ files, the above method of passing data items by value works correctly. The following sample programs illustrate this. The program MAIN1.CBL calls SUB1.CBL and passes a data item to it. The data will be passed by value because SUB1.CBL defines the data item in its WORKING-STORAGE SECTION, not in the LINKAGE section. Compile and link the programs as follows: COBOL MAIN1; COBOL SUB1; LINK MAIN1 SUB1; The following is MAIN1.CBL: IDENTIFICATION DIVISION. PROGRAM-ID. MAIN1. DATA DIVISION. WORKING-STORAGE SECTION. 01 DATA-ITEM PIC 9 VALUE 4. PROCEDURE DIVISION. DISPLAY DATA-ITEM. CALL “SUB1” USING DATA-ITEM. DISPLAY DATA-ITEM. STOP RUN. The following program is SUB1.CBL: IDENTIFICATION DIVISION. PROGRAM-ID. SUB1. DATA DIVISION. WORKING-STORAGE SECTION. * Data item is defined in WORKING-STORAGE to pass by value 01 DATA-ITEM PIC 9. PROCEDURE DIVISION USING DATA-ITEM. DISPLAY DATA-ITEM. COMPUTE DATA-ITEM = DATA-ITEM + 3. DISPLAY DATA-ITEM. EXIT PROGRAM. The output of MAIN1.EXE would be the following: 4 4 7 4 The following sample program illustrates the problem when using nested programs. The program SUB1.CBL is nested inside MAIN2.CBL. MAIN2.CBL passes a data item to SUB1.CBL that should be passed by value because it is declared in the WORKING-STORAGE SECTION of SUB1.CBL, not in the LINKAGE SECTION. However, no value is passed, and the data item in SUB1.CBL is initialized to a space. Compile and link the program as follows: COBOL MAIN2; LINK MAIN2; The following is MAIN2.CBL: $SET NESTCALL IDENTIFICATION DIVISION. PROGRAM-ID. MAIN2. DATA DIVISION. WORKING-STORAGE SECTION. 01 DATA-ITEM PIC 9 VALUE 4. PROCEDURE DIVISION. DISPLAY DATA-ITEM. CALL “SUB2” USING DATA-ITEM. DISPLAY DATA-ITEM. STOP RUN. IDENTIFICATION DIVISION. PROGRAM-ID. SUB2. DATA DIVISION. * Data item is declared in WORKING-STORAGE to pass by value WORKING-STORAGE SECTION. 01 DATA-ITEM PIC 9. PROCEDURE DIVISION USING DATA-ITEM. DISPLAY DATA-ITEM. COMPUTE DATA-ITEM = DATA-ITEM + 3. DISPLAY DATA-ITEM. EXIT PROGRAM. END PROGRAM SUB2. END PROGRAM MAIN2. The output of MAIN2.EXE would be the following: 4 3 4 Because DATA-ITEM does not have an initial value in SUB2.CBL, it does not DISPLAY a value, only a space.

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