Page 1 of 1
Stop Run in both called and calling programs.
Posted: Mon Jun 09, 2014 12:33 pm
by Leena
Hi,
What happens if we use STOP RUN in both called and calling program?
To get an answer about this I read that, if you give STOP RUN in the Called program, the control won't be returned to the calling program after executing the called program. So, one need to use GO BACK always in the called program to transfer the control back to it's Calling program. However, Stop Run or Go Back both work fine in the main program. My question why is it so, what happens when we issue the STOP RUN and why it does not halt the excution of main program?
Thanks.
Re: Stop Run in both called and calling programs.
Posted: Mon Jun 09, 2014 2:00 pm
by William Collins
STOP RUN causes return to the Operating System. GOBACK causes return to the program which called it. In the case of the program which is the entry-point used to satisfy EXEC PGM=... in the JCL, the Operating System has "called" the program, so STOP RUN and GOBACK give the same results.
It is much more flexible to use GOBACK. The allows you to have a program which CALLs your "main program" and which can, for instance, interrogate the RETURN-CODE from your "main program". With STOP RUN, this would not be possible.
Re: Stop Run in both called and calling programs.
Posted: Mon Jul 06, 2015 2:16 pm
by Leena
Thanks. I've got one more question:
This is reason when we talk about IMS or CICS then we always use GOBACK and the COBOL program works as a "sub-program" which sends the return back to the IMS or CICS?
But then how IMS and CICS behave as we've not coded anything to make them work with zOS?
Re: Stop Run in both called and calling programs.
Posted: Mon Jul 06, 2015 6:04 pm
by Robert Sample
The Enterprise COBOL
Language Reference manual has a table to define what happens with a STOP RUN:
Code: Select all
_________ _________________________________ _____________________________
| Terminat|on | |
| statemen| Main program | Subprogram |
|_________|_________________________________|_____________________________|
| STOP | Returns to the calling program. | Returns directly to the |
| RUN | (Can be the system, which | program that called the |
| | causes the application to end.) | main program. (Can be the |
| | | system, which causes the |
| | | application to end.) |
|_________|_________________________________|_____________________________|
When STOP RUN is used in IMS or CICS, the "system" is IMS or CICS -- not the operating system. Note the wording the manual uses -- STOP RUN in a subprogram returns to the "program that called the main program" .
Re: Stop Run in both called and calling programs.
Posted: Mon Jul 06, 2015 8:17 pm
by William Collins
Code STOP RUN in a CICS or IMS program at your peril, however. I was told never to do that, so I've never tried it. I assume there are consequences :-)
Re: Stop Run in both called and calling programs.
Posted: Mon Jul 06, 2015 10:52 pm
by Robert Sample
Merely coding STOP RUN in a CICS program is no big deal (and actually COBOL requires a program termination statement -- EXIT PROGRAM, GOBACK, STOP RUN -- be present for the program to be syntactically correct).
However, if CICS actually executes that STOP RUN statement .... well, CICS was invoked from the operating system (and hence functions as a main program), and your transaction runs under CICS (hence your program functions as a subprogram) with predictable consequences as the manual I quoted indicates. The CICS region comes down. I assume IMS would function the same way, but don't have any experience with it to say for sure.
Re: Stop Run in both called and calling programs.
Posted: Tue Jul 07, 2015 4:41 pm
by Leena
Robert Sample wrote:Merely coding STOP RUN in a CICS program is no big deal (and actually COBOL requires a program termination statement -- EXIT PROGRAM, GOBACK, STOP RUN -- be present for the program to be syntactically correct).
What will happen if it actually gets executed?? And, for that matter, what condition can be that where the STOP RUN never gets executed, I wonder? Can you please elaborate on it.
Re: Stop Run in both called and calling programs.
Posted: Tue Jul 07, 2015 5:54 pm
by Robert Sample
My post explicitly stated what happens if the STOP RUN gets executed -- the CICS region comes down. Typical coding would be
Code: Select all
EXEC CICS RETURN END-EXEC.
STOP RUN.
so the STOP RUN cannot be executed.
Re: Stop Run in both called and calling programs.
Posted: Sun Jul 26, 2015 9:55 am
by Leena
Thanks all.
