Summary -

In this topic, we described about the STOP RUN Statement with detailed example.

The STOP statement halts execution of the program either permanently or temporarily.

Syntax -


When STOP RUN is specified, it terminates the execution and control is returned to the system.

When STOP RUN is not the last or only statement in a sequence of imperative statements within a sentence, the statements following STOP RUN are not executed.

STOP RUN should be the last executable statement in the program. STOP RUN always coded in the calling program.

If STOP RUN coded in the sub program, the control returns to the system instead of returning it to main program. In this case, the remaining task coded in main program won't get completed.

When the STOP RUN executed, all running tasks by the program immediately closed and control transfers to system. When STOP RUN executed, it closes all opened files in the program.

Practical Example:

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.