COBOL: EXTERNAL file Vs GLOBAL file

Within a main program and each of its contained subprograms, data and files are normally private, which means that they are accessible only to the program in which they are contained.

However, COBOL has provisions for sharing data and files among a main program and its subprograms.

Procedure names and paragraph names are private to a program. They can not be shared by other programs.But, program names must be unique.

PROGRAM-ID. program-name IS COMMON PROGRAM.

A program with COMMON, can be called by all other programs, not limited to by the program containing it.It can not be called by outside programs, since its load is not present in other load module.

In mainframe, a subprogram can be called by itself. It is called recursive calling
Global concept

01 data-name IS GLOBAL

Means data item is global to all programs

FD file-name IS GLOBAL

File name and record names are global to all programs
External Concept

A declaration of EXTERNAL for a file means that anywhere in the run unit that the same file is declared (with the same name and the attribute EXTERNAL), the reference is to the same exact file.

FD file-name IS EXTERNAL

You must define the file in any program that references it. However, an external file does not really “belong” to any particular program—it belongs to the whole run unit.

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.