Different types of PERFORM statements

1) Normal Perform,
In this type of PERFORM statements all the statements in the para are executed and the control of program is returned back to the next statement of PERFORM statement.Example of Normal PERFORM statement.
PROCEDURE DIVISION.
MAIN-PARAGRAPH.
DISPLAY ‘I AM IN MAIN PARAGRAPH’.
PERFORM ADD-PARA.
DISPLAY ‘SUM OF VALUE IS :’ A.   ADD-PARA.
COMPUTE A = B+C.
2) Perform from para to para.In this type of perform the program executes all the statements from the first statement of first para to last statements of second para.Example of PERFORM from para to para statement.

PROCEDURE DIVISION.
MAIN-PARAGRAPH.
DISPLAY ‘I AM IN MAIN PARAGRAPH’.
PERFORM A000-COMPUTE-PARA THRU A000-EXIT.
DISPLAY ‘SUM OF VALUE IS :’ A.   A000-COMPUTE-PARA.
COMPUTE A = B+C.
COMPUTE D= A*C.
COMPUTE A = D-A.
A000-EXIT.
3) Perform with timesThis is very similar to normal perform, except that in this type of perform we can specify how many times we want to execute same set of commands.Example of PERFORM with times.

PROCEDURE DIVISION.
MAIN-PARAGRAPH.
DISPLAY ‘I AM IN MAIN PARAGRAPH’.
PERFORM ADD-PARA 10 TIMES.
DISPLAY ‘SUM OF VALUE IS :’ A.   ADD-PARA.
COMPUTE A = B+C.
4) Perform with untilIn this type of perform all the statements in the para are executed till a given condition becomes true. It is very similar to while statement in C programming language. In the below example the para will will be executed until A is greater than 10.So, value of A will be 9.Example of PERFORM with until.

PROCEDURE DIVISION.
MAIN-PARAGRAPH.
DISPLAY ‘I AM IN MAIN PARAGRAPH’.
PERFORM ADD-PARA UNTIL A > 10.
DISPLAY ‘SUM OF VALUE IS :’ A.   ADD-PARA.
COMPUTE A = B+C.
5) Perform with test after until.It is similar to perform with until only difference is in this type of perform the condition is checked after the statements of the para are executed. It is similar to do while statement in C programming language. In below condition also the perform condition will be performed until A is greater than 10. But, since the condition is checked after the para is executed value of A will be 10 in this case.Example of PERFORM with test after until.

PROCEDURE DIVISION.
MAIN-PARAGRAPH.
DISPLAY ‘I AM IN MAIN PARAGRAPH’.
PERFORM ADD-PARA WITH TEST AFTER UNTIL A > 10.
DISPLAY ‘SUM OF VALUE IS :’ A.   ADD-PARA.
COMPUTE A = B+C.
6) Perform varying.In this type of perform all the statements in a para are executed until the incremented counter meets condition specified. It is similar to FOR statement in C programming language. Perform varying has a counter and condition on the perform statement.Example for perform varying is given below. To get factorial of a number.

PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY ” ENTER ANY NUMBER “.
ACCEPT N.
PERFORM X-PARA VARYING I FROM 1 BY 1 UNTIL I > N
MOVE F TO P.
DISPLAY ” THE FACTORIAL OF THE GIVEN NUMBER IS ” P.   X-PARA.
COMPUTE F = F * I.
Categories: COBOL

Leave a Reply