💻 COBOL
COBOL ALTER Statement
Intermediate 🕑 8 min read
👁 1 views
COBOL ALTER Statement
ALTER dynamically changes the target of a GO TO statement at runtime. This statement is obsolete and should be avoided.
Syntax
```cobol ALTER procedure-name-1 TO PROCEED TO procedure-name-2 ```
How It Works
Changes where a GO TO statement will transfer control.
Example
```cobol GO-PARA. GO TO DEFAULT-PARA.
... ALTER GO-PARA TO PROCEED TO SPECIAL-PARA. ```
Why Avoid ALTER
- Creates unpredictable program flow
- Makes debugging extremely difficult
- Code becomes hard to maintain
- Not thread-safe
- Considered harmful practice
Alternatives
- Use EVALUATE for multi-way branching
- Use 88-level conditions
- Use PERFORM THRU with conditions
Code Example
IDENTIFICATION DIVISION.
PROGRAM-ID. ALTER-DEMO.
* NOTE: ALTER is obsolete - shown for legacy code
PROCEDURE DIVISION.
MAIN-PARA.
GO TO INITIAL-PARA.
PROCESS-PARA.
DISPLAY 'In PROCESS-PARA'
GO TO END-PARA.
INITIAL-PARA.
DISPLAY 'First call - setting up'
ALTER PROCESS-PARA TO PROCEED TO MODIFIED-PARA
GO TO PROCESS-PARA.
MODIFIED-PARA.
DISPLAY 'In MODIFIED-PARA'
GO TO END-PARA.
END-PARA.
STOP RUN.