STOP RUN vs GOBACK
Problem Description
Explain and demonstrate the difference between STOP RUN and GOBACK.
Expected Output
Understanding program termination
Hints
STOP RUN ends program, GOBACK returns to caller.
Solution
IDENTIFICATION DIVISION.
PROGRAM-ID. MAINPROG.
* STOP RUN - Terminates the entire run unit
* GOBACK - Returns control to calling program
*
* Use STOP RUN in main programs
* Use GOBACK in subprograms called via CALL
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-MSG PIC X(30).
PROCEDURE DIVISION.
MOVE "MAIN PROGRAM EXECUTING" TO WS-MSG.
DISPLAY WS-MSG.
* For main program, use STOP RUN
STOP RUN.
*
* If this were a subprogram:
* GOBACK.
* Would return to the calling program
Explanation:
STOP RUN terminates run unit. GOBACK returns to caller (use in subprograms).