COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

to procedure-names defined within another logically discrete area. For detailed restrictions
and permissions, see ALTER, GO TO, and PERFORM.
Procedure names defined within a nondebugging declarative procedure (and
procedure-names defined within utility sections associated with that declarative procedure)
can be referred to by PERFORM statements located anywhere in the Procedure Division.
A declarative exception procedure in which the GLOBAL phrase is specified must not
execute an EXIT PROGRAM statement.
Declarative exception procedures apply only to data files, not to sort-merge files.
Implicit and Explicit File Reference
A USE statement that mentions a file by name is said to make an explicit reference to the
corresponding file. A USE statement that mentions an open mode (INPUT, I-O, OUTPUT, or
EXTEND) makes reference to a file implicitly, according to the mode in which the program
opened (or attempted to open) the file.
It is usually best to write USE statements that explicitly reference individual files, because this
gives you better control over the handling of exceptions. The declarative called by implicit
reference has no simple way to determine the identity of the file that generated an exception.
The management of this generic sort of exception handling can be difficult, particularly when
program maintenance might introduce additional files, or in nested programs when a GLOBAL
declarative is active.
Precedence Rules for Nested Programs
When a program contains other programs, these precedence rules apply. When the run-time
routines detect an I-O exception, they apply these rules (in the order indicated) to select and
perform only the first declarative procedure that qualifies.
1. If the program in which the exception-causing statement occurred contains an appropriate
declarative, use it.
2. If no declarative in that program is appropriate, check the next containing program (the
next one outward in the nesting). If the containing program contains an appropriate
declarative in which the GLOBAL phrase is specified, use it.
3. Repeat Item 2 until the outermost program has been checked. If no qualifying declarative
procedure has been found, none is executed.
An outer program can contain a GLOBAL declarative procedure to handle each file, but a
nested program can contain an overriding GLOBAL or local declarative procedure that governs
the handling of exceptions for certain files within the nested program or any programs it
contains.
File Status and GUARDIAN-ERR Special Register
For information on file status and the special register GUARDIAN-ERR, see I-O Status Code
(page 247). A USE AFTER EXCEPTION procedure can base its activity on the values of these
data items.
In Example 141, two files use the same error routine and another file uses a separate error routine.
486 Procedure Division Verbs