Microsoft KB Archive/62949

Using Both WORKING-STORAGE & LINKAGE to Pass Parameters Fails

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

3.00 3.00a MS-DOS

Summary: When passing parameters between two COBOL programs that are statically or dynamically linked and the CALLed program declares one or more of the parameters in the WORKING-STORAGE SECTION and one or more of them in the LINKAGE SECTION, the parameters declared in WORKING-STORAGE will be corrupted. If the parameters are declared only in WORKING-STORAGE or LINKAGE, the data is passed properly. 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. This problem has been corrected in Microsoft COBOL Professional Development System version 4.0 for MS-DOS and MS OS/2.

More Information: The following sample programs illustrate the problem. The program MAIN calls the program SUB, passing it two PIC X parameters. When SUB displays the parameters, the one declared in the WORKING-STORAGE SECTION will be corrupted while the one declared in the LINKAGE SECTION will transfer correctly. Compile and link the programs for DOS as follows: cobol main; cobol sub; link main sub; Compile and link the programs for OS/2 as follows: pcobol main; pcobol sub; link /nop main sub,,,pcobol doscalls; The following is MAIN.CBL: IDENTIFICATION DIVISION. PROGRAM-ID. MAIN. DATA DIVISION. WORKING-STORAGE SECTION. 01 Data1 PIC X VALUE “A”. 01 Data2 PIC X VALUE “B”. PROCEDURE DIVISION. DISPLAY Data1 Data2. CALL “SUB” USING Data1, Data2. DISPLAY Data1 Data2. STOP RUN. The following is SUB.CBL: IDENTIFICATION DIVISION. PROGRAM-ID. SUB. DATA DIVISION. WORKING-STORAGE SECTION. 01 Data1 PIC X. LINKAGE SECTION. 01 Data2 PIC X. PROCEDURE DIVISION USING Data1, Data2. DISPLAY Data1 Data2. EXIT PROGRAM. The following is the output: AB nB AB Here, “n” represents a random ASCII character. Note that only the parameter declared in the WORKING-STORAGE SECTION of SUB is corrupted. If BOTH parameters are declared in the WORKING-STORAGE or LINKAGE SECTIONs, the output will be correct: AB AB AB

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