Microsoft KB Archive/59886

COBOL 3.00 PERFORM-TYPE Directive Explained

PSS ID Number: Q59886 Article last modified on 04-26-1991

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: The information below explains the COBOL PERFORM-TYPE directive. The PERFORM-TYPE directive can be used with three different parameters to control the operation of return jumps from nested PERFORM statements. The PERFORM statement’s action is similar to the BASIC language FOR-NEXT looping statement. The default parameter for the PERFORM-TYPE directive is PERFORM-TYPE “MF”. The following information applies to Microsoft COBOL Versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: Code examples (and their output) are available to illustrate the following discussion of the different PERFORM-TYPE dialects. These code examples are located in a file named COBPERFO in the Software Library. COBPERFO can be found in the Software Library by searching for COBPERFO, the Q number of this article, or S12539. COBPERFO was archived using the PKware file-compression utility. The COBOL PERFORM statement can be used to execute statements or paragraphs multiple times. When PERFORM statements are nested within each other, the action they take can change depending on the active PERFORM-TYPE directive. The exit point for each PERFORM is indicated by one of several different general forms: 1. With no special options, the PERFORM statement operates only on the next statement (which can in turn be a nested PERFORM statement). For example: PERFORM 6 TIMES. PERFORM 7 TIMES. DISPLAY “HELLO”. <– exit point of both PERFORMS 2. Several statements can be grouped together between a PERFORM and END PERFORM statement, in which case the END PERFORM statement indicates the exit point. 3. The exit point can be indicated by the PERFORM statement itself by using the procedure-name1 THROUGH procedure-name2 syntax. Note: The performance of the PERFORM loop is erratic when an outer loop exit point is reached before the inner loop completes. In Microsoft COBOL Versions 3.00 and 3.00a, there are three distinct COBOL dialects for the PERFORM-TYPE directive. The dialects and their implications are listed below: MF - Only the exit point of the innermost PERFORM loop currently being executed will be recognized and returned from when encountered. OSVS - The exit point of any PERFORM statement that is currently being executed will be recognized and returned from when encountered. This directive will allow a type of nesting unavailable in most modular languages (note the BASIC example below and the perform2.cbl program example). PERFORM statements with the same exit point can be nested safely to a depth of two. Further nesting of exit points causes abnormal behavior in the PERFORM statement and is not advised with this directive set. +—> FOR i = 1 TO 5 | +–> FOR j = 1 TO 5 +—> | NEXT i +–> NEXT j RM - The exit point of any PERFORM statement that is currently being executed will be recognized and returned when encountered. This directive is similar to the OSVS directive except that no nesting of PERFORM statements is allowed. In addition to PERFORM statement actions being regulated by directives, the statement can be altered by several other COBOL verbs. Of particular interest are verbs that change program structure (jump statements) and/or program variables (notably, perform counter variables and exit indicators). The following COBOL verbs were tested with the programs below to view program behavior: GO TO [ParagraphName]; EXIT [PROGRAM]; ALTER ParagraphName1 TO [PROCEED TO] ParagraphName2; STOP RUN; COMPUTE (with ADD, SUBTRACT, MULTIPLY and DIVIDE); The analysis of the PERFORM statement action due to these verbs is as follows: GO TO [ParagraphName] There are no special conditions when using the GO TO statement. If a jump outside the loop is executed, the iteration of the PERFORM is halted. If a jump inside a nested PERFORM is made to another area inside the PERFORM loop, the looping continues. EXIT [PROGRAM] An explicit EXIT statement, with or without the program verb, is recognized by all of the PERFORM-TYPE directives. When an EXIT statement is called (by an explicit GO TO ExitParagraphName statement), the program logic jumps out of the desired amount of PERFORM loops. If a called program encounters an EXIT PROGRAM statement, the program returns to the sentence preceding the CALL statement in the CALLing program. Note: The EXIT statement must be called by a GO TO to achieve its action. If a GO TO is not used, the EXIT statement proceeds to the next sentence and does nothing. ALTER The ALTER statement changes the action of a GO TO statement. This COBOL statement is, however, considered obsolete and is not ordinarily recommended for use. STOP RUN The STOP RUN statement halts program execution whether the statement is inside a looping structure or not. COMPUTE The COMPUTE verb (used with any of the mathematical operators) works as expected. However, be careful when altering the perform counter variables. If the counter variables are changed, the outcome of the loop can be altered drastically.

Copyright Microsoft Corporation 1991.