Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference Between exit program and goback

Status
Not open for further replies.

ramanaefds

Programmer
Dec 9, 2002
6
IN
Hi,

Please let me know if any major difference is there between exit program and goback apart from the below.

Exit program means must be coded in subrountine and control returns back to the calling program.

GOBACK can be code in subroutine as well as in mainprogram. If We code in mainprogram, it works as a stop run verb.If the same verb I coded in subrountine, it acts like exit program.

Thanks in advance
Ramana Murthy P.V.
 
Hi ramanaefds,

The behavior of GOBACK and EXIT PROGRAM depends on whether the program unit was CALLed.

If there is no CALL in effect (the unit is MAIN), GOBACK behaves as STOP RUN, and EXIT PROGRAM behaves as a comment (no effect): the code falls through to the next executable statement.

If there is a CALL (the unit is a subprogram), GOBACK is still STOP RUN, but EXIT PROGRAM comes alive, stops execution of the subprogam and returns control to the caller.

GOBACK as introduced in ANSI 85 as a catchall. There are programming situations (multi language, for example) where the main program unit is not always determined or known at coding time.

Dimandja
 
Dimandja,

GOBACK can be confusing, and your explanation contains a couple errors.

I like to think of it this way; GOBACK is the equivalent of the sequence:
Code:
   EXIT PROGRAM.
   STOP RUN.
Now, applying your explanation of EXIT PROGRAM, one can see that in a main program, GOBACK is the equivalent of STOP RUN (because EXIT PROGRAM has no effect in a main program); in a CALLed program, GOBACK is the equivalent of EXIT PROGRAM.

GOBACK has never been a part of any ANSI or ISO standard, but it is a very common extension. Tom Morrison
 
Tom,

Besides the fact that GOBACK is not ANSI, our posts seem to agree on everything else.

Dimandja
 
Dimandja,

In one paragraph you state:
If there is no CALL in effect (the unit is MAIN), GOBACK behaves as STOP RUN,...

In the next paragraph you state:
If there is a CALL (the unit is a subprogram), GOBACK is still STOP RUN... (emphasis added). But this not the case;
Code:
GOBACK
behaves as if it were an
Code:
EXIT PROGRAM.

... or am I missing something? [bugeyed] Tom Morrison
 
Tom,

You are right, I meant to say: If there is a CALL (the unit is a subprogram), GOBACK behaves as EXIT PROGRAM.

Thanks for picking that error out.

Dimandja
 
The IBM COBOL Language Reference manual confirms what Tom posted:

"The GOBACK statement functions like the EXIT PROGRAM statement when it is coded as part of a called program (or the EXIT METHOD statement when it is coded as part of an invoked method) and like the STOP RUN statement when
coded in a main program."

Dimandja
 
Hi All,
I've never seen EXIT PROGRAM (apart from in the manual) and would avoid using a statement that may or not do what it says on the tin (ie exit a program) depending on whether the program happens to be a main program or a subroutine.

My advice would be to use GOBACK everytime (particularly remembering those long oft days when STOP RUN used to bring down the CICs region).

Unless of course someone knows different......

Marc
 
Marc,

I agree -- GOBACK always works the way it reads. However, it is nonstandard, so some shops might ban it, and, though widely implemented, it may not be available on all compilers. Tom Morrison
 
Hi,

In the 25 years I am working with IBM mainframe COBOL, none of my customers is using EXIT PROGRAM or STOP RUN. No one! They all use GOBACK because it works better in all circumstances. IBM also gives the advice to use it.

Mainframe look-alike compilers have the same possibilities.

For example the older CA-REALIA COBOL versions had the possibility to create an independent EXE file that was also callable with the using option.

Also on the IBM mainframe you can make a program that can be an executable on its own and can be used as a called module. No problem. When it is executed with the exec statement, it can read a parm from the JCL:

//MYMOD EXEC PGM=MYMODULE,PARM='MYPARM'

In your cobol program, you need a linkage section with:

Code:
01  MYPARM.
    03  LENGTH-OF-MYPARM   PIC S9(4) COMP-4.
    03  MYPARM-DATA.
        05  FILLER OCCURS 1 TO 256 DEPENDING ON LENGTH-OF-MYPARM PIC X.

In fact I use it sometimes both on PC and on the mainframe. The fun of doing this on te mainframe is that the 'called module' can perform tests without a driver.

Regards,

Crox
 
Somebody told me once. Don't know if it is true.

In the old days of CICS/COBOL when you coded a STOP RUN, this verb acted too powerfull and it stopped the whole CICS region!

That's why IBM recommended it's own extesion: GOBACK. It acts the same as EXIT PROGRAM and STOP RUN, and it won't harm your CICS.
 
Yeah, Crox. I've used that technique as an easy to test a subpgm without having the mainline pgm written.

It works if the length of the passed data doesn't exceed the parm length limit. I think it's 99, but not sure.

Regards, Jack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top