Microsoft KB Archive/63041

Can’t Pass Parameters to WORKING-STORAGE of INITIAL Programs

PSS ID Number: Q63041 Article last modified on 06-20-1990

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

Summary: When parameters are passed from one COBOL program to another, and those parameters are declared in the WORKING-STORAGE (not LINKAGE) SECTION of the called program, the INITIAL clause must not be used in the PROGRAM-ID of that program. If it is, the passed parameters will be initialized just like any local variables of the program. To prevent the parameters from being initialized when using the INITIAL clause and still pass them by value, the BY CONTENT clause must be used in the CALL statement that invokes the called program, and the parameters must be declared in the LINKAGE SECTION. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: Parameters can be declared in the WORKING-STORAGE SECTION of a called program to pass them by value. If this method is used, however, the parameters will be initialized along with any locally declared variables if the INITIAL clause is used in the PROGRAM-ID paragraph. To prevent the passed parameters from being initialized, they must be declared in the LINKAGE SECTION and passed BY CONTENT from the calling program. For more information on passing parameters with CALL and the INITIAL clause, see Chapter 10, “Inter-Program Communication,” of the “Microsoft COBOL Compiler 3.0: Language Reference Manual” for versions 3.00 and 3.00a. The following sample programs illustrate how to do this. The program MAIN calls the program SUB and passes it a PIC X field initialized to “A”. SUB is an INITIAL program but the parameter passed to it will not be initialized because it is declared in the LINKAGE SECTION. The BY CONTENT clause in the CALL statement of MAIN will cause the value of the parameter, rather than the address, to be passed. Compile and LINK as follows: COBOL MAIN.CBL ; COBOL SUB.CBL ; LINK MAIN ; LINK SUB ; The following is MAIN.CBL: $SET VSC2 IDENTIFICATION DIVISION. PROGRAM-ID. MAIN. DATA DIVISION. WORKING-STORAGE SECTION. 01 DataItem PIC X VALUE “A”. PROCEDURE DIVISION. CALL “SUB” USING BY CONTENT DataItem. STOP RUN. The following is SUB.CBL: IDENTIFICATION DIVISION. PROGRAM-ID. SUB IS INITIAL. DATA DIVISION. LINKAGE SECTION. 01 Parameter PIC X. PROCEDURE DIVISION USING Parameter. DISPLAY Parameter. EXIT PROGRAM. The output is as follows: “A”

Copyright Microsoft Corporation 1990.