Você está na página 1de 5

|********************************* TOP OF DATA ********************************|

|
*** PERFORM STATEMENT ***
|
|
|
| The PERFORM statement is a PROCEDURE DIVISION statement which transfers
|
| control to one or more specified procedures and controls as specified
|
| the number of times the procedures are executed. After execution of
|
| the specified procedures is completed (i.e., for the appropriate number
|
| of times or until some specified condition is met), control is
|
| transferred to the next executable statement following the PERFORM
|
| statement.
|
|
|
| There are 4 types of PERFORM statements:
|
|
|
|
Basic PERFORM
|
|
PERFORM TIMES
|
|
PERFORM UNTIL
|
|
PERFORM VARYING
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Each type has two basic formats:


An out-of-line PERFORM statement
An in-line PERFORM statement
In an out-of-line PERFORM statement, a procedure name (or names) is
specified and control is transferred "out-of-line" to the specified
procedures. In an in-line PERFORM, a set of "in-line" statements
(followed by an END-PERFORM delimiter) make up the procedure to be
performed.
The two formats
procedure name
PERFORM must be
line statements

cannot be mixed in the same PERFORM statement. If a


is specified, then the in-line statements and the ENDomitted. If no procedure name is specified, the inand the END-PERFORM must be specified.

BASIC PERFORM
In the basic PERFORM statement, the specified procedures are executed
once. Control is then passed to the next executable statement
following the PERFORM statement.
Format 1- Basic PERFORM
----------------------PERFORM procedure-name1 THROUGH/THRU procedure-name2
statement1 END-PERFORM
Procedure-name1 and Procedure-name2 must name a section or paragraph in
the PROCEDURE DIVISION. Procedure-name1 specifies the first (or, if
the optional THROUGH phrase is omitted) the only procedure making up
the out-of-line procedure to be executed.
The THROUGH phrase may be used only when procedure-name1 is specified.
In this case, procedure-name2 specifies the last of the out-of-line
procedures to be executed.
When procedure-name1 is specified, statement1 and the END-PERFORM must
not be specified.
If procedure-name1 is omitted, then statement1 and the END-PERFORM must
be specified.

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Statement1 represents the statement or statements that make up the inline procedure to be executed.
When procedure-name1 is specified, control is passed to the first
sentence of procedure-name1. If procedure-name1 is a section, then
control is passed to the first sentence of the first paragraph of
procedure-name1.
If procedure-name2 is omitted, then control returns after the last
sentence of procedure-name1 is executed. If procedure-name1 is a
section, then control returns after the last sentence of the last
paragraph of procedure-name1 is executed.
If procedure-name2 is specified, then control returns after the last
sentence of procedure-name2 is executed. If procedure-name2 is a
section, then control returns after the last sentence of the last
paragraph of procedure-name2 is executed.
When the performed procedures include another PERFORM statement, the
procedures associated with the embedded PERFORM must be totally
included in or totally excluded from the performed procedures of the
first PERFORM statement.
PERFORM TIMES
The procedure or procedures specified in the PERFORM TIMES statement
are executed one or more times as specified by the TIMES phrase.
Control is then passed to the next executable statement following the
PERFORM statement.
Format 2- PERFORM TIMES
----------------------PERFORM procedure-name1 THROUGH/THRU procedure-name2 phrase1
phrase1 statement1 END-PERFORM
where phrase1 is:
identifier1/integer1 TIMES
If procedure-name1 is specified, statement1 and the END-PERFORM must
not be specified.
If procedure-name1 is omitted, then statement1 and the END-PERFORM must
be specified.
The value of identifier1/integer1 dictates the number of times the
procedure or procedures are executed.
If the value of identifier1 is not greater than zero when the PERFORM
statement is executed, control passes to the next executable statement
following the PERFORM statement.
PERFORM UNTIL
The procedure or procedures specified in the PERFORM UNTIL statement
are executed until the condition specified by the UNTIL phrase is true.
Control is then passed to the next executable statement following the
PERFORM statement.

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Format 3- PERFORM UNTIL


----------------------PERFORM procedure-name1 THROUGH/THRU procedure-name2 phrase1
phrase1 statement1 END-PERFORM
where phrase1 is:
{WITH} TEST BEFORE/AFTER UNTIL condition1
If procedure-name1 is specified, statement1 and the END-PERFORM must
not be specified.
If procedure-name1 is omitted, the AFTER phrase must not be specified.
The TEST BEFORE and AFTER phrases are optional.
Condition1 is any conditional expression.
If the TEST BEFORE phrase is specified, the condition is tested before
any statements are executed. If the condition is true when the PERFORM
statement is initiated, then the specified procedure or procedures are
not executed at all. (This corresponds to DO WHILE.)
If the TEST AFTER phrase is specified, the procedure or procedures are
executed at least once before the condition is tested. (This
corresponds to DO UNTIL.)
In either case, once the condition is tested and determined to be true,
control passes to the next executable statement following the PERFORM
statement.
If neither TEST BEFORE nor TEST AFTER is specified, TEST BEFORE is
assumed.
PERFORM VARYING
The procedure or procedures specified in the PERFORM VARYING statement
are executed -as certain specified identifiers, subscripts, or index
data items are initiated and incremented- until the condition specified
by one or more UNTIL phrases is true. Control is then passed to the
next executable statement following the PERFORM statement.
Format 4- PERFORM VARYING
----------------------PERFORM procedure-name1 THROUGH/THRU procedure-name2 phrase1
phrase1 statement1 END-PERFORM
where phrase1 is:
{WITH} TEST BEFORE/AFTER
VARYING identifier1/index-name1
FROM identifier2/index-name2/literal1
BY identifier3/literal2
UNTIL condition1
If procedure-name1 is specified, statement1 and the END-PERFORM must
not be specified.
If procedure-name1 is omitted, the AFTER phrase must not be specified.

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

The TEST BEFORE and AFTER phrases are optional.


Condition1 is any conditional expression.
If the TEST BEFORE phrase is specified, the condition is tested before
any statements are executed. If the condition is true when the PERFORM
statement is initiated, then the specified procedure or procedures are
not executed at all. (This corresponds to DO WHILE.)
Note: TEST BEFORE may behave differently when the CMPR2 compiler
option is used.
If the TEST AFTER phrase is specified, the procedure or procedures are
executed at least once before the condition is tested. (This
corresponds to DO UNTIL.)
In either case, once the condition is tested and determined to be true,
control passes to the next executable statement following the PERFORM
statement.
If neither TEST BEFORE nor TEST AFTER is specified, TEST BEFORE is
assumed.
Identifier1/index-name1 is varied as described below:
1. Identifier1/index-name1 is set to its initial value (i.e.,
identifier2, index-name2, or literal1).
2. Condition1 is evaluated. If true (and TEST BEFORE is specified or
assumed), control passes to the statement following the PERFORM
statement.
3. The specified procedure or procedures are executed.
4. Identifier1/index-name1 is incremented as specified by identifier3
or literal2.
5. Condition1 is evaluated. If false, continue with step 3. If true,
control passes to the statement following the PERFORM statement.
The PERFORM VARYING may be specified with up to 7 "varying" identifiers
by the addition of one or more AFTER phrases (i.e., one for each
additional identifier to be varied).
The format of the AFTER phrase is shown below:
AFTER identifer4/index-name3
FROM identifier5/index-name4/literal3
BY identifier6/literal4
UNTIL condition2
For the items defined below:
05 WS-SUB
PIC S9(4) COMP.
05 WS-AMT-TOTAL
PIC S9(7) COMP-3 VALUE +0.
05 WS-TABLE.
10 WS-TABLE-AMT PIC S9(5) COMP-3
OCCURS 10 TIMES.
The PERFORM VARYING statement shown below calculates the total of all

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

| the amount values stored in WS-TABLE:


|
|
|
|
PERFORM CALC-TOTAL
|
|
VARYING WS-SUB FROM 1 BY 1
|
|
UNTIL WS-SUB GREATER THAN 10.
|
|
.
|
|
.
|
|
CALC-TOTAL.
|
|
ADD WS-TABLE-AMT (WS-SUB) TO WS-AMT-TOTAL.
|
|
.
|
|
.
|
|
|
| The in-line PERFORM TIMES statement shown below accomplishes the same
|
| function:
|
|
|
|
MOVE +0 TO WS-SUB.
|
|
PERFORM 10 TIMES
|
|
ADD +1 TO WS-SUB
|
|
ADD WS-TABLE-AMT (WS-SUB) TO WS-AMT-TOTAL
|
|
END-PERFORM.
|
|******************************* BOTTOM OF DATA *******************************|

Você também pode gostar