COBOL Stop Run, GO Back and Exit Program

STOP Run Vs GOBACK  Vs Exit Program in COBOL: Stop Run, Go Back and Exit statements are to give control back from the program (in which these are coded as a last statement) to where this program is being called.  All works in the same by giving the control back but one gives it to OS where as other one gives control to different location. Lets see how there controls works in COBOL.

STOP RUN:
As the name implies it stops the execution of the program and gives control back to OS. With STOP RUN all the programs that are dynamically allocated are also deleted from the run unit. As it gives the control back to OS, It is advised to use only in Main modules. Not suggested to use in Sub-programs as it gives control back to OS where the sub program supposed send control back to its main module. It also  closes all the files associated in that run unit.

GOBACK:
If used in a sub program, it gives control back to the called module. In a standalone module it works same as STOPRUN by giving control back to OS. So this can be used both in Main and Sub modules. It does not change the status of the files that are used in that run unit. But if the program issuing GOBACK has INITIAL attribute, then it closes all the files in that program.

EXIT Program:
This is valid only in subprograms. This statement coded in sub programs, gives the control back to the called program. It is similar to GOBACK used in sub programs. Same as GOBACK, EXIT Program also does not change the status of the files used. It also closes all the files in that program if it has INITIAL attribute.

Difference Between GOBACK and EXIT Program
GOBACK can be used in standalone programs but EXIT program is for sub programs only. For Subprograms use both works similarly.

Difference Between STOP RUN and GOBACK:
STOP RUN ideal use is for Main programs or Stand alone programs but it can be used in Sub programs as well where it returns control to OS. Goback can be used in both Main and sub programs. It works similar to STOPRUN in main modules and in sub modules it gives control to main programs.

For more detailed information on this check the IBM link given below

IBM LINK

Add a Comment

Your email address will not be published. Required fields are marked *

Close Bitnami banner