sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 4: PROCEDURE DIVISION . . .  
   
  PERFORM STATEMENT  
   
 

The PERFORM statement can be used to execute a group of consecutive statements written elsewhere in the program. We shall refer to this group of statements as the range of the PERFORM statement. During execution, when a PERFORM statement is encountered, a temporary departure from the normal sequential execution takes place and the statements contained in the specified range are executed. Upon execution of the said statements, the control implicitly returns to the next statement following the PERFORM statement. It is also possible to get the statements in the said range executed repetitively for a specified number of times or until a condition is satisfied.

 
   
  SIMPLE PERFORM STATEMENT
 
   
   
 

The statement group beginning with the first statement of the procedure named in procedure-name-1 and ending with the last statement of the procedure names in procedurename- 2, constitutes the range consists of the statements contained in the procedure referred to by procedure-name-1. when the simple PERFORM statement is executed, this range is executed only once.

Example:


 
 

PERFORM CALCUALTE-TAX.

 
 

In this example, CALCULATE-TAX is either a section name or paragraph name. Suppose it is a section name. All the statements contained in this section will be executed as a result of the execution of the PERFORM statement and after the execution of these statements, the control will come back to the statement following the PERFORM statement.

 
  PERFORM BEGIN-CALCULATION THRU END-CALCULATION.  
 

Suppose, BEGIN-CALCULATION and END-CALCULTION are paragraph names. The execution of the above PERFORM statement will cause the execution of the group of the statements starting with the first statement of BEGIN-CALCULATION and ending with the last statement of end-calculation. It may be noted that there may be other paragraphs in between these two paragraphs. All these paragraphs area also included in the range. Upon the execution of the range, the control returns to the statement following the PERFORM statement.

It may be noted that the return of control after the execution of the statements in the specified range takes place implicitly. This means that at the end of the range, the programmer should not put any statement (such as GO TO) to transfer the control explicitly to the statement following the PERFORM statement.


 
  Important:

 
 
A GO TO statement is allowed within the range of a PERFORM statement. However, it is the responsibility of the programmer to ensure that the control Ultimately reaches the last statement of the range.
There is no restriction as to what can be the last statement of a range except that it cannot be a GO TO statement. When an IF sentence is used at the end of a range, the next sentence (specified implicitly or explicitly) for that IF sentence refers to the return mechanism.
The use of a PERFORM statement within the range of another PERFORM Statement is allowed. The sequence of ranges specified in the Nested PERFORM statements should neither overlap nor share the same Terminal statement.