Microsoft KB Archive/43532

Use EXTERNAL Clause in WORKING-STORAGE for Passing Data Items

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

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

Summary: The EXTERNAL clause in the WORKING-STORAGE SECTION can be used to pass data items between COBOL programs communicating through the CALL Statement. EXTERNAL is an ANSI 85 standard. If a data item is EXTERNAL, it does not need to be included in the LINKAGE SECTION and it is not passed as a parameter in the CALL USING statement.

More Information: To make a data item external, the EXTERNAL clause needs to be included for the data item in every program that will use the variable. The syntax of the EXTERNAL clause is on Page 10-26 of the “Microsoft COBOL Compiler Version 3.0: Language Reference Manual.” The external support routine, EXTERNL.OBJ, must be used with programs that use external data. This routine needs to be LINKed to the main program or separately LINKed and available on disk for dynamic calling (EXTERNL.EXE). The EXTERNAL clause cannot be used to communicate between CHAINed programs or between NESTED programs. To communicate with NESTED programs, you must use the GLOBAL clause. The following programs demonstrate the EXTERNAL clause. PROGRAM1 CALLs PROGRAM2, and they have the data item PASSED-VAR in common through the EXTERNAL clause. Use the COBOL directive ANS85 when compiling the following: COBOL PROGRAM1.CBL /ANS85; COBOL PROGRAM2.CBL /ANS85; LINK EXTERNL: LINK PROGRAM1; LINK PROGRAM2; Program 1, the main program: IDENTIFICATION DIVISION. PROGRAM-ID. PROGRAM1. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 PASSED-VAR EXTERNAL PIC x(30). PROCEDURE DIVISION. 000-MAIN. MOVE “PASS WAS SUCCESSFUL” TO PASSED-VAR. CALL “PROGRAM2”. DISPLAY “END OF PROGRAM.”. STOP RUN. Program 2, the called program: IDENTIFICATION DIVISION. PROGRAM-ID. PROGRAM2. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 PASSED-VAR EXTERNAL PIC x(30). PROCEDURE DIVISION. 000-MAIN. DISPLAY PASSED-VAR. STOP RUN

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