IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

EXIT or RETURN


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
cvnlynn

New User


Joined: 14 Jun 2017
Posts: 31
Location: US

PostPosted: Wed Jul 19, 2017 2:50 am
Reply with quote

What's the correct way to end the REXX program. Thanks.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Wed Jul 19, 2017 4:09 am
Reply with quote

If the program is a top-level routine (i.e., invoked directly from TSO or IRXJCL), there is no difference, although exit may be clearer. Otherwise, of course, return should be used.
Back to top
View user's profile Send private message
cvnlynn

New User


Joined: 14 Jun 2017
Posts: 31
Location: US

PostPosted: Wed Jul 19, 2017 4:46 am
Reply with quote

Thanks.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Wed Jul 19, 2017 9:41 pm
Reply with quote

Quote:
If the program is a top-level routine (i.e., invoked directly from TSO or IRXJCL)

I do not think that is the best description. Within a PDS member, you have a main routine (the first lines of the member) and it can call subroutines that are included also within the member. For this main routine of the member, the EXIT or RETURN do not make a difference. For any internal subroutines, use RETURN. If you use EXIT from an internal subroutine, it will flush the entire member.

It makes no difference if the PDS member was called from TSO or IRXJCL or from a separate rexx PDS member.
Back to top
View user's profile Send private message
cvnlynn

New User


Joined: 14 Jun 2017
Posts: 31
Location: US

PostPosted: Thu Jul 20, 2017 12:00 am
Reply with quote

so, would it be safe to always use RETURN ?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Jul 21, 2017 11:40 am
Reply with quote

You RETURN from a sub-routine to a higher level. At the highest level you END (i.e. EXIT) the task (program).


Edit: added (i.e. EXIT) to clarify as per Pedro's comment following.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Fri Jul 21, 2017 9:23 pm
Reply with quote

Quote:
You RETURN from a sub-routine to a higher level. At the highest level you END the task (program).


It is not clear what you mean by 'END'; perhaps you meant EXIT. You can issue RETURN from the highest level and it will return the caller which might be the operating system.

I think it is almost always safe to use RETURN.

You might want to issue EXIT during various error situations where you intend to flush the entire program.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Fri Jul 21, 2017 9:49 pm
Reply with quote

This my personal preference.

As a former COBOL programmer before coding Rexx full time, I believe in the single entry/single exit philosophy.

I code my programs as such.

I also like one EXIT statement at the end of my main code. This way I can easily tell that everything after that is an internal subroutine.

I use labels to signify the beginning and end of each subroutine.

Here is a sample of my structure. Feel free to use or ignore. Nasty remarks not required.

Code:
/* REXX PROGRAM A*/

/* MAINLINE CODE */
V1 = 'VALUE1'
CALL SUBROUTINE1
IF V1 = 'ERROR' THEN SIGNAL EXIT99
CALL SUBROUTINE2
EXIT99: NOP
EXIT

/* SUBROUTINE1 CODE */
SUBROUTINE1: NOP
V1 = 'ERROR'
EXIT_SUBROUTINE1: NOP
RETURN

/* SUBROUTINE2 CODE */
SUBROUTINE2: NOP
V1 = 'OK'
EXIT_SUBROUTINE2: NOP
RETURN
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Sat Jul 22, 2017 12:13 pm
Reply with quote

According to TRL2:
Quote:
If no internal routine (subroutine or function) is active, then RETURN has the identical effect on the program that is being executed as EXIT (see page 54).

But, like Dave, I like to RETURN from subroutines/functions and EXIT from my program at the end.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2019
Location: USA

PostPosted: Sun Jul 23, 2017 10:07 am
Reply with quote

The rule of thumb: use RETURN at every point of normal program/function/(sub)routine end, and use EXIT at every point of abnormal termination, e.g. unrecoverable error encountered.
Back to top
View user's profile Send private message
Willy Jensen

Active Member


Joined: 01 Sep 2015
Posts: 712
Location: Denmark

PostPosted: Mon Jul 24, 2017 8:08 pm
Reply with quote

I like to have a common exit point like in the following snippet, because then I don't have to return up through levels with the bad RC.

Code:
 
 Call Init                                       
 Call Main                                       
 Call Close 0 'Normal end of program'             
Close:                                           
 . . . do whatever cleanup is necessary . . .     
 parse arg n m                                   
 if m<>'' then say m                             
 Exit word(n 0,1)                                 
                                                 
Init: /* initialization routine */               
 . . .                                           
 deflib=userid()'.DEF.LIB'                       
 cc=Sysdsn("'"deflib"'")                         
 if cc<>'OK' then call close 8 'Sysdsn' deflib 'failed -' cc       
 . . .     
 Return 0                                       
Back to top
View user's profile Send private message
cvnlynn

New User


Joined: 14 Jun 2017
Posts: 31
Location: US

PostPosted: Mon Jul 24, 2017 9:00 pm
Reply with quote

Quote:
/* SUBROUTINE1 CODE */
SUBROUTINE1: NOP
V1 = 'ERROR'
EXIT_SUBROUTINE1: NOP
RETURN


please tell me the meaning for NOP in the LABEL statement, and the EXIT_SUBROUTINE1:NOP.
Thanks.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Mon Jul 24, 2017 9:06 pm
Reply with quote

Please read the z/OS TSO/E REXX Reference (PDF) for the answers to your questions.
Back to top
View user's profile Send private message
cvnlynn

New User


Joined: 14 Jun 2017
Posts: 31
Location: US

PostPosted: Mon Jul 24, 2017 10:12 pm
Reply with quote

thanks
Back to top
View user's profile Send private message
cvnlynn

New User


Joined: 14 Jun 2017
Posts: 31
Location: US

PostPosted: Mon Jul 24, 2017 10:58 pm
Reply with quote

Quote:
SUBROUTINE2: NOP
V1 = 'OK'
EXIT_SUBROUTINE2: NOP

Hi Daveporcelan,
please tell me why we need to code NOP in the LABEL statement. Thanks.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Mon Jul 24, 2017 11:25 pm
Reply with quote

This is again personal preference.

The CALL SUBROUTINE2 statement will execute the first statement after the colon :

So without the NOP, it would execute the V1= 'OK'.

I want to always execute a NOP rather than an unknown statement.

Also, if I search for ': NOP' all, I can see the beginning and end of each subroutine.

So, I do not need to code NOP, it is my preference.
Back to top
View user's profile Send private message
cvnlynn

New User


Joined: 14 Jun 2017
Posts: 31
Location: US

PostPosted: Mon Jul 24, 2017 11:49 pm
Reply with quote

thanks.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2019
Location: USA

PostPosted: Thu Aug 17, 2017 2:14 am
Reply with quote

daveporcelan wrote:
This is again personal preference.

The CALL SUBROUTINE2 statement will execute the first statement after the colon :

So without the NOP, it would execute the V1= 'OK'.

I want to always execute a NOP rather than an unknown statement.

Also, if I search for ': NOP' all, I can see the beginning and end of each subroutine.

So, I do not need to code NOP, it is my preference.


1) Either with NOP, or without NOP, the next statement V1= 'OK' shall be executed mandatory. Either it is an "unknown" statement, or a "known" one. What is the difference?

2) NOP is used much more often for other more useful purposes in different places of the code. For instance (but not only) - to minimize required changes in a big if-then-else group after one part of it becomes empty, it can be replaced with:
Code:
if . . . . . . . . . . . . .
   {multi-line logical expression}
   . . . . . . . . . . . . . . . . . . . . . .   then
   nop
else do
   . . . . . . . . . . . . . . .
   {multi-line sequence of statements}
   . . . . . . . . . . . . . . .
end
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Thu Aug 17, 2017 4:57 pm
Reply with quote

Quote:
1) Either with NOP, or without NOP, the next statement V1= 'OK' shall be executed mandatory. Either it is an "unknown" statement, or a "known" one. What is the difference?


Like I said:
Quote:
So, I do not need to code NOP, it is my preference.


Like I also said:
Quote:
Here is a sample of my structure. Feel free to use or ignore. Nasty remarks not required.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Return codes-Normal & Abnormal te... JCL & VSAM 7
No new posts Use of Perform Thru Exit COBOL Programming 6
No new posts user exit in IBM Infosphere Optim DB2 8
No new posts VSAM return code 23 - for a Random read COBOL Programming 4
No new posts ACS exit routine JCL & VSAM 0
Search our Forums:

Back to Top