COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-17
ALTER
destination
is the name of a paragraph or section to which the GO TO statement in
paragraph-name transfers control.
Usage Considerations:
•
Maintenance Problems
ALTER can cause maintenance problems because it enables a GO TO statement
to transfer control anywhere in the program. When you read the source code, the
only clue you have that the destination was altered is that the GO TO statement is
alone in a paragraph.
•
Using a Flag, Conditional GO TO, and MOVE Instead of ALTER
Suppose that you want to initialize a routine the first time it is called, but not each
time it is called. You could either use an ALTER statement as Example 9-6 does
(not recommended) or a flag, a conditional GO TO statement, and a MOVE
statement as Example 9-7 does (recommended and no less efficient).
Example 9-6. ALTER Statement
PROCEDURE DIVISION.
ROUTINE-1.
GO TO INITIALIZATION-ROUTINE.
INITIALIZATION-ROUTINE.
...
ALTER ROUTINE-1 TO PROCEED TO ROUTINE-2.
GO TO ROUTINE-2.
ROUTINE-2.
...
Example 9-7. Alternative to ALTER Statement
DATA DIVISION.
WORKING-STORAGE SECTION.
77 FLAG VALUE IS 1.
PROCEDURE DIVISION.
ROUTINE-1.
GO TO INITIALIZATION-ROUTINE
ROUTINE-2
DEPENDING ON FLAG.
INITIALIZATION-ROUTINE.
...
MOVE 2 TO FLAG.
GO TO ROUTINE-2.
ROUTINE-2.
...