STOP RUN Statement
STOP RUN Statement
- The STOP RUN statement terminates a program's execution.
- Once STOP RUN is executed, control returns to the operating system.
- It should be the last executable statement in the program.
- It should always be coded in the main program. If it is coded in the subprogram, the control returns to the system instead of the main program.
Syntax -
1----+----2----+----3
STOP RUN
The STOP RUN statement doesn't have any parameters.
Processing -
When a COBOL program executes the STOP RUN, it performs the following actions -
- All files opened by the program are closed.
- Any buffered output is written to the respective output devices or files.
- Control is returned to the operating system.
Practical Example -
Scenario - Checks if a person is an adult based on age.
----+----1----+----2----+----3----+----4----+----5----+
...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-AGE PIC 9(3).
...
PROCEDURE DIVISION.
ACCEPT WS-AGE.
IF WS-AGE >= 18
DISPLAY "Person is an adult."
ELSE
DISPLAY "Person is not an adult."
END-IF.
STOP RUN.