STOP RUN Statement


The STOP RUN statement is used to terminate the execution of a program. Once STOP RUN is executed, control returns to the operating system.

STOP RUN should be the last executable statement in the program and always coded in the calling or main program. If STOP RUN 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----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SRPROG.
	   AUTHOR. MTH.
	   
       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.

Expalining Example -

In the above example, once the age is checked and the result is displayed, the STOP RUN statement is executed, which terminates the program and returns control to the environment that initiated the program.