|
HP COBOL Reference Manual
With COUNT phrase:
DISPLAY "Enter two dates in a row: " NO ADVANCING.
ACCEPT INMESSAGE.
MOVE 1 TO PTR.
PERFORM DISPLAY-TWO 2 TIMES.
GO TO DISPLAYED-TWO.
DISPLAY-TWO.
MOVE SPACES TO THEDATE.
MOVE 0 TO FIELD-COUNT MONTH-COUNT DAY-COUNT YEAR-COUNT.
UNSTRING INMESSAGE
DELIMITED BY "-" OR "/" OR ALL " "
INTO THEMONTH DELIMITER IN HOLD-DELIM COUNT MONTH-COUNT
THEDAY DELIMITER IN HOLD-DELIM COUNT DAY-COUNT
THEYEAR DELIMITER IN HOLD-DELIM COUNT YEAR-COUNT
WITH POINTER PTR
TALLYING IN FIELD-COUNT.
INSPECT THEDATE REPLACING ALL " " BY "0".
DISPLAY THEDATE " " PTR " " FIELD-COUNT
" : " MONTH-COUNT "-" DAY-COUNT "-" YEAR-COUNT.
DISPLAYED-TWO.
EXIT.
|
Results
Enter two dates in a row: 6/13/87 8/15/87
870613 09 03 : 01-02-02
870815 21 03 : 01-02-02
Enter two dates in a row: 10 15 87-1 1 88
871015 10 03 : 02-02-02
880101 21 03 : 01-01-02
Enter two dates in a row: 6/13/87-12/31/87
870613 09 03 : 01-02-02
871231 21 03 : 02-02-02
Enter two dates in a row: 6/13/87-12/31
870613 09 03 : 01-02-02
001231 21 02 : 02-02-00
Enter two dates in a row: 6/13/87/12/31/87
870613 09 03 : 01-02-02
871231 21 03 : 02-02-02
|
6.8.42 USE
Function
The USE statement specifies Declarative USE procedures to handle
input/output exceptions and errors. It can also specify procedures to
be executed before the program processes a specific report group.
file-name
is the name of a file connector described in a file description entry
in a Data Division. It cannot refer to a sort or merge file.
group-data-name
is the name of a report group in a report group description entry in a
Data Division. It must not appear in more than one USE statement.
Syntax Rules
All Formats
- A USE statement can be used only in a sentence immediately after a
section header in the Procedure Division declaratives area. It must be
the only statement in the sentence. The rest of the section can contain
zero, one, or more paragraphs to define the USE procedures.
- The USE statement itself does not execute. It defines the
conditions that cause execution of the USE procedure.
Format 1
- The ERROR and EXCEPTION syntax are equivalent and interchangeable.
Format 2
- Of the four Report Writer Procedure Division verbs (SUPPRESS,
GENERATE, INITIATE, or TERMINATE), only the SUPPRESS statement can
appear in a USE BEFORE REPORTING procedure. A PERFORM statement in a
USE BEFORE REPORTING procedure must not have GENERATE, INITIATE, or
TERMINATE statements in its range.
The USE procedure must not alter
the value of any control data item.
General Rules
All Formats
- At run time, two special precedence rules apply for the selection
of a USE procedure when a program is contained within another program.
In applying these rules, only the first qualifying USE procedure is
selected for execution. The order of precedence for the selection of a
USE procedure is as follows:
- First, select the applicable USE procedure within the program
containing the statement that caused the qualifying condition.
- If a USE procedure is not found in the program using the previous
rule, the Run-Time System searches all programs directly or indirectly
containing that program for a USE GLOBAL procedure. This search
continues until the Run-Time System either: (a) finds an applicable USE
GLOBAL procedure, or (b) finds the outermost containing program, if
there is no applicable USE GLOBAL procedure. Either condition
terminates the search.
- A Declarative USE procedure cannot refer to a non-Declarative
procedure. However, only the PERFORM statement can transfer execution
control from:
- A Declarative USE procedure to another Declarative USE procedure
- A non-Declarative procedure to a Declarative USE procedure
- After a USE procedure executes, control returns to the next
executable statement in the invoking routine, if one is defined.
Otherwise, control transfers according to the rules for Explicit and
Implicit Transfers of Control.
- A program must not execute a statement in a USE procedure that
would cause execution of a USE procedure that had been previously
executed and had not yet returned control to the routine that invoked
it.
Format 1
- A USE procedure executes automatically:
- After the system's input-output exception processing completes
- When an invalid key or at end condition results from an
input-output statement that has no INVALID KEY or AT END clause
- If there is an applicable USE AFTER EXCEPTION procedure, it
executes whenever an input or output condition occurs that would result
in a nonzero value in the first character of a FILE STATUS data item.
However, it does not execute if: (a) the condition is invalid key and
there is an INVALID KEY phrase, or (b) the condition is at end, and
there is an AT END phrase.
- One input-output exception cannot cause more than one USE AFTER
EXCEPTION procedure to execute.
- More than one USE AFTER EXCEPTION procedure can relate to an
input-output operation when there is one procedure for
file-name and another for the applicable open mode. In this
case, only the procedure for file-name executes. This rule
applies only to USE procedures in the same program.
- If no applicable USE procedures are found in the local program,
then containing programs are searched upwards for: (a) USE GLOBAL
procedures for the file, and then (b) for USE GLOBAL procedures for the
input-output type.
- A USE AFTER EXCEPTION procedure specifying an open mode applies to
an input-output operation only when all of the following are true:
- The open mode (INPUT, OUTPUT, I-O, or EXTEND) specified in the USE
AFTER EXCEPTION procedure is identical to the open mode in effect (that
is, the open mode established by the OPEN statement).
- The file is open or in the process of being opened.
- There is no file-name declarative procedure for that file
within the same program.
- If an input-output error occurs for a file that is not open or not
in the process of being opened, the only applicable USE procedure is a
file-name USE procedure.
Format 2
- The Report Writer Control System (RWCS) executes the USE BEFORE
REPORTING procedure before it processes the named
group-data-name report group. Only during the processing of
the report group does the RWCS change prior values, execute control
breaks, adjust LINE-COUNTER and PAGE-COUNTER, and present the report
group.
Additional References
Example
***************************************************************
* This example assumes that SELECT and FD statements exist
* for FILE1-SEQ, FILE1-RAN, FILE1-DYN and FILE1-EXT.
* All three USE procedures are local to the program
* that hosts this fragment.
* At run-time if there is an exception on opening FILE1-RAN
* or FILE1-DYN, FILE1-ERR section can be invoked.
* If there is an exception on opening FILE1-SEQ, INPUT-ERR
* section can be invoked. Since there is no USE procedure
* declared for the EXTEND mode or for FILE1-EXT,
* an exception on opening that file will cause an abnormal
* termination of the program. Also, since FILE1-SEQ in the
* fragment is not opened for OUTPUT mode, the OUTPUT-ERR USE
* procedure is not eligible to be invoked here.
***********************************************************
PROCEDURE DIVISION.
DECLARATIVES.
INPUT-ERR SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON INPUT.
INP-1.
DISPLAY "INVOKED USE PROCEDURE FOR INPUT".
OUTPUT-ERR SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON OUTPUT.
OUT-1.
DISPLAY "INVOKED USE PROCEDURE FOR OUTPUT".
FILE1-ERR SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON FILE1-RAN, FILE1-DYN.
FILE1-1.
DISPLAY "INVOKED USE PROCEDURE FOR FILES".
END DECLARATIVES.
MAIN-PROGRAM SECTION.
P0. DISPLAY "***ENTERED USE TEST PROGRAM FRAGMENT***".
OPEN INPUT FILE1-SEQ.
OPEN OUTPUT FILE1-RAN.
OPEN I-O FILE1-DYN.
OPEN EXTEND FILE1-EXT.
...
|
|