COBOL Stop run
STOP RUN is the last executable statement in the program which will returns the control back to OS.
STOP RUN always coded in the main program.
If STOP RUN coded in the sub program, the control will return to OS instead of returning to main program. In this case, the remaining task coded in main program will be incomplete.
STOP RUN closes all opened files in the program.
When the STOP RUN executed, immediately all running tasks by the program will be closed and control transfers to OS.
STOP RUN always terminates the current program execution regardless of the program type (main program or sub program).
Below example shows the subprogram calling from main program.
Main program - code:
IDENTIFICATION DIVISION. PROGRAM-ID. MAINPROG. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT1 PIC 9(02). 01 INPUT2 PIC 9(02). 01 OUT-PUT PIC 9(03). PROCEDURE DIVISION. ACCEPT INPUT1. ACCEPT INPUT2. CALL 'SUBPROG' USING INPUT1, INPUT2, OUT-PUT. DISPLAY OUT-PUT. STOP RUN.
Sub program - code:
IDENTIFICATION DIVISION. PROGRAM-ID. SUBPROG. ENVIRONMENT DIVISION. DATA DIVISION. LINKAGE SECTION. 01 IP1 PIC 9(02). 01 IP2 PIC 9(02). 01 OP PIC 9(03). PROCEDURE DIVISION USING IP1,IP2,OP. COMPUTE OP = IP1 * IP2. GO BACK.
COBOL Display Statement COBOL Exit Program