Search code examples
ibm-midrangecobol

Exit Program in AS400 cobol still continue to run


I dont know why the succeeding section is still running after the Exit Program.

Here is my code:


       IDENTIFICATION DIVISION.                                   
       PROGRAM-ID. PGM2.                                      
      /                                                           
       ENVIRONMENT DIVISION.                                      
       CONFIGURATION SECTION.                                     
       SOURCE-COMPUTER.                                IBM-AS400. 
       OBJECT-COMPUTER.                                IBM-AS400. 
      /                                                           
       DATA DIVISION.                                             
       WORKING-STORAGE SECTION.                                   
       01  WS-VARS                        PIC X(10).              
      /                                                           
       PROCEDURE DIVISION.                                        
       000-MAIN SECTION.                                          
      ******************                                          
       010-START.                                                 
      *                                                           
           INITIALIZE WS-VARS.                                    
      *                                                           
       090-EXIT.                                                  
           EXIT PROGRAM.                                          
      /                                                           
       200-WRITE-LINE SECTION.       
      ************************       
       210-START.                    
      *                              
           DISPLAY 'STILL RUNNING'.  
      *                              
       290-EXIT.                     
           EXIT.                     
      /

This program is being called in another program. After the Exit Program, I am expecting it to return to the program that calls it but it is still continuing to run. Please help me to understand why.

Edit: I found out that if the calling program is another COBOL program, it will exit the program as per my expectation. But it seems that if the calling program is a CLP, the EXIT PROGRAM does not exiting.


Solution

  • This is because EXIT PROGRAM only leaves the program to the COBOL caller.

    What you want to do (in nearly all cases) is to use GOBACK as it always leaves the run unit, no matter how it was invoked. If it was CALLed from COBOL, it has the same effect as EXIT PROGRAM, otherwise as STOP RUN.