Microsoft KB Archive/43692

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Explanation and Example of COBOL 3.0 EXTERNAL Files

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

3.00 3.00a MS-DOS

The information in this article applies to:
- Microsoft COBOL for MS-DOS, versions 3.0 and 3.0a

Summary: This article explains the use of EXTERNAL files in COBOL Versions 3.0 and 3.0a. EXTERNAL files are a new feature of ANSI 85 COBOL not available in ANSI 74 compilers such as Microsoft COBOL Versions 2.x. EXTERNAL files allow you to share a common file-record storage area between CALLed and CHAINed programs. The concept of EXTERNAL in COBOL is synonymous with “COMMON” storage areas in other languages. The purpose is to save data space for record storage and coding. When a file is declared as EXTERNAL in two or more programs, it shares the same record storage space at run time, and all actions taken on the file immediately affect that file in every program in which it is declared EXTERNAL. Therefore, if the file is OPENed in one program, it is open in the other; if data is written to the file, it is immediately available in the other.

More Information: The following are the required steps to make a file EXTERNAL: 1. In the COBOL Code a. Exactly match the SELECT clauses and FD file description in each of the programs. b. Include the EXTERNAL clause in the FD file description header. c. In each program, match the FD file-descriptions records. d. The filename literals, e.g. “filename.ext”, must match exactly. 2. At Compile Time a. Assume that we are working with PROG1.COB and PROG2.COB. Compile both programs, as follows: COBOL PROG1.COB; COBOL PROG2.COB; b. LINK the programs. There are two support modules required to use external files, EXTFH and EXTERNL. You can link these with your program, either statically or dynamically, as shown below: 1) To statically LINK the programs, do the following: LINK PROG1.OBJ EXTFH.OBJ EXTERNL.OBJ; LINK PROG2; (If you are chaining between more than two programs, you must LINK EXTFH and EXTERNL with each program.) 2) To dynamically LINK the programs, do the following: LINK PROG1.OBJ; LINK PROG2.OBJ; LINK the following modules once only. You do not have to LINK them every time you create a program: LINK EXTERNL.OBJ; LINK EXTFH.OBJ; The following is PROG1.COB: $set nolitlink errq *************************** * PROG1.COB ************************** environment division. input-output section. file-control. select ext-file assign to disk organization is line sequential access mode is sequential. data division. file section. fd ext-file is external value of file-id is file-name. 01 ext-file-rec pic x(80). working-storage section. 77 file-name pic x(12) value “testfile.dat”. procedure division. start-test. open output ext-file. call “prog2”. cancel “prog2”. close ext-file. * Now the file contains “hello”. Read it and print it out. open input ext-file. read ext-file. display ext-file-rec. close ext-file. stop run. The following is PROG2.COB: $set nolitlink errq *************************** * PROG2.COB ************************** environment division. input-output section. file-control. select ext-file assign to disk organization is line sequential access mode is sequential. data division. file section. fd ext-file external value of file-id is file-name. 01 ext-file-rec pic x(80). working-storage section. 77 file-name pic x(12) value “testfile.dat”. procedure division. start-test. move “Hello” to ext-file-rec. write ext-file-rec. exit program.

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