Microsoft KB Archive/59561

Example and Explanation of the COBOL ALTER Statement

PSS ID Number: Q59561 Article last modified on 03-26-1990

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

Summary: This article explains the COBOL ALTER statement. The function of the ALTER statement is to modify a GO TO jump. Upon execution of the ALTER statement, the subsequent action of the modified GO TO statement(s) transfers control to the procedure name specified in the ALTER statement syntax. ALTER is now considered an obsolete COBOL language element and is currently supported to allow for upward compatibility. (The ANSI 1985 COBOL specification standard calls for the ALTER statement to be removed in the next ANSI standard of COBOL.) The following information applies to Microsoft COBOL Versions 1.07, 1.10, 1.12, 2.00, 2.10, 2.20, 3.00, and 3.00a for MS-DOS and MS OS/2.

More Information: The general format of the ALTER statement is as follows: ALTER procedure1 TO [PROCEED TO] procedure2 [procedure3 TO [PROCEED TO] procedure4] … The ALTER statement refers to a paragraph name (for example, procedure1, procedure3, etc.) that includes a GO TO statement as a single sentence only. Furthermore, the GO TO verb cannot contain the DEPENDING clause. If the paragraph has additional sentences, erratic actions will occur (note: the output derived from the sample program when the comment in 200-sub is removed exhibits improper action). The sample program, ALTER.CBL, shown below demonstrates the use of the ALTER statement. Compile and LINK as follows: COBOL ALTER.CBL ; LINK ALTER.CBL ;

Code Example
$SET ANS85 IDENTIFICATION DIVISION. WORKING-STORAGE SECTION. 77 stall      PIC X.   PROCEDURE DIVISION. ALTER 200-sub TO PROCEED TO see-alter. DISPLAY &quot;In Main&quot;. 200-sub. *     DISPLAY &quot;In sub 200&quot;. GO TO do-not-alter. do-not-alter. DISPLAY &quot;Did not alter&quot;. STOP-RUN. see-alter. DISPLAY &quot;Did the alter waggle!!!!&quot;. STOP-RUN.

Program Output (with Comment)
In Main Did the alter waggle!!!!

Program Output (No Comment)
In Main In sub 200 Did not alter

Copyright Microsoft Corporation 1990.