  | 
		
HP COBOL Reference Manual
 
 
Format 1 
 
 
  - Format 1 is the basic PERFORM statement. The statement sets in the
  PERFORM range execute once. Control then passes to the end of the
  PERFORM statement.
  
Format 2 
 
 
  - The statement sets execute the number of times specified by
  repeat-count. If the value of repeat-count is zero or
  negative when the PERFORM statement executes, control passes to the end
  of the PERFORM statement. 
 During PERFORM statement execution,
  changing the value of repeat-count does not change the number
  of times the statement sets execute.
  
Format 3 
 
 
  - The statement sets execute until cond is true. Control
  then transfers to the end of the PERFORM statement.
  
 - If cond is true when the PERFORM statement executes:
  
    - If there is a TEST BEFORE phrase or one is implied, there is no
    transfer to first-proc; control passes to the end of the
    PERFORM statement.
    
 - If there is a TEST AFTER phrase, the PERFORM statement tests
    cond after the statement set executes.
  
  
  
Format 4 
 
 
  - The Format 4 PERFORM statement systematically changes the value of
  var during its execution.
  
 - If var is an index-name, its value, when the PERFORM
  statement execution begins, must equal the occurrence number of an
  element in its table.
  
 - If init is an index-name, var must equal the
  occurrence number of an element in the table associated with
  init. As the value of the var index changes during
  PERFORM execution, it cannot contain a value outside the range of its
  table. However, when the PERFORM statement ends, the var index
  can contain a value outside the range of the table by one increment or
  decrement value.
  
 - increm must not be zero.
  
 - init must be positive when var is an index-name
  and init is an identifier.
  
 - If there is a TEST BEFORE phrase (or one is implied), and one
  var is varied (see Figure 6-3):
  
    - var is set to the value of init when the PERFORM
    statement begins to execute.
    
 - If cond is false, the statement set executes once. The
    value of var changes by the increment or decrement value
    (increm), and cond is evaluated again. This cycle
    continues until cond is true. Control then transfers to the
    end of the PERFORM statement.
    
 - If cond is true when the PERFORM statement begins
    executing, control transfers to the end of the PERFORM statement.
  
  
Figure 6-3 PERFORM ... VARYING with the TEST BEFORE Phrase and
One Condition
  
 
   - If there is a TEST BEFORE phrase (or one is implied), and the
  PERFORM statement has two vars (see Figure 6-4):
  
    - The first and second vars are set to the value of the
    first and second init when the PERFORM statement begins to
    execute.
    
 - If the first cond is true, control transfers to the end of
    the PERFORM statement.
    
 - If the second cond is false, the statement set executes
    once. The second var changes by the value of increm,
    and the second cond is evaluated again. This cycle continues
    until the second cond is true.
    
 - When the second cond is true, the value of the first
    var  changes by the value of the first increm, and
    the second var is set to the value of the second
    init. The first cond is reevaluated. The PERFORM
    statement ends if the first cond is true. Otherwise, the cycle
    continues until cond is true.
  
  
Figure 6-4 PERFORM ... VARYING with the TEST BEFORE Phrase and
Two Conditions
  
 
   - At the end of a PERFORM statement with the TEST BEFORE phrase:
  
    - The value of the first var exceeds the last-used value by
    one increment or decrement value. However, if cond was true
    when the PERFORM statement began, var contains the current
    value of init.
    
 - The value of each other var equals the current value of
    its associated init.
  
  
   - If there is a TEST AFTER phrase and one var is varied (see
  Figure 6-5):
  
    - var is set to the value of init when the PERFORM
    statement starts to execute.
    
 - The statement set executes once. Then, cond is evaluated.
    If it is false, the value of var changes by the increment or
    decrement value (increm), and the statement set executes
    again. This cycle continues until cond is true. Control then
    transfers to the end of the PERFORM statement.
  
  
Figure 6-5 PERFORM ... VARYING with the TEST AFTER Phrase and
One Condition
  
 
    - If there is a TEST AFTER phrase, and two vars are varied
  (see Figure 6-6):
  
    - The first and second vars are set to the value of the
    first and second init when the PERFORM statement starts to
    execute.
    
 - The statement set executes. The second cond is then
    evaluated. If it is false, the second var changes by the value
    of increm, and the statement set executes again. This cycle
    continues until the second cond is true.
    
 - When the second cond is true, the first cond is
    evaluated. If it is false, the value of the first var changes
    by the value of the first increm, the second var is
    set to the value of the second init, and the statement set
    executes again. The PERFORM statement ends if the first cond
    is true. Otherwise, the cycle continues until cond is
    true.
  
  
Figure 6-6 PERFORM ... VARYING with the TEST AFTER Phrase and
Two Conditions
  
 
   - At the end of a PERFORM statement with the TEST AFTER phrase, the
  value of each var is the same as at the end of the most recent
  statement set execution.
  
 - During execution of the sets of statements in the range, any change
  to var, increm, or init affects PERFORM
  statement operation.
  
 - When there is more than one var, var in each
  AFTER phrase goes through a complete cycle each time var in
  the preceding AFTER (or VARYING) phrase is varied.
  
Additional References 
 
 
Examples 
 
 
In the examples' results, s represents a space. The examples assume
these Data Division and Procedure Division entries:
 
 
  
    
       
      
DATA DIVISION.
WORKING-STORAGE SECTION.
01  ITEMA  VALUE "ABCDEFGHIJ".
    03  CHARA OCCURS 10 TIMES PIC X.
01  ITEMB  VALUE SPACES.
    03  CHARB OCCURS 10 TIMES PIC X.
01  ITEMC PIC 99  VALUE 1.
01  ITEMD PIC 99  VALUE 7.
01  ITEME PIC 99  VALUE 4.
01  ITEMF VALUE SPACES.
    03  ITEMG OCCURS 4 TIMES.
        05  ITEMH OCCURS 5 TIMES.
            07 ITEMI PIC 99.
PROCEDURE DIVISION.
   .
   .
   .
PROC-A.
    MOVE CHARA (ITEMC) TO CHARB (ITEMC).
PROC-B.
    MOVE CHARA (ITEMC) TO CHARB (10).
PROC-C.
    ADD 2 TO ITEMC.
PROC-D.
    MULTIPLY ITEMC BY ITEMD
                 GIVING ITEMI (ITEMC, ITEMD).
 |   
  - Performing one procedure (Format 1):
 
     ITEMB = Asssssssss
   - Performing a range of procedures (Format 1):
 
  
    
       
      
PERFORM PROC-A THRU PROC-B.
 
 |   
     ITEMB = AssssssssA
   - Performing a range of procedures (Format 2):
 
  
    
       
      
PERFORM PROC-A THRU PROC-C
  3 TIMES.
 
 |   
     ITEMB = AsCsEssssE
 
ITEMC = 07
   - Performing a range of procedures (Format 4):
 
  
    
       
      
PERFORM PROC-A THRU PROC-B
     VARYING ITEMC FROM 1 BY 1
  UNTIL ITEMC > 5.
 |   
     ITEMB = ABCDEssssE
 
ITEMC = 06
   - Testing the UNTIL condition after execution (Format 4):
 
  
    
       
      
PERFORM PROC-A THRU PROC-B
     TEST AFTER
     VARYING ITEMC FROM 1 BY 1
  UNTIL ITEMC > 5.
 |   
     ITEMB = ABCDEFsssF
 
ITEMC = 06
   - Performing a range of procedures varying a data item by a negative
  amount (Format 4):
 
  
    
       
      
PERFORM PROC-A THRU PROC-B
  VARYING ITEMC FROM ITEMD BY -1
  UNTIL ITEMC < ITEME.
 
 |   
     ITEMB = sssDEFGssD
 
ITEMC = 03
   - In-line PERFORM (Format 4):
 
  
    
       
      
PERFORM
  VARYING ITEMC FROM 1 BY 2
  UNTIL ITEMC > 7
   MOVE CHARA (ITEMC) TO CHARB (ITEMC)
   MOVE CHARA (ITEMC) TO CHARB (ITEMC + 3)
END-PERFORM.
 
 |   
     ITEMB = AsCAECGEsG
   - Varying two data items (Format 4):
 
  
    
       
      
PERFORM PROC-D
  VARYING ITEMC FROM 1 BY 1 UNTIL ITEMC > 4
  AFTER ITEMD FROM 1 BY 1 UNTIL ITEMD > 5.
 
 |   
     ITEMG (1) = 01s02s03s04s05s
 
ITEMG (2) = 02s04s06s08s10s
 
ITEMG (3) = 03s06s09s12s15s
 
ITEMG (4) = 04s08s12s16s20s
  
  
  
		 |