Module 6: Procedure Division
EXIT statement and END PROGRAM
- EXIT statement does nothing but as name suggests it is generally used to indicate end of paragraph(s)
- When executed, no action takes place
- Basic syntax:-
- In COBOL-74, when we code EXIT, then it should be only statement in a paragraph. However in COBOL-85,it is allowed to code it with other statements
In PROCEDURE DIVISION,PARA-0. DISPLAY 'IN PARA-0' PERFORM PARA-1 THRU PARA-1-EXIT. DISPLAY 'IN PARA-0 AGAIN' STOP RUN. PARA-1. DISPLAY 'IN PARA-1'. IF WS-X = 1 GO TO PARA-1-EXIT ELSE ADD 5 TO WS-X DISPLAY 'WS-X: ' WS-X END-IF. PARA-1-EXIT. EXIT.In above example, para-1 have two routes to return control back to PARA-0. When WS-X =’1’, directly it will reach to PARA-1-EXIT since GO TO statement is coded. In other cases, it will exit normally after adding 5 to WS-X and displaying WS-X.
- With COBOL-85, it is possible to include one program within scope of another program. The included program can in turn can be included in another program. This way, ‘nesting’ of program is possible in COBOL-85.
- Thus, in such cases END PROGRAM is used to mark the end of any program
END PROGRAM program-id.