Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

EXIT or RETURN

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
cvnlynn

New User


Joined: 14 Jun 2017
Posts: 29
Location: US

PostPosted: Wed Jul 19, 2017 2:50 am    Post subject: EXIT or RETURN
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: 1772
Location: Bloomington, IL

PostPosted: Wed Jul 19, 2017 4:09 am    Post subject:
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: 29
Location: US

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

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

Senior Member


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

PostPosted: Wed Jul 19, 2017 9:41 pm    Post subject: Reply to: EXIT or RETURN
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: 29
Location: US

PostPosted: Thu Jul 20, 2017 12:00 am    Post subject:
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: 1846
Location: UK

PostPosted: Fri Jul 21, 2017 11:40 am    Post subject:
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

Senior Member


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

PostPosted: Fri Jul 21, 2017 9:23 pm    Post subject: Reply to: EXIT or RETURN
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: 674
Location: Pennsylvania

PostPosted: Fri Jul 21, 2017 9:49 pm    Post subject:
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: 1846
Location: UK

PostPosted: Sat Jul 22, 2017 12:13 pm    Post subject:
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

Active User


Joined: 29 Apr 2008
Posts: 128
Location: Maryland

PostPosted: Sun Jul 23, 2017 10:07 am    Post subject:
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 User


Joined: 01 Sep 2015
Posts: 155
Location: Switzerland

PostPosted: Mon Jul 24, 2017 8:08 pm    Post subject:
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: 29
Location: US

PostPosted: Mon Jul 24, 2017 9:00 pm    Post subject:
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: 1772
Location: Bloomington, IL

PostPosted: Mon Jul 24, 2017 9:06 pm    Post subject:
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: 29
Location: US

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

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

New User


Joined: 14 Jun 2017
Posts: 29
Location: US

PostPosted: Mon Jul 24, 2017 10:58 pm    Post subject:
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: 674
Location: Pennsylvania

PostPosted: Mon Jul 24, 2017 11:25 pm    Post subject:
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: 29
Location: US

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

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

Active User


Joined: 29 Apr 2008
Posts: 128
Location: Maryland

PostPosted: Thu Aug 17, 2017 2:14 am    Post subject:
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: 674
Location: Pennsylvania

PostPosted: Thu Aug 17, 2017 4:57 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts QUESTION: RETURN CHANNEL pahiker CA Products 21 Thu Apr 20, 2017 12:31 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts MAX-RC 88 and Return code 606 in DFH0... lind sh CICS 2 Tue Jan 24, 2017 1:23 pm
No new posts How to Capture the Max return code of... anilkumar922 All Other Mainframe Topics 2 Thu Jan 12, 2017 12:02 pm
No new posts DFHWS2LS return value divated CICS 4 Mon Nov 07, 2016 5:44 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us