COBOL Exit Program

COBOL Stoprun COBOL Go Back

EXIT PROGRAM specifies that the program came to end.

EXIT PROGRAM also responsible for returning the control to the calling program.

EXIT PROGRAM always coded in subprogram.

EXIT PROGRAM passed control to the statement which is immediately next to the active CALL statement in the main program.

If no active CALL statement is active, EXIT PROGRAM passes the control to exit through next executable statement.



EXIT PROGRAM is a PROCEDURE DIVISION statement which will be coded in AREA B.

Practicle Example:

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.                                      
     EXIT PROGRAM.                                                

COBOL Stoprun COBOL Go Back