Professional Documents
Culture Documents
ch09 97
ch09 97
Copyright @ 2000 John Wiley & Sons, In. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express permission of the copyright owner is unlawful. Request for further information should be addressed to the permissions Department , John Wily & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.
9th Edition
OBJECTIVES
To familiarize you with:
CONTENTS
The Simple PERFORM Reviewed
The Basic Formats Modularizing Programs Using PERFORM Statements Nested PERFORM: A PERFORM within a PERFORM Executing a Group of Paragraphs with a Simple PERFORM The Use and Misuse of GO TO Statements The EXIT Statement
Structured COBOL Programming, Stern & Stern, 9th Edition
CONTENTS
Iteration Using Other Types of PERFORMs
PERFORM UNTIL(A Review)
PERFORM VARYING
Using Nested PERFORM VARYING Statements The PERFORM WITH TEST AFTER Option (COBOL 85)
Structured COBOL Programming, Stern & Stern, 9th Edition
END-PERFORM
All instructions within the PERFORM ... END-PERFORM are executed in sequence.
Periods are optional after any scope terminator except at the end of a paragraph, when they are required.
Structured COBOL Programming, Stern & Stern, 9th Edition
PERFORM [paragraph-name-1]
The PERFORM paragraph-name statement will:
1. Execute all instructions in the named paragraph.
2. Transfer control to the next instruction in sequence, after the PERFORM paragraphname.
Structured COBOL Programming, Stern & Stern, 9th Edition
PERFORM
. Statements
.
.
to be performed
go here
END-PERFORM
Structured COBOL Programming, Stern & Stern, 9th Edition
PARAGRAPH
. . {Statements to be performed go here
GO TO paragraph-name-1
Unlike the PERFORM, which returns control to the statement following the PERFORM, the GO TO permanently transfers control to another paragraph. However, in well-designed, structured programs it is best to avoid the use of GO TO as much as possible.
Structured COBOL Programming, Stern & Stern, 9th Edition
Format 2
PERFORM [paragraph-name-1] [{THROUGH} {THRU} paragraphname-2] UNTIL condition-1
Any simple or compound condition can be specified in a PERFORM UNTIL ... As with a simple PERFORM, COBOL 85 permits an in-line PERFORM UNTIL
this format also uses END-PERFORM as a scope terminator.
Structured COBOL Programming, Stern & Stern, 9th Edition
1. Be preceded by an instruction that initializes the field to be tested (e.g., MOVE 0 TO COUNTER1).
2. Include a PERFORM UNTIL ... that is executed repeatedly UNTIL the field to be tested reaches the desired value
(e.g., PERFORM UNTIL COUNTER1 = 5 or PERFORM UNTIL COUNTER1 >= 5).
Structured COBOL Programming, Stern & Stern, 9th Edition
PERFORM TIMES
Format
PERFORM TIMES
When using the TIMES format --
PERFORM TIMES
The THRU clause is optional with any PERFORM paragraph-name statement. When using the integer option with the PERFORM TIMES format, only the actual number is acceptable.
DEBUGGING TIP
Use PERFORM TIMES rather than PERFORM UNTIL if you know in advance the specific number of times a paragraph is to be executed. If the number of times a paragraph is to be executed is variable use a PERFORM UNTIL. It is also best to use a PERFORM UNTIL if the number of times a paragraph is being executed needs to be used for output.
Structured COBOL Programming, Stern & Stern, 9th Edition
PERFORM VARYING
The last format for a PERFORM statement is the most comprehensive:
PERFORM paragraph-name-1 [{THROUGH} {THRU} paragraphname-2] VARYING identifier-1 FROM {identifier-2}{integer-1} BY {identifier-3} {integer-2} UNTIL condition-1
Structured COBOL Programming, Stern & Stern, 9th Edition
PERFORM paragraph-name-1
[WITH TEST {BEFORE} {AFTER}]
UNTIL condition-1
With COBOL 85, if an in-line PERFORM is used, no paragraph-name is coded,
Statements within the PERFORM end with an END-PERFORM scope terminator.
Structured COBOL Programming, Stern & Stern, 9th Edition
Note that PERFORM UNTIL (with no WITH TEST clause) and PERFORM WITH TEST BEFORE UNTIL do the same thing.
Structured COBOL Programming, Stern & Stern, 9th Edition
CHAPTER SUMMARY
A. Formats of the PERFORM Statement
CHAPTER SUMMARY
After execution of the instructions within either the PERFORM ... END-PERFORM or in the PERFORM paragraph-name, control is transferred to the statement directly following the PERFORM.
CHAPTER SUMMARY
b. If the condition in the UNTIL clause is met at the time of execution, then the named paragraph(s) will not be executed at all. With COBOL 85, the WITH TEST AFTER clause can be used to test the condition after the paragraph has been executed once.
CHAPTER SUMMARY
4. The PERFORM VARYING statement
a. The counter or loop control field must be defined in the DATA DIVISION, typically in WORKING-STORAGE. An initial VALUE for the loop control field is not required.
CHAPTER SUMMARY
(3) Continues with the statement directly following the PERFORM if the condition specified in the UNTIL clause is satisfied. (4) Executes the named paragraph(s) if the condition specified in the UNTIL clause is not met. (5) After execution of the named paragraph(s), increases (or decreases) the counter by the value of the integer or identifier specified in the VARYING clause.
CHAPTER SUMMARY
B. Additional Considerations
1. The THRU option can be included with all versions of the PERFORM but we recommend that you avoid this option.
2. PERFORM statements within PERFORM statements are permissible. These are called nested PERFORMs.
CHAPTER SUMMARY
3. EXIT is a reserved word that can be used to indicate the end point of paragraph(s) being performed.
EXIT must be the only entry in a paragraph when it is used with COBOL 74.
4. In-line PERFORMs are permitted in COBOL 85 with all PERFORM options; with in-line PERFORMs it is not necessary to code separate paragraphs.
The PERFORM is terminated with an ENDPERFORM.
Structured COBOL Programming, Stern & Stern, 9th Edition