Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

MODULE 7: COBOL Control statements


ALTER statement

  • The ALTER statement changes the transfer point specified in a GO TO statement
  • During program execution, using ALTER statement it is possible to modify the targets of GO TO statements written elsewhere in the PROCEDURE DIVISION
  • Basic syntax:-

    ALTER paragraph-1 TO [PROCEED TO] paragraph-2       [, paragraph-3 TO [PROCEED TO] paragraph-4]…

  • Use of ALTER statement mandates that paragraph-1, paragraph-3 must contain only one GO TO statement without DEPENDING phrase
  • During the execution, the ALTER statement has ability to replace the actual parameters of GO TO coded in paragraph-1, paragraph-3 by paragraph-2, paragraph-4 etc. respectively
  • Example:-
    In PROCEDURE DIVISION,

    PARA-0. IF WS-X = 1 THEN GO TO SELECT-PATH ELSE IF WS-X = 2 THEN GO TO SEPECT PATH TO PROCEED TO PATH-2 ELSE IF WS-X = 3 THEN ALTER SELECT-PATH TO PROCEED TO PATH-3 END-IF. STOP RUN. SELECT-PATH. GO TO PATH-1.

  • Explanation of above code is as given below:-
    • When WS-X=1, control will be transferred to SELECT-PATH where again control is transferred to PATH-1.
    • If WS-X = 2, transfer point of SELECT-PATH is replaced from PATH-1 to PATH-2 and thus control will be transferred to PATH-2.
    • Similarly, if WS-X =3, transfer point of GO TO code in SELECT-PATH is modified to PATH-3 and the control will be transferred to PATH-3.
    • If any subsequent statement does GO TO SELECT-PATH, then control will be transferred to new para altered by most recent ALTER statement






© copyright mainframebug.com
Privacy Policy