View previous topic :: View next topic
|
Author |
Message |
i_suman
New User
Joined: 01 Mar 2005 Posts: 20
|
|
|
|
Hello,
I observed control going to CONTINUE in WHEN OTHER clause even though already a condition has been satisfied. Is it how an EVALUATE behaves when CONTINUE is used in OTHER clause?
Example:
EVALUATE ctry-cd
WHEN 'CA'
MOVE 'CA' TO ws-ctry-cd
WHEN 'UK'
MOVE 'UK' TO ws-ctry-cd
WHEN 'US'
MOVE 'US' TO ws-ctry-cd
WHEN OTHER
CONTINUE
END-EVALUATE.
Lets say for example, ctry-cd value is 'CA'. As per the condition it moves 'CA' to ws-ctry-cd and interestingly control goes to CONTINUE statement.
Control is not coming to CONTINUE statement when I tried coding some display statements in place of CONTINUE in OTHER condition.
Could some one explain why control goes like that?
Thanks |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Why do you believe the code is doing this "interestingly control goes to CONTINUE statement"?
Control is (or should be) going to the next statement after the end-evaluate when the value is 'CA'. |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Quote: |
I observed control going to CONTINUE in WHEN OTHER clause even though already a condition has been satisfied. |
How did u observe that, are you using XPED or INTERTSET to monitor every step at run time execution.If yes then don't get confused by it.
I believe and as Dick has suggested the control will go to the statement following the end-evaluate once the condition meets.
Cris |
|
Back to top |
|
|
rajeshmel
New User
Joined: 03 Nov 2008 Posts: 1 Location: India
|
|
|
|
Even if you use XPED or INTERTEST, you can see control going to END-EVALUATE which may again confuse you as control going to CONTINUE.
Otherwise, there is no difference in using CONTINUE or any other statement. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Try this:
Code: |
WHEN OTHER
Display"i want to Disply this"
EVALUATE ctry-cd
WHEN 'CA'
MOVE 'CA' TO ws-ctry-cd
WHEN 'UK'
MOVE 'UK' TO ws-ctry-cd
WHEN 'US'
MOVE 'US' TO ws-ctry-cd
END-EVALUATE. |
|
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
Anuj,
Doesn't the WHEN OTHER clause need to be inside the EVALUATE, not outside of it? I assume that's a typo.
i_suman,
Put DISPLAYs after each WHEN clause, including the WHEN OTHER, and I think you'll see that what you thought was happening really wasn't true. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Terry Heinze wrote: |
Doesn't the WHEN OTHER clause need to be inside the EVALUATE, not outside of it? I assume that's a typo. |
Yes sir, Thanks for correcting me:
Code: |
EVALUATE ctry-cd
WHEN OTHER
Display"i want to Disply this"
WHEN 'CA'
MOVE 'CA' TO ws-ctry-cd
WHEN 'UK'
MOVE 'UK' TO ws-ctry-cd
WHEN 'US'
MOVE 'US' TO ws-ctry-cd
END-EVALUATE. |
Quote: |
control going to CONTINUE in WHEN OTHER clause |
due to this I just wanted to epphasise that it's not the position of CONTINUE which determines the flow instead it's just what you've coded, Thanks. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Anuj,
Just a thought
Code: |
EVALUATE ctry-cd
WHEN OTHER
Display"i want to Disply this"
WHEN 'CA'
MOVE 'CA' TO ws-ctry-cd
WHEN 'UK'
|
AFAIK have always seen WHEN OTHER coded at the last after all the conditions are checked.
I think there might be differences in the output by coding this way .If not for all, atleast for few scenarios. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
I've also always seen the test for OTHER coded last since that's what makes logical sense. I suspect that an Assembler programmer could tell us what the compiler generates when OTHER is coded first. I'm willing to bet the conditions are tested in the order coded except for the OTHER condition which is tested last. I'd do it myself but currently don't have access to a mainframe. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Terry,
Quote: |
I'd do it myself but currently don't have access to a mainframe. |
Same here . It would be great if some one can test and let us know. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
ok, I tested it with enterprise cobol. burnt up enough of my customers cpu cycles with that, did not bother to try cobol 2.
both <EVALUATE TRUE> and <EVALUATE variable> when immediately followed by a WHEN OTHER catches the following error:
Quote: |
IGYPS2140-S "OTHER" was found in a "WHEN" phrase of an "EVALUATE" statement.
|
when I move the WHEN OTHER to the 'end', compiles clean. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
Thanks for the info Dick. I would have guessed that the compiler would have moved the WHEN OTHER clause to the end and given us a warning, but apparently it wants us to use our heads when we code! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
To return to the original request. . .
The "WHEN OTHER" code will not be executed if some other WHEN in the EVALUATE is true.
Quote: |
but apparently it wants us to use our heads when we code! |
Be excellent if the compiler would do that more often |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Dick,
Quote: |
ok, I tested it with enterprise cobol |
Thanks Dick for testing. Now its clear. |
|
Back to top |
|
|
|