The formats for the USE statement are:
For general information about declaratives, see Declaratives.
LABEL declaratives are supported by IBM Enterprise COBOL for z/OS.
The EXCEPTION/ERROR declarative specifies procedures for input/output exception or error handling that are to be executed in addition to the standard system procedures.
The words EXCEPTION and ERROR are synonymous and can be used interchangeably.
A USE AFTER EXCEPTION/ERROR declarative statement specifying the name of a file takes precedence over a declarative statement specifying the open mode of the file.
The EXCEPTION/ERROR procedure is executed:
After execution of the EXCEPTION/ERROR procedure, control is returned to the invoking routine in the input/output control system. If the input/output status value does not indicate a critical input/output error, the input/output control system returns control to the next executable statement following the input/output statement whose execution caused the exception.
An applicable EXCEPTION/ERROR procedure is activated when an input/output error occurs during execution of a READ, WRITE, REWRITE, START, OPEN, CLOSE, or DELETE statement. To determine what conditions are errors, see Common processing facilities.
A declarative procedure must not reference a nondeclarative procedure.
A PERFORM statement in a nondeclarative procedure can reference a declarative procedure; otherwise, a declarative procedure must not be referenced from a nondeclarative procedure.
You can include a statement that executes a previously called USE procedure that is still in control. However, to avoid an infinite loop, you must be sure that there is an eventual exit at the bottom.
EXCEPTION/ERROR procedures can be used to check the file status key values whenever an input/output error occurs.
Special precedence rules are followed when programs are contained within other programs. In applying these rules, only the first qualifying declarative is selected for execution. The order of precedence for selecting a declarative is:
Steps 3 and 4 are repeated until the last examined program is the outermost program, or until a qualifying declarative has been found.
The LABEL declarative (format 2 of the USE statement) is supported by IBM Enterprise COBOL for z/OS. If a LABEL declarative is encountered by COBOL for Windows, a warning message is issued and the declarative is ignored.
Debugging sections are permitted only in the outermost program; they are not valid in nested programs. Debugging sections are never triggered by procedures contained in nested programs.
Debugging sections are not permitted in:
The WITH DEBUGGING MODE clause of the SOURCE-COMPUTER paragraph activates all debugging sections and lines that have been compiled into the object code. See Appendix D. Source language debugging for additional details.
When the debugging mode is suppressed by not specifying the WITH DEBUGGING MODE clause, all USE FOR DEBUGGING declarative procedures and all debugging lines are inhibited.
Automatic execution of a debugging section is not caused by a statement that appears in a debugging section.
| Format 3: USE (Debugging declarative) |
|---|
|
Except for the USE FOR DEBUGGING sentence itself, within the debugging procedure there must be no reference to any nondeclarative procedures.
Execution of debugging declaratives (Table 56) shows, for each valid option, the points during execution when the USE FOR DEBUGGING procedures are executed.
Any given procedure-name can appear in only one USE FOR DEBUGGING sentence, and only once in that sentence. All procedures must appear in the outermost program.
| USE FOR DEBUGGING operand | Upon execution of the following, the USE FOR DEBUGGING procedures are executed immediately |
|---|---|
| procedure-name-1 | Before each execution of the named
procedure
After the execution of an ALTER statement referring to the named procedure |
| ALL PROCEDURES | Before each execution of every
nondebugging procedure in the outermost program
After the execution of every ALTER statement in the outermost program (except ALTER statements in declarative procedures) |