View previous topic :: View next topic
|
Author |
Message |
warren
New User
Joined: 30 Aug 2006 Posts: 14 Location: Tampa, Florida
|
|
|
|
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 |
|
|
cpuhawg
Active User
Joined: 14 Jun 2006 Posts: 331 Location: Jacksonville, FL
|
|
|
|
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 |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
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:
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 |
|
|
cpuhawg
Active User
Joined: 14 Jun 2006 Posts: 331 Location: Jacksonville, FL
|
|
|
|
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 |
|
|
|