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

REXX 'end' delimiter in select & do statements, no loopi


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

New User


Joined: 30 Aug 2006
Posts: 14
Location: Tampa, Florida

PostPosted: Thu Aug 31, 2006 7:44 pm
Reply with quote

I have to maintain REXX code that is as follows:
Code:

select
    when (a & b) then
    do
        say 'a & b'
        submit jcl
    end
    when (a & c) then
    do
        say 'a & c'
        submit jcl
    end
    when (a & d) then
    do
        say 'a & d'
        submit jcl
    end
    otherwise
        whatever
end


The 3 'when-do's are repeated roughly 50 times for different conditions,
before the 'otherwise'.

I don't understand the use of the 'end' delimiter in 'when-do's. It seems that there shoud be just one 'end' and it should go before the 'otherwise' statement. With all the 'end' delimiters used, it seems that each condition is checked even if the previous condition is true, which is grossly inefficient because only 1 of the conditions can be true (eg. a & b).

I looked in several manuals and IBM online doco but there is no clear explanation of the simple 'end' delimiter, except in 'do' LOOPS- not in a straight 'do' that has no loopomg, like above.

The code is obviously inefficient due to the contant repetition of the test for 'a', in the beginning of each compound condition. The 'submit jcl' statements are also repeated. But I haven't been able to find out if these simple 'end' delimiters need to be repeated.

Can anyone tell me whether all these 'end' delimiters are needed for each 'do' or if this is just inefficient programming?

Thanx!
Back to top
View user's profile Send private message
cpuhawg

Active User


Joined: 14 Jun 2006
Posts: 331
Location: Jacksonville, FL

PostPosted: Thu Aug 31, 2006 8:01 pm
Reply with quote

Every time you have a "THEN DO", you must have an END to close the "THEN DO".

You also need an "END" to close the SELECT.

The following code would prevent the use of so many END statements:

Code:

select
when (a & b) then say 'a & b'
when (a & b) then submit jcl
when (a & c) then say 'a & c'
when (a & c) then submit jcl
when (a & d) then say 'a & d'
when (a & d) then submit jcl
otherwise
whatever
end


If none of the whens are true, the program will execute the commands after "otherwise". If otherwise is missing, an error will result.
Back to top
View user's profile Send private message
Pedro

Global Moderator


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

PostPosted: Fri Sep 01, 2006 1:10 am
Reply with quote

Warren, you are mistaken about the syntax of the Select statement, which is:

Code:

Select
  When ( ) Then
  Otherwise
End


The DO is not part of the select statement. Following the WHEN and OTHERWISE, you can put any valid statement. Your code has:
Code:
 When (  )  Then   Do

Since the DO is not part of the SELECT, it wants to work like it always works: it has to have its normal delimiter, which is an end.

The DO / END statements are a way to group things together. I do not think the program will run without matching DO / END statements.

cpuhawg, I think your example is wrong. It will process one and only one WHEN statement. It will never do the second WHEN (A & B) THEN clause
Back to top
View user's profile Send private message
cpuhawg

Active User


Joined: 14 Jun 2006
Posts: 331
Location: Jacksonville, FL

PostPosted: Fri Sep 01, 2006 1:33 am
Reply with quote

Pedro,

You are correct. Once a When condition is met, the program will branch to the END statement associated with the SELECT statement.

All the logic could be re-written without SELECT, such as:

Code:

if (a & b) then do
    say 'a & b'
    submit jcl
    signal nextstep
end
if (a & c) then do
    say 'a & c'
    submit jcl
    signal nextstep
end
if (a & d) then do
    say 'a & d'
    submit jcl
    signal nextstep
end
whatever
nextstep:


If it submits JCL from any if the "IF/THEN DO", it will drop down to the logic following nextstep. If no JCL are submitted, the whatever logic will be executed and the program will continue onward.
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 Compile Several JCL JOB Through one r... CLIST & REXX 4
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts run rexx code with jcl CLIST & REXX 15
Search our Forums:

Back to Top