COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-8
Sharing Files Among HP COBOL Programs
When a HP COBOL run unit opens a file, the file remains open until one of these
happens:
The run unit explicitly closes the file.
The calling program cancels the called program that has the file open (with the
CANCEL statement).
The run unit terminates execution.
A well-structured program unit has all the file activity for a certain file within one called
program. The other programs in the run unit call that program to open, read, write,
position, or close the file.
In the called program, include a data item whose initial value indicates that the file is
not open. When the program opens the file, set the data item to a value that indicates
that the file is open. When the program closes the file, set the data item to a value that
indicates that the file is closed. The value of the data item is retained between calls to
that program unless a CANCEL statement intervenes.
Sharing Files Among HP COBOL Programs
Two programs in a run unit can refer to common file connectors in these
circumstances:
Any program that has described an external file connector can refer to that file
connector.
If a program G is contained within another program H, both programs can refer to a
common file connector. They do so by referring to an associated global file name
(or associated global record-name, in the case of the WRITE statement) described
in either:
°
The containing program H
°
Any program that directly or indirectly contains H
If several programs define a file connector as external (causing its storage location to
be a single location outside all programs) and they also define the file connector as
having a global name, then all such programs and all programs nested within each of
them have access to the file connector.
Sharing Files Among Different-Language Modules
If your program consists of modules written in different languages, the modules can
share the standard files—the predefined files called “standard input,” “standard output,”
and “standard log” (except that FORTRAN modules cannot share “standard log”
because FORTRAN does not support it).