Gentle Breeze

[COBOL] PERFORM statement <5> 본문

⑨ 직무역량강화/zOS COBOL

[COBOL] PERFORM statement <5>

재령 2009. 8. 8. 16:19

▶ PERFORM with VARYING phrase

The VARYING phrase increases or decreases the value of one or more identifiers or index-names, according to certain rules.

The format-4 VARYING phrase PERFORM statement can serially search an entire seven-dimensional table.

사용자 삽입 이미지


If procedure-name-1 is specified, imperative-statement-1 and the END-PERFORM phrase must not be specified. If procedure-name-1 is omitted, the AFTER phrase must not be specified.

identifier-2 through identifier-7

    Must name a numeric elementary item.
    These identifiers cannot be windowed date fields.

literal-1 through literal-4
 
    Must represent a numeric literal.

condition-1, condition-2

    If the condition is true at the time the PERFORM statement is initiated,
    the specified procedures are not executed.

    After the conditions specified in the UNTIL phrase are satisfied, control is
    passed to the next executable statement following the PERFORM statement.

    If any of the operands specified in condition-1 or condition-2 is subscripted,
    reference modified, or is a function-identifier, the subscript,
    reference-modifier, or function is evaluated each time the condition is tested.

Floating-point data items and literals can be used anywhere a numeric data item or literal can be specified.

When TEST BEFORE is indicated, all specified conditions are tested before the first execution, and the statements to be performed are executed, if at all, only when all specified tests fail. When TEST AFTER is indicated, the statements to be performed are executed at least once, before any condition is tested.

If neither the TEST BEFORE nor the TEST AFTER phrase is specified, the TEST BEFORE phrase is assumed.

▶ Varying identifiers

The way in which operands are increased or decreased depends on the number of variables specified. In the following discussion, every reference to identifier-n refers equally to index-name-n (except when identifier-n is the object of the BY phrase).

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 an augmenting operation.

The following figure illustrates the logic of the PERFORM statement when an identifier is varied with TEST BEFORE.

사용자 삽입 이미지


The following figure illustrates the logic of the PERFORM statement when an identifier is varied with TEST AFTER.



사용자 삽입 이미지


▶ Varying two identifiers

사용자 삽입 이미지

1. identifier-2 and identifier-5 are set to their initial values, identifier-3 and identifier-6, respectively.

2. condition-1 is evaluated as follows: a. If it is false, steps 3 through 7 are executed. b. If it is true, control passes directly to the statement following the PERFORM statement.

3. condition-2 is evaluated as follows: a. If it is false, steps 4 through 6 are executed. b. If it is true, identifier-2 is augmented by identifier-4, identifier-5 is set to the current value of identifier-6, and step 2 is repeated.

4. procedure-name-1 and procedure-name-2 are executed once (if specified).

5. identifier-5 is augmented by identifier-7.

6. Steps 3 through 5 are repeated until condition-2 is true.

7. Steps 2 through 6 are repeated until condition-1 is true.

At the end of PERFORM statement execution:

    * identifier-5 contains the current value of identifier-6.

    * identifier-2 has a value that exceeds the last-used setting by the increment or
      decrement value (unless condition-1 was true at the beginning of PERFORM
      statement execution, in which case, identifier-2 contains the current value of
      identifier-3).

The following figure illustrates the logic of the PERFORM statement when two identifiers are varied with TEST BEFORE.

사용자 삽입 이미지


The following figure illustrates the logic of the PERFORM statement when two identifiers are varied with TEST AFTER.

사용자 삽입 이미지


▶ Varying three identifiers

사용자 삽입 이미지


The actions are the same as those for two identifiers, except that identifier-8 goes through the complete cycle each time that identifier-5 is augmented by identifier-7, which, in turn, goes through a complete cycle each time that identifier-2 is varied.

At the end of PERFORM statement execution:

    * identifier-5 and identifier-8 contain the current values of identifier-6 and
       identifier-9, respectively.
 
    * identifier-2 has a value exceeding its last-used setting by one
       increment/decrement value (unless condition-1 was true at the beginning
       of PERFORM statement execution, in which case identifier-2 contains
       the current value of identifier-3).

▶ Varying more than three identifiers

You can produce analogous PERFORM statement actions to the example above with the addition of up to four AFTER phrases.

▶ Varying phrase rules

No matter how many variables are specified, the following rules apply:

* In the VARYING or AFTER phrases, when an index-name is specified:

    – The index-name is initialized and incremented or decremented according to
       the rules under “INDEX phrase”

    – In the associated FROM phrase, an identifier must be described as an
       integer and have a positive value; a literal must be a positive integer.

    – In the associated BY phrase, an identifier must be described as an integer;
       a literal must be a nonzero integer.

* In the FROM phrase, when an index-name is specified:

    – In the associated VARYING or AFTER phrase, an identifier must be described
       as an integer. It is initialized as described in the SET statement.

    – In the associated BY phrase, an identifier must be described as an integer
       and have a nonzero value; a literal must be a nonzero integer.

* In the BY phrase, identifiers and literals must have nonzero values.

* Changing the values of identifiers or index-names in the VARYING, FROM, and
   BY phrases during execution changes the number of times the procedures are
   executed.

'⑨ 직무역량강화 > zOS COBOL' 카테고리의 다른 글

[COBOL] PERFORM statement <6>  (0) 2009.08.08
[COBOL] PERFORM statement <4>  (0) 2009.08.08
[COBOL] PERFORM statement <3>  (0) 2009.08.08
[COBOL] PERFORM statement <2>  (0) 2009.08.08
[COBOL] PERFORM statement <1>  (0) 2009.08.08
Comments