💻 COBOL
COBOL STOP Statement
Beginner 🕑 10 min read
👁 1 views
COBOL STOP Statement
The STOP statement terminates program execution or pauses for operator response.
Syntax
STOP RUN
STOP literal
Example Program
IDENTIFICATION DIVISION.
PROGRAM-ID. STOP-DEMO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-ERROR-FLAG PIC 9 VALUE 0.
88 HAS-ERROR VALUE 1.
88 NO-ERROR VALUE 0.
01 WS-RETURN-CODE PIC S9(4) COMP VALUE 0.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'Program starting...'
PERFORM PROCESS-DATA
IF HAS-ERROR
MOVE 8 TO WS-RETURN-CODE
MOVE WS-RETURN-CODE TO RETURN-CODE
DISPLAY 'Ending with error'
STOP RUN
END-IF
DISPLAY 'Normal completion'
MOVE 0 TO RETURN-CODE
STOP RUN.
PROCESS-DATA.
DISPLAY 'Processing data...'
SET NO-ERROR TO TRUE.
Expected Output
Program starting...
Processing data...
Normal completion
GOBACK vs STOP RUN
| STOP RUN | GOBACK |
|---|---|
| Terminates run unit | Returns to caller |
| Main program use | Subprogram use |
| Closes all files | Preserves caller's files |
Key Points
- STOP RUN terminates the entire run unit
- GOBACK returns control to calling program
- Set RETURN-CODE before STOP RUN for batch jobs
- STOP literal pauses execution (rarely used)