Module 6: Procedure Division
EXIT PROGRAM
- Program can be terminated using STOP RUN, but this statement will directly return control back to OS regardless of whether it is used in a sub program or main program
- Generally, when we call sub routine, we expect the control should be transferred back to main program once processing is done in sub-program. For this purpose, we can use ‘EXIT PROGRAM’
- EXIT PROGRAM is last executable statement of sub-program and it returns control back to main program
- Syntax:-
EXIT PROGRAM.
- Example:-
Main program code snippet:-
PROCEDURE DIVION.
DISPLAY 'HELLO WORLD.'
CALL SUB-PROG.
STOP RUN.
Sub-program "SUB-PROG" code snippet:-
LINKAGE SECTION.
.
.
PROCEDURE DIVION.
DISPLAY ‘SUB-PROGRAM IS CALLED’
EXIT PROGRAM.