Stop Run in both called and calling programs.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Leena
Registered Member
Posts: 30
Joined: Fri Aug 09, 2013 10:17 pm

Stop Run in both called and calling programs.

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Stop Run in both called and calling programs.

Post 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.
Leena
Registered Member
Posts: 30
Joined: Fri Aug 09, 2013 10:17 pm

Re: Stop Run in both called and calling programs.

Post 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?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1886
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Stop Run in both called and calling programs.

Post 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" .
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Stop Run in both called and calling programs.

Post 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 :-)
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1886
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Stop Run in both called and calling programs.

Post 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.
Leena
Registered Member
Posts: 30
Joined: Fri Aug 09, 2013 10:17 pm

Re: Stop Run in both called and calling programs.

Post 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.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1886
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Stop Run in both called and calling programs.

Post 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.
Leena
Registered Member
Posts: 30
Joined: Fri Aug 09, 2013 10:17 pm

Re: Stop Run in both called and calling programs.

Post by Leena »

Thanks all. :)
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”