The USE statement specifies procedures for input-output error handling beyond the standard procedures provided by the runtime system. It is a compiler directing statement required in each declarative section.
A USE statement must immediately follow a section header in the declaratives portion of the Procedure Division and must be followed by a separator period. The remainder of the section must consist of zero or more paragraphs that define the procedures to be used.
The USE statement itself is not executed; it defines the conditions calling for the execution of the USE procedure.
A file-name may not be listed in more than one USE statement, nor may it appear more than once in the list of any USE statement. File-names that appear in a USE statement list may not be SORT or MERGE files.
The appearance of a file-name in a USE statement must not cause the simultaneous request for execution of more than one USE procedure.
The INPUT, OUTPUT, I-O and EXTEND phrases may each be specified only once in the declaratives portion of a given Procedure Division.
The words ERROR and EXCEPTION are synonymous in this context.
Declarative procedures may be included in any source program irrespective of whether the program contains or is contained within another program. A declarative is invoked when any of the conditions described in the USE statement that prefaces the declarative occurs while the program is being executed. Only a declarative within the separately compiled program that contains the statement which caused the qualifying condition is invoked when any of the conditions described in the USE statement which prefaces the declarative occurs while that separately compiled program is being executed. If no qualifying declarative exists in the separately compiled program, no declarative is executed.
During the execution of an input-output statement, the runtime system executes the section associated with a USE statement under these conditions:
The USE section is executed as if it were the operand of a Format 1 PERFORM statement, after having stored the I-O status value into the associated file status data item if there is one.
In circumstances where it is appropriate to do so, the system standard input-output error recovery procedures are also performed.
The rules that determine which USE procedure is to be executed are as follows:
When the execution of the USE procedure is complete, control returns to the runtime system. The runtime system then resumes execution of the COBOL program at the next executable statement following the input-output statement whose execution caused the exception or error.
When there is no applicable USE procedure and a critical error occurs for an input-output statement, the runtime system produces an error message and terminates execution of the run unit. This behavior can be configured to allow the program to continue as if a default empty USE procedure were applicable. See the DEFAULT-USE-PROCEDURE keyword of the COMPILER-OPTIONS record in Chapter Configuration, of the RM/COBOL User’s Guide for, information on configuring this behavior.
Within a USE procedure there must be no reference to any nondeclarative procedure. Conversely, in the nondeclarative portion there must be no reference to procedure-names that appear in the declarative portion, except that PERFORM statements may refer to the procedures associated with a USE statement.
Within a USE procedure, there must not be the execution of any statement that would cause the execution of a USE procedure that had previously been invoked and had not yet returned control to the invoking routine.
Special precedence rules are followed when programs are contained within other programs. In applying these rules, only the first qualifying declarative will be selected for execution. The declarative that is selected for execution must satisfy the rules for execution of that declarative. The order of precedence for selecting a declarative is:
USE Statement Example
USE AFTER STANDARD EXCEPTION PROCEDURE ON I-O.
DISPLAY "Error for file in I-O open mode.".
ACCEPT CONTINUE-FLAG POSITION 0 PROMPT.
IF CONTINUE-FLAG = "NO" STOP RUN.
COBOL Related Interview Questions
|VSAM Interview Questions||IBM - VSAM Interview Questions|
|IBM-CICS Interview Questions||JCL Interview Questions|
|IBM DB2 Interview Questions||IBM-JCL Interview Questions|
|DB2 Using SQL Interview Questions||IBM-JCL&VSAM Interview Questions|
|IBM Mainframe Interview Questions||COBOL, CICS, JCL, VSAM, DB2 Interview Questions|
|DB2 SQL Programming Interview Questions||IMS/DB Interview Questions|
|Mainframe DB2 Interview Questions|
Procedure Division Statements
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.