Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

PERFORM statement

Function

The PERFORM statement is used to execute one or more procedures or a set of statements.

Format 1

of the PERFORM statement executes the specified procedures statements one time.

Format 2

of the PERFORM statement executes the specified procedures or statements a specified number of times.

Format 3

of the PERFORM statement executes the specified procedures or statements until a specified condition is true.

Format 4

of the PERFORM statement changes the values of one or more identifiers or index names in ascending or descending order, and executes a series of procedures or the specified statements one or more times, based on this action.

Format 1



"out-of-line"

PERFORM procedure-name-1 [{THRU | THROUGH} procedure-name-2]


"in-line"

PERFORM [imperative-statement END-PERFORM]


Syntax rules

  1. The words THROUGH and THRU are equivalent.

  2. Where both procedure-name-1 and procedure-name-2 are specified, and either is the name of a procedure within the declarative sections, then both procedure-names must be within the same declarative section.

General rules

  1. The END-PERFORM phrase delimits the scope of the in-line PERFORM statement.

  2. 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 specially 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.

  3. When a PERFORM statement is executed, control is transferred to the first statement of the procedure named by procedure-name-1. An implicit return to the next executable statement following the PERFORM statement is made as follows:

    1. If procedure-name-1 is a paragraph-name and procedure-name-2 is not specified, then the return takes place after the last statement of procedure-name-1.

    2. If procedure-name-1 is a section-name, and procedure-name-2 is not specified, then the return is after the last statement of the last paragraph in procedure-name-1.

    3. If procedure-name-2 is specified and it is a paragraph-name, then the return is after the last statement of the paragraph.

    4. If procedure-name-2 is specified and it is a section-name, then the return is after the last statement of the last paragraph in the section.

    5. 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.

  4. There is no necessary relationship between procedure-name-1 and procedure-name-2, except that a consecutive sequence of operations is to be executed beginning at the procedure named procedure-name-1 and ending with the execution of the procedure named procedure-name-2. Even GO TO and PERFORM statements may occur between procedure-name-1 and the end of procedure-name-2. If there are two or more logical paths to the return point, then procedure-name-2 may be the name of a paragraph consisting of the EXIT statement to which all of these paths must lead.

  5. The statements within the range of the PERFORM statement are executed once, and control returns to the statement following the PERFORM statement.

  6. The range of a PERFORM statement consists logically of all those statements that are executed as a result of executing the PERFORM statement through execution of the implicit transfer of control to the end of the PERFORM statement. The range includes all statements that are executed as the result of a transfer of control by CALL, EXIT, GO TO, and PERFORM statements in the range of the PERFORM statement, as well as all statements in declarative procedures that are executed as a result of the execution of statements in the range of the PERFORM statement. The statements in the range of a PERFORM statement need not appear consecutively in the compilation unit.

  7. Statements executed as the result of a transfer of control caused by executing an EXIT PROGRAM statement are not considered to be part of the range of the PERFORM statement when:

    1. That EXIT PROGRAM statement is specified in the same program in which the PERFORM statement is specified, and

    2. The EXIT PROGRAM statement is within the range of the PERFORM statement.

  8. If the range of a PERFORM statement includes another PERFORM statement, the sequence of procedures associated with the included PERFORM must itself either be totally included in, or totally excluded from, the logical sequence referred to by the first PERFORM. Thus, an active PERFORM statement, whose execution point begins within the range of another active PERFORM statement, must not allow control to pass to the exit of the other active PERFORM statement; furthermore, two or more such active PERFORM statements must not have a common exit.
    See the following illustrations for examples of legal PERFORM constructs:

  9. The following information on segmentation is relevant here (for further details, refer to chapter "Segmentation").

    1. If a PERFORM statement appears in a section whose segment number is less than the value specified in the SEGMENT-LIMIT clause, then it may contain within its range only the following procedures:

      • either sections all having a segment number less than 50, or

      • sections which are wholly contained in a single independent segment whose segment number is greater than 49.

    2. If a PERFORM statement appears in a section whose segment number is greater than 49, then it may contain within its range only the following procedures:

      • either sections which all have the same segment number as the section containing the PERFORM statement or

      • sections all having a segment number less than 50.

    3. If a procedure-name in a segment with a segment number greater than 49 is referenced by a PERFORM statement in a segment with a different segment number, then the referenced segment is made available in its initial state (that is, any GO TO statements in this segment which have been modified by the execution of ALTER statements will be reset to their original values).

Example 8-59

PERFORM X-PAR.
ADD A TO B.

Let X-PAR be a paragraph-name. In this case, all statements in the paragraph named X-PAR are executed, and control is then returned to the ADD statement following the PERFORM statement.

Example 8-60

    ...
    PERFORM X1-PAR THRU X3-PAR.
    ...
X-KAP SECTION.
X1-PAR.
    ...
X2-PAR.
    ...
X3-PAR.
    ...
Y-KAP SECTION.
    ...

The PERFORM statement has the effect that all statements in the paragraphs named X1-PAR, X2-PAR and X3-PAR are executed.

Example 8-61

The same effect would result from the execution of the statement:

PERFORM X-KAP.

Format 2


"out-of-line"

PERFORM procedure-name-1 [{THRU | THROUGH} procedure-2] {identifier-1 | integer-1} TIMES


"in-line"

PERFORM {identifier-1 | integer-1} TIMES imperative-statement END-PERFORM


Syntax rules

  1. identifier-1 specifies an elementary numeric data item described as an integer.

  2. The words THROUGH and THRU are equivalent.

  3. Where both procedure-name-1 and procedure-name-2 are specified, and either is the name of a procedure in the declaratives portion of the Procedure Division, then both procedure-names must be within the same declarative section.

General rules

  1. The END-PERFORM phrase delimits the scope of the in-line PERFORM statement.

  2. 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 stated to the contrary, all the general rules which apply to the out-of-line PERFORM statement also apply to the in-line PERFORM statement.

  3. When a PERFORM statement is executed, control is transferred to the first statement of the procedure named by procedure-name-1. An implicit return to the next executable statement following the PERFORM statement is made as follows:

    1. If procedure-name-1 is a paragraph-name and procedure-name-2 is not specified, then the return takes place after the last statement of procedure-name-1.

    2. If procedure-name-1 is a section-name, and procedure-name-2 is not specified, then the return is after the last statement of the last paragraph in procedure-name-1.

    3. If procedure-name-2 is specified and it is a paragraph-name, then the return is after the last statement of the paragraph.

    4. If procedure-name-2 is specified and it is a section-name, then the return is after the last statement of the last paragraph in the section.

    5. 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.

  4. procedure-name-2, except that a consecutive sequence of operations is to be executed beginning at the procedure named procedure-name-1 and ending with the execution of the procedure named procedure-name-2. Even GO TO and PERFORM statements may occur between procedure-name-1 and the end of procedure-name-2. If there are two or more logical paths to the return point, then procedure-name-2 may be the name of a paragraph consisting of the EXIT statement to which all of these paths must lead.

  5. The specified set of statements is performed the number of times specified by integer-1 or by the initial value of the data item referenced by identifier-1 for that execution. Following the execution of the specified set of statements, control is transferred to the end of the PERFORM statement.

  6. If at the time of the execution of a PERFORM statement, the value of the data item referenced by identifier-1 is equal to zero or is negative, control passes to the end of the PERFORM statement.

  7. The range of a PERFORM statement consists logically of all those statements that are executed as a result of executing the PERFORM statement through execution of the implicit transfer of control to the end of the PERFORM statement. The range includes all statements that are executed as the result of a transfer of control by CALL, EXIT, GO TO, and PERFORM statements in the range of the PERFORM statement, as well as all statements in declarative procedures that are executed as a result of the execution of statements in the range of the PERFORM statement. The statements in the range of a PERFORM statement need not appear consecutively in the compilation unit.

  8. Statements executed as the result of a transfer of control caused by executing an EXIT PROGRAM statement are not considered to be part of the range of the PERFORM statement when:

    1. That EXIT PROGRAM statement is specified in the same program in which the PERFORM statement is specified, and

    2. The EXIT PROGRAM statement is within the range of the PERFORM statement.

  9. If the range of a PERFORM statement includes another PERFORM statement, the sequence of procedures associated with the included PERFORM must itself either be totally included in, or totally excluded from, the logical sequence referred to by the first PERFORM. Thus, an active PERFORM statement, whose execution point begins within the range of another active PERFORM statement, must not allow control to pass to the exit of the other active PERFORM statement; furthermore, two or more such active PERFORM statements must not have a common exit.
    See the following illustrations for examples of legal PERFORM constructs:

  10. The following information on segmentation is relevant here (for further details, refer to chapter "Segmentation".

    1. If a PERFORM statement appears in a section whose segment number is less than the value specified in the SEGMENT-LIMIT clause, then it may contain within its range only the following procedures:

      • either sections all having a segment number less than 50, or

      • sections which are wholly contained in a single independent segment whose segment number is greater than 49.

    2. If a PERFORM statement appears in a section whose segment number is greater than 49, then it may contain within its range only the following procedures:

      • either sections which all have the same segment number as the section containing the PERFORM statement or

      • sections all having a segment number less than 50.

    3. If a procedure-name in a segment with a segment number greater than 49 is referenced by a PERFORM statement in a segment with a different segment number, then the referenced segment is made available in its initial state (that is, any GO TO statements in this segment which have been modified by the execution of ALTER statements will be reset to their original values).

Example 8-62

PERFORM X-PAR 5 TIMES.

All statements in the paragraph named X-PAR are performed five times. Control then passes to the statement following the PERFORM statement.

Example 8-63

...
77 A PICTURE 9.
...
    MOVE 3 TO A.
    ...
    PERFORM X-PAR A TIMES.
    ...
X-PAR.
    ...
    ADD 1 TO A.
Y-PAR.
    ...

Since the value of A is 3 when the PERFORM statement is executed, the paragraph named X-PAR is executed three times.

The reference to A within X-PAR has no effect on the PERFORM statement.

Format 3


"out-of-line"

PERFORM procedure-name-1 [{THRU | THROUGH} procedure-name-2]

[WITH TEST {BEFORE | AFTER}] UNTIL condition-1


"in-line"

PERFORM [WITH TEST {BEFORE | AFTER}] UNTIL condition-1

imperative-statement END-PERFORM


Syntax rules

  1. The words THROUGH and THRU are equivalent.

  2. When both procedure-name-1 and procedure-name-2 are specified, and either is the name of a procedure within the declaratives portion of the Procedure Division, then both procedure-names must be within the same declarative section.

  3. If neither TEST BEFORE nor TEST AFTER is specified, TEST BEFORE is assumed.

General rules

  1. The END-PERFORM phrase delimits the scope of the in-line PERFORM statement.

  2. 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 specially 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.

  3. When a PERFORM statement is executed, control is transferred to the first statement of the procedure named by procedure-name-1. An implicit return to the next executable statement following the PERFORM statement is made as follows:

    1. If procedure-name-1 is a paragraph-name and procedure-name-2 is not specified, then the return takes place after the last statement of procedure-name-1.

    2. If procedure-name-1 is a section-name, and procedure-name-2 is not specified, then the return is after the last statement of the last paragraph in procedure-name-1.

    3. If procedure-name-2 is specified and it is a paragraph-name, then the return is after the last statement of the paragraph.

    4. If procedure-name-2 is specified and it is a section-name, then the return is after the last statement of the last paragraph in the section.

    5. 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.

  4. There is no necessary relationship between procedure-name-1 and procedure-name-2, except that a consecutive sequence of operations is to be executed beginning at the procedure named procedure-name-1 and ending with the execution of the procedure named procedure-name-2. Even GO TO and PERFORM statements may occur between procedure-name-1 and the end of procedure-name-2. If there are two or more logical paths to the return point, then procedure-name-2 may be the name of a paragraph consisting of the EXIT statement to which all of these paths must lead.

  5. The statements within the range of the PERFORM statement are executed once, and control returns to the statement following the PERFORM statement.

  6. The range of a PERFORM statement consists logically of all those statements that are executed as a result of executing the PERFORM statement through execution of the implicit transfer of control to the end of the PERFORM statement. The range includes all statements that are executed as the result of a transfer of control by CALL, EXIT, GO TO, and PERFORM statements in the range of the PERFORM statement, as well as all statements in declarative procedures that are executed as a result of the execution of statements in the range of the PERFORM statement. The statements in the range of a PERFORM statement need not appear consecutively in the compilation unit.

  7. Statements executed as the result of a transfer of control caused by executing an EXIT PROGRAM statement are not considered to be part of the range of the PERFORM statement when:

    1. That EXIT PROGRAM statement is specified in the same program in which the PERFORM statement is specified, and

    2. The EXIT PROGRAM statement is within the range of the PERFORM statement.

  8. If the range of a PERFORM statement includes another PERFORM statement, the sequence of procedures associated with the included PERFORM must itself either be totally included in, or totally excluded from, the logical sequence referred to by the first PERFORM. Thus, an active PERFORM statement, whose execution point begins within the range of another active PERFORM statement, must not allow control to pass to the exit of the other active PERFORM statement; furthermore, two or more such active PERFORM statements must not have a common exit.
    See the following illustrations for examples of legal PERFORM constructs:

  9. The specified set of statements is performed until the condition specified by the UNTIL phrase is true. When the condition is true, control is transferred to the end of the PERFORM statement. If the condition is true when the PERFORM statement is entered, 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.

  10. 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.
  11. Any subscripting or reference modification associated with the operands specified in condition-1 is evaluated each time the condition is tested.
  12. The following information on segmentation is relevant here (for further details, refer to chapter "Segmentation").

    1. If a PERFORM statement appears in a section whose segment number is less than the value specified in the SEGMENT-LIMIT clause, then it may contain within its range only the following procedures:

      • either sections all having a segment number less than 50, or

      • sections which are wholly contained in a single independent segment whose segment number is greater than 49.

    2. If a PERFORM statement appears in a section whose segment number is greater than 49, then it may contain within its range only the following procedures:

      • either sections which all have the same segment number as the section containing the PERFORM statement or

      • sections all having a segment number less than 50.

    3. If a procedure-name in a segment with a segment number greater than 49 is referenced by a PERFORM statement in a segment with a different segment number, then the referenced segment is made available in its initial state (that is, any GO TO statements in this segment which have been modified by the execution of ALTER statements will be reset to their original values).

Example 8-64

    PERFORM X-PAR UNTIL A GREATER THAN 3.
    ...
X-PAR.
    ...
    COMPUTE A = A + 1.
    ...
Y-PAR.
    ...

Assume A = 1, when the PERFORM statement is initiated. In this case, the statements in the paragraph named X-PAR are performed three times:

The first time X-PAR is performed, A is set to 2.

The second time X-PAR is performed, A is set to 3.

The third time X-PAR is performed, A is set to 4.

Since 4 is greater than 3, the condition specified in the PERFORM statement is true. Thus, control passes to the statement which follows the PERFORM statement.

Format 4


"out-of-line"

PERFORM procedure-name-1 [{THRU | THROUGH} procedure-name-2] [WITH TEST {BEFORE | AFTER}]

 VARYING {index-1 | identifier-2} FROM {index-2 | literal-1 | identifier-3} BY {literal-2 | identifier-4} UNTIL condition-1

[AFTER {index-3 | identifier-5} FROM {index-4 | literal-3 | identifier-6} BY {literal-4 | identifier-7} UNTIL condition-2]...


"in-line"

PERFORM [WITH TEST {BEFORE | AFTER}]

VARYING {index-1| identifier-2} FROM {index-2 | literal-1 | identifier-3} BY {literal-2 | identifier-4} UNTIL condition-1

imperative-statement END-PERFORM


Syntax rules

  1. The words THROUGH and THRU are equivalent.

  2. When both procedure-name-1 and procedure-name-2 are specified, and either is the name of a procedure within the declaratives portion of the Procedure Division, then both procedure-names must be within the same declarative section.

  3. If neither TEST BEFORE nor TEST AFTER is specified, TEST BEFORE is assumed.

  4. Each identifier represents a numeric item described as an integer. However, the compiler allows each identifier to be described as a non-integer numeric item.

  5. Each literal must be numeric.

  6. The literal in the associated BY phrase must be a non-zero integer.

  7. If an index-name is specified in the VARYING or AFTER phrase, then:

    1. The identifier in the associated FROM and BY phrases must reference an integer data item.

    2. The literal in the associated FROM phrase must be a positive integer.

    3. The literal in the associated BY phrase must be a non-zero integer.

  8. If an index-name is specified in the FROM phrase, then:

    1. The identifier in the associated VARYING or AFTER phrase must reference an integer data item.

    2. The identifier in the associated BY phrase must reference an integer data item.

    3. The literal in the associated BY phrase must be an integer.

  9. condition-1, condition-2 may be any conditional expression.

  10. A maximum of 6 AFTER phrases are permitted in the out-of-line PERFORM statement.

General rules

  1. The data items referenced by identifier-4 and identifier-7 must not have a zero value.

  2. If an index-name is specified in the VARYING or AFTER phrase, and an identifier is specified in the associated FROM phrase, the data item referenced by the identifier must have a positive value.

  3. Format 4 of the PERFORM statement is used to increment or decrement the values of one or more identifiers or index-names in a specific manner while the PERFORM statement is executing. Execution depends on the number of identifiers or index-names that are varied. The following rules describe what happens when one, two and three identifiers or index-names are varied.

  4. The END-PERFORM phrase delimits the scope of the in-line PERFORM statement.

  5. 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 specially 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.

  6. When a PERFORM statement is executed, control is passed to the first statement of the procedure named by procedure-name-1. An implicit return to the next executable statement following the PERFORM statement is made as follows:

    1. If procedure-name-1 is a paragraph-name and procedure-name-2 is not specified, then the return takes place after the last statement of procedure-name-1.

    2. If procedure-name-1 is a section-name, and procedure-name-2 is not specified, then the return is after the last statement of the last paragraph in procedure-name-1.

    3. If procedure-name-2 is specified and it is a paragraph-name, then the return is after the last statement of the paragraph.

    4. If procedure-name-2 is specified and it is a section-name, then the return is after the last statement of the last paragraph in the section.

    5. 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.

  7. There is no necessary relationship between procedure-name-1 and procedure-name-2, except that a consecutive sequence of operations is to be executed beginning at the procedure named procedure-name-1 and ending with the execution of the procedure named procedure-name-2. Even GO TO and PERFORM statements may occur between procedure-name-1 and the end of procedure-name-2. If there are two or more logical paths to the return point, then procedure-name-2 may be the name of a paragraph consisting of the EXIT statement to which all of these paths must lead.

  8. In the following discussion, every reference to identifier as the object of the VARYING, AFTER, and FROM (current value) phrases also refers to index-names.

    1. If index-name-1 or index-name-3 is specified, the value of the associated index at the beginning of the PERFORM statement must be set to an occurrence number of an element in the table.

    2. If index-name-2 or index-name-4 is specified, the value of the data item referenced by identifier-2 or identifier-5 at the beginning of the PERFORM statement must be equal to an occurrence number of an element in a table associated with index-name-2 or index-name-4.

    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 may contain a value that is outside the range of the associated table by one increment or decrement value.

    4. 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.

    5. 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.

  9. Statements executed as the result of a transfer of control caused by executing an EXIT PROGRAM statement are not considered to be part of the range of the PERFORM statement when:

    1. That EXIT PROGRAM statement is specified in the same program in which the PERFORM statement is specified, and

    2. The EXIT PROGRAM statement is within the range of the PERFORM statement.

  10. If the range of a PERFORM statement includes another PERFORM statement, the sequence of procedures associated with the included PERFORM must itself either be totally included in, or totally excluded from, the logical sequence referred to by the first PERFORM. Thus, an active PERFORM statement, whose execution point begins within the range of another active PERFORM statement, must not allow control to pass to the exit of the other active PERFORM statement; furthermore, two or more such active PERFORM statements must not have a common exit.
    See the following illustrations for examples of legal PERFORM constructs:

  11. If the TEST BEFORE phrase is specified or implied:

    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 .

    • This 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.

    When the data items referenced by two identifiers are varied:

    • At the start of execution of the PERFORM statement, 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 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 condition-1 is 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.

    • This cycle of evaluation and augmentation continues until condition-2 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, and 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.

    • 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.

  12. If the TEST AFTER phrase is specified or implied:

    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 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.

    • The specified set of statements is then executed.

    • condition-2 is then evaluated.

    • If condition-2 is false, the content of the data item referenced by identifier-5 is augmented by literal-4 or the content of 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 this time, condition-1 is evaluated.

    • If condition-1 is false, 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, and 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.

    • The specified set of statements is then executed again.

    • 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.

    After the 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.

  13. 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.

  14. The following information on segmentation is relevant here (for further details, refer to chapter "Segmentation").

    1. If a PERFORM statement appears in a section whose segment number is less than the value specified in the SEGMENT-LIMIT clause, then it may contain within its range only the following procedures:

      • either sections which all have a segment number less than 50, or

      • sections which are wholly contained in a single independent segment whose segment number is greater than 49.

    2. If a PERFORM statement appears in a section whose segment number is greater than 49, then it may contain within its range only the following procedures:

      • either sections which all have the same segment number as the section containing the PERFORM statement or

      • sections all having a segment number less than 50.

    3. If a procedure-name in a segment with a segment number greater than 49 is referenced by a PERFORM statement in a segment with a different segment number, then the referenced segment is made available in its initial state (that is, any GO TO statements in this segment which have been modified by the execution of ALTER statements will be reset to their original values). 

Example 8-65

    ...
01  STATES.
    02  COUNTIES OCCURS 51 INDEXED STATE.
       03  FIRST-COUNTY     PIC 9(3).
       03  LAST-COUNTY     PIC 9(3).
       03  CITIES OCCURS 100 INDEXED COUNTIES.
           04  FIRST-CITY   PIC 9(3).
           04  LAST-CITY    PIC 9(3).
01  CITY                    PIC 9(3).
     ...
PROCEDURE DIVISION.
K1.
    PERFORM X-PAR THRU Y-PAR
       VARYING STATE FROM 1 BY 1
           UNTIL STATE IS GREATER THAN 50;
       AFTER COUNTY FROM FIRST-COUNTY (STATE) BY 1
           UNTIL COUNTY IS EQUAL TO LAST-COUNTY (STATE)
       AFTER CITY FROM FIRST-CITY (STATE COUNTY)
           UNTIL CITY IS EQUAL TO LAST-CITY (STATE COUNTY)
. . .
.

Example 8-66

for format 3 and 4, WITH TEST AFTER/BEFORE

IDENTIFICATION DIVISION.
PROGRAM-ID. PWTA.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
    TERMINAL IS T.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 N PIC 9.
77 K PIC 9(3).
77 Z PIC 9(4).
77 E PIC 9(4).
PROCEDURE DIVISION.
P1 SECTION.

 

Flowchart:

 

COMPUTATION.
    MOVE 0 TO Z.
    DISPLAY "Enter single-digit number as upper bound N" UPON T.
    ACCEPT N FROM T.
    PERFORM WITH TEST AFTER VARYING K FROM 1 BY 1 UNTIL K >= N
        COMPUTE E = K ** 3
        ADD E TO Z
    END-PERFORM
    DISPLAY "Result =" Z UPON T.
FIN.
    STOP RUN.

The program calculates the nth sum of the cube of an integer K. Only after the COMPUTE and ADD statements are executed is there a test to see whether the termination condition is satisfied.

If TEST BEFORE is specified, the termination condition is tested first. If K <= N, the in-line statements are executed. If K > N, the PERFORM statement is terminated with END-PERFORM.