The PERFORM statement is used to transfer control explicitly to one or more procedures and to return control implicitly whenever execution of the specified procedure is complete.
The PERFORM statement is also used to control execution
of one or more imperative statements which are in the scope of that
PERFORM statement.
See also the section The EXIT Statement earlier in this chapter.
If procedure-name-1 is omitted, imperative-statement-1 and
the END-PERFORM phrase must be specified; if procedure-name-1 is specified,
imperative-statement-1 and the END-PERFORM phrase must not be specified.
When imperative-statement-1 is specified, the END-PERFORM
phrase is optional.
Procedure-name-1 and imperative-statement-1 may both be
omitted.
Floating-point data items and literals can be used
anywhere a numeric data item or literal can be specified. They can not be used
where an integer is required.
If neither the TEST BEFORE nor the TEST
AFTER phrase is specified, the TEST BEFORE phrase
is assumed.
In Format 4, if procedure-name-1 is omitted, the AFTER phrase
must not be specified.
Six AFTER phrases are permitted in Format 4 of the PERFORM
statement.
This limit is raised to fifteen.
when procedure-name-1 is omitted, the PERFORM statement
is referred to as an in-line PERFORM statement.
or contained in the PERFORM statement
itself for an in-line PERFORM statement
are referred to as the specified set of statements.
The END-PERFORM phrase delimits the scope of the in-line
PERFORM statement. (See the section Explicit And Implicit Scope
Terminators in the chapter Concepts of the COBOL Language.)
An in-line PERFORM statement functions according to the
following general rules for an otherwise identical out-of-line
PERFORM statement, with the exception that the statements
contained within the in-line PERFORM statement are executed in
place of the statements contained within the range of
procedure-name-1 (through procedure-name-2 if specified). Unless
specifically qualified by the word in-line or out-of-line, all the
general rules which apply to the out-of-line PERFORM statement
also apply to the in-line PERFORM statement.
If an in-line PERFORM statement is specified,
an execution of the PERFORM statement is completed after the last
statement contained within it has been executed.
An EXIT PERFORM statement can be used to exit
an in-line perform before executing all statements within the in-line
perform.
During execution of the PERFORM statement, reference to identifier-1 cannot alter the number of times the specified set of statements is to be executed from that which was indicated by the initial value of the data item referenced by identifier-1.
Integer-1 must be zero or positive, but it may be signed.
and the TEST BEFORE phrase is
specified or implied,
no transfer to procedure-name-1 takes place, and control is passed to the end of the PERFORM statement.
If the TEST AFTER phrase is specified,
the PERFORM statement functions as if the TEST BEFORE phrase were
specified except that the condition is tested after the specified
set of statements has been executed. Any subscripting or
reference modification associated with the operands specified
in condition-1 is evaluated each time the condition is
tested.
When UNTIL EXIT is specified, the specified set of statements
is performed repeatedly until some statement in the set causes
this repetition to end. In the case of an out-of-line PERFORM,
the only statements that will cause this termination are
statements such as EXIT PROGRAM and STOP RUN. In the
case of an in-line PERFORM, the repetition can also be
terminated by the EXIT PERFORM statement and the GO TO statement.
If index-name-1 is specified, the value of identifier-3, index-name- 2, or literal-1 at the beginning of the execution of the PERFORM statement must correspond to an occurrence number of an element in the table associated with index-name-1. If index-name-3 is specified, the value of identifier-6, index-name-4, or literal-3 at the beginning of the execution of the PERFORM statement must correspond to an occurrence number of an element in the table associated with index-name-3.
Subsequent augmentation, as described below, of index-name-1 or index-name-3 must not result in the associated index being set to a value outside the range of the table associated with index-name-1 or index-name-3; except that, at the completion of the PERFORM statement, the index associated with index-name-1 can contain a value that is outside the range of the associated table by one increment or decrement value.
If identifier-2 or identifier-5 is subscripted, the subscripts are evaluated each time the content of the data item referenced by the identifier is set or augmented. If identifier-3, identifier-4, identifier-6, or identifier-7 is subscripted, the subscripts are evaluated each time the content of the data item referenced by the identifier is used in a setting or augmenting operation. Any subscripting or reference modification associated with the operands specified in condition-1 or condition-2 is evaluated each time the condition is tested.
Representations of the actions of several types of Format 4 PERFORM statements are given on the following pages.
When the data item referenced by one identifier is varied, the content of the data item referenced by identifier-2 is set to literal-1 or the current value of the data item referenced by identifier-3 at the point of initial execution of the PERFORM statement; then, if the condition of the UNTIL phrase is false, the specified set of statements is executed once. The value of the data item referenced by identifier-2 is augmented by the specified increment or decrement value (literal-2 or the value of the data item referenced by identifier-4) and condition-1 is evaluated again. The cycle continues until this condition is true, at which point control is transferred to the end of the PERFORM statement. If condition-1 is true at the beginning of execution of the PERFORM statement, control is transferred to the end of the PERFORM statement.
Figure 4-1: The VARYING Option of a PERFORM Statement with the TEST BEFORE Phrase Having One Condition
When the data items referenced by two identifiers are varied, the content of the data item referenced by identifier-2 is set to literal-1 or the current value of the data item referenced by identifier-3 and then the content of the data item referenced by identifier-5 is set to literal-3 or the current value of the data item referenced by identifier-6.
After the contents of the data items referenced by the identifiers have been set, condition-1 is evaluated; if true, control is transferred to the end of the PERFORM statement; if false, condition-2 is evaluated. If condition-2 is false, the specified set of statements is executed once, then the content of the data item referenced by identifier-5 is augmented by literal-4 or the content of the data item referenced by identifier-7 and condition-2 is evaluated again.
Figure 4-2: The VARYING Option of a PERFORM Statement with the TEST BEFORE Phrase Having Two Conditions
This cycle of evaluation and augmentation continues until this condition is true. When condition-2 is true, the content of the data item referenced by identifier-2 is augmented by literal-2 or the content of the data item referenced by identifier-4, the content of the data item referenced by identifier-5 is set to literal-3 or the current value of the data item referenced by identifier-6, and condition-1 is reevaluated. The PERFORM statement is completed if condition-1 is true; if not, the cycle continues until condition-1 is true.
At the termination of the PERFORM statement, the data item referenced by identifier-5 contains literal-3 or the current value of the data item referenced by identifier-6. The data item referenced by identifier-2 contains a value that exceeds the last used setting by one increment or decrement value, unless condition-1 was true when the PERFORM statement was entered, in which case the data item referenced by identifier-2 contains literal-1 or the current value of the data item referenced by identifier-3.
If the TEST AFTER phrase is specified:
When the data item referenced by one identifier is varied, the content of the data item referenced by identifier-2 is set to literal-1 or the current value of the data item referenced by identifier-3 at the point of execution of the PERFORM statement; then the specified set of statements is executed once and condition-1 of the UNTIL phrase is tested. If the condition is false, the value of the data item referenced by identifier-2 is augmented by the specified increment or decrement value (literal-2 or the value of the data item referenced by identifier-4) and the specified set of statements is executed again. The cycle continues until condition-1 is tested and found to be true, at which point control is transferred to the end of the PERFORM statement.
When the data items referenced by two identifiers are varied, the content of the data item referenced by identifier-2 is set to literal-1 or the current value of the data item referenced by identifier-3; then the current value of the data item referenced by identifier-5 is set to literal-3 or the current value of the data item referenced by identifier-6; and the specified set of statements is then executed. Condition-2 is then evaluated; if false, the content of the data item referenced by identifier-5 is augmented by literal-4 or the content of the data item referenced by identifier-7 and the specified set of statements is again executed. The cycle continues until condition-2 is again evaluated and found to be true, at which time condition-1 is evaluated. If false, the content of the data item referenced by identifier-2 is augmented by literal-2 or the content of data item referenced by identifier-4, the content of the data item referenced by identifier-5 is set to literal-3 or the current value of the data item referenced by identifier-6 and the specified set of statements is again executed. This cycle continues until condition-1 is again evaluated and found to be true, at which time control is transferred to the end of the PERFORM statement.
Figure 4-3: The VARYING Option of a PERFORM Statement with the TEST AFTER Phrase Having One Condition
After completion of the PERFORM statement, each data item varied by an AFTER or VARYING phrase contains the same value it contained at the end of the most recent execution of the specified set of statements. See Figure 4-4.
Figure 4-4: The VARYING Option of a PERFORM Statement with a TEST AFTER Phrase Having Two Conditions
During the execution of the specified set of statements associated with the PERFORM statement, any change to the VARYING variable (the data item referenced by identifier-2 and index-name-1), the BY variable (the data item referenced by identifier-4), the AFTER variable (the data item referenced by identifier-5 and index-name-3), or the FROM variable (the data item referenced by identifier-3 and index-name-2) will be taken into consideration and will affect the operation of the PERFORM statement.
When the data items referenced by two identifiers are varied, the data item referenced by identifier-5 goes through a complete cycle (FROM, BY, UNTIL) each time the content of the data item referenced by identifier-2 is varied. When the contents of three or more data items referenced by identifiers are varied, the mechanism is the same as for two identifiers except that the data item being varied by each AFTER phrase goes through a complete cycle each time the data item being varied by the preceding AFTER phrase is augmented.
These restrictions are not enforced. PERFORM statements
can be freely nested, and recursion (a PERFORM statement performing
a procedure containing it) is allowed. Only the exit point of the
innermost PERFORM statement currently being executed is recognized.
These rules can be changed by use of the PERFORM-TYPE
Compiler directive.
See the following illustrations for examples of legal PERFORM constructs.
These restrictions do not apply.
These restrictions do not apply.
For sequential access, the READ
statement makes available the next
logical record from a file. For random access, the READ statement makes available a specified record from a mass storage file.
This restriction has been removed.
The storage area associated with identifier and the storage area which is the record area associated with file-name must not be the same storage area.
Identifier can be a floating-point data item.
This rule is not enforced.
The WITH LOCK phrase can be included
only when single records are being locked manually in a shareable file.
The WITH NO LOCK phrase
is only allowed when records are being locked manually or automatically in a shareable file.
phrases must be specified for files in dynamic access mode when records are to be retrieved sequentially.
The WITH KEPT LOCK phrase
can be included only when multiple records are being locked manually in a shareable file.
Data-name may also be a redefinition of a data-item specified
as a record key associated with a file-name, provided the data-name
has the same length as that data-item.
The redefinition may have a different length from the record key.
Split-key-name is a concatenation of one or more data
items specified as a record key associated with file-name.
When the AT END condition occurs,
the execution of the
READ statement is unsuccessful.
If the file position indicator was positioned by the
execution of the OPEN statement, the record pointed to by the file position indicator is made available.
If the file position indicator was positioned by the execution
of a previous READ statement, the file position indicator is
>updated to point to the next existing record in the file, and that record is made available.
However if the previous statement was a READ, and if that
READ returned a locked record status, the file position
indicator is left unchanged. The record pointed to by the file
position indicator is made available.
For files opened for INPUT, the READ, READ WITH LOCK or
READ WITH KEPT LOCK statements do not acquire a record
lock.
Two or more run units can share a sequential
output file by opening it EXTEND with AUTOMATIC or MANUAL record
locking. Records that are appended to the file are in unspecified order.
For files opened for I/O:
If an end-of-file status occurs on a READ statement
in a file opened for I/O or INPUT by one run unit and opened EXTEND
by another run unit, the run unit that attempted the READ must close the file.
This run unit has no access to the appended records because the
status remains end-of-file.
sequential files or
files in sequential access mode, the NEXT phrase is optional and has no effect on the execution of the READ statement.
Following a READ which encounters a locked record
status, the file position indicator points at the locked record.
A subsequent READ NEXT or READ PREVIOUS will retrieve the same record
again.
The NOT AT END phrase is only executed following successful completion
of the operation.
If when a READ statement with the PREVIOUS
option is executed no previous logical record exists in the file, the AT END condition
occurs, and the execution of the READ statement is considered unsuccessful.
the next Format 3 READ statement, if any, executed
for that file must be a READ NEXT statement, if AT END occurred
because no previous logical record existed. Otherwise
the AT END condition must be followed by:
as described in General Rule 8.
If the file position indicator
was positioned by the execution
of an OPEN statement, and the PREVIOUS option
is specified, the AT END condition occurs. Otherwise
if the file position indicator was positioned by the execution of the START or OPEN statement and the record is still accessible through the path indicated by the file position indicator, the record pointed to by the file position indicator is made available. If the record is no longer accessible, which can have been caused for a relative file by deletion of the record, or for an indexed file by a change in an alternate key, the file position indicator is updated to point to the next
or, if the PREVIOUS option is specified, the previous
existing record within the established key of reference, and that record is then made available.
or, if the PREVIOUS option is specified, the previous
existing record in the file.
However, if the previous statement was a READ, and
if that READ returned a locked record status, the file position
indicator is left unchanged. The record pointed to by the file
position indicator is made available.
If the lock mode is MANUAL with single
record locking and the referenced file is opened I/O, the run unit acquires a record lock
on the record only if the WITH LOCK phrase is specified.
A simple READ statement does not acquire a record lock. To
read past a locked record the file position indicator
should be updated using the START statement. This, however, cannot be used on alternate
keys which allow duplicates.
If the lock mode is MANUAL with multiple record
locking and the referenced file is opened I/O, the run unit acquires a lock on the
record only if the WITH KEPT LOCK phrase
is specified. A simple READ statement does not acquire a record lock. To
read past a locked record the file position indicator should be updated using
the START statement. This, however, cannot be used on alternate
keys which allow duplicates.
The WITH WAIT phrase ensures that a lock is
acquired on the record, waiting if necessary.
or split-key-name
is established as the key of reference for this retrieval. If dynamic access mode is specified, this key of reference is also used for retrievals by any subsequent executions of Format 3 READ statements for the file until a different key of reference is established for the file.
The RELEASE statement transfers records to the initial phase of a SORT operation.
If identifier is a function-identifier, it must reference
an alphanumeric function. When identifier is not a function-identifier,
record-name and identifier must not reference the same storage area.
Record-name can be defined as a floating-point item.
Identifier can be a floating-point item.
The RETURN statement obtains either sorted records from the final phase of a SORT operation or merged records during a MERGE operation.
Identifier-1 can be a floating-point item.
and the NOT AT END phrase if specified is ignored.
When the at end condition occurs, execution of the RETURN statement is unsuccessful and the contents of the record area associated with file-name are undefined. After the execution of imperative-statement-1 in the AT END phrase, no RETURN statement can be executed as part of the current output procedure.
If an at end condition does not occur during the execution
of a RETURN statement, then after the record is made available and
after executing any implicit move resulting from the presence of
an INTO phrase, control is transferred to imperative-statement-2,
if specified. Otherwise, control is transferred to the end of the
RETURN statement.
The END-RETURN phrase delimits the scope of the RETURN
statement.