COBOL Manual for TNS and TNS/R Programs
Procedure Division
HP COBOL Manual for TNS and TNS/R Programs—522555-006
8-9
Statements
The detailed rules for scope termination are:
•
A conditional statement is composed of other statements. When no delimited-
scope statements occur in the conditional statement, the next phrase of the
conditional statement terminates the contained statement. In this example, the
ELSE phrase implicitly terminates the statement of the THEN phrase and the
separator period implicitly terminates the ELSE phrase:
IF CREDIT
THEN PERFORM POST-CREDIT
ELSE PERFORM POST-DEBIT.
•
When the last statement in a sentence is a conditional statement, the period
separator that terminates the sentence implicitly terminates the conditional
statement. In this example, the paragraph BOTTOM-LINE consists of a single
sentence. The period separator that ends the sentence ends the IF statement:
BOTTOM-LINE.
MOVE NET-SALES TO NET-S OF SALES-REC-DISPLAY
MOVE NET-PROFIT TO NET-P OF SALES-REC-DISPLAY
IF NET-PROFIT < 0
DISPLAY "Get Cracking!" UPON DIST-MGR-TUBE.
•
When statements are contained within other statements, a period separator that
terminates the sentence also implicitly terminates the scope of any contained
statements not yet terminated otherwise. In this example, the period separator
terminates both the READ and the IF statements:
IF AUXILIARY-INPUT-TAPE
READ AUX-TAPE
AT END PERFORM AUX-TAPE-ENDED
NOT AT END PERFORM PROCESS-AUX-REC.
•
A conditional statement can be nested within an IF statement, but not within any
other form of conditional statement. The preceding example shows a conditional
READ statement nested within an IF statement. It is not possible, for example, to
have a READ statement with an AT END phrase and no END-READ terminator
(making it a conditional statement) within another such READ statement’s AT END
phrase. Both must be provided with scope terminators as shown in this example:
READ PRIMARY-FILE
AT END READ SECONDARY-FILE
AT END DISPLAY "End of second file"
END-READ
END-READ