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

When OTHER in EVALUATE


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
i_suman

New User


Joined: 01 Mar 2005
Posts: 20

PostPosted: Mon Nov 03, 2008 8:50 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Mon Nov 03, 2008 9:00 am
Reply with quote

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
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Mon Nov 03, 2008 12:54 pm
Reply with quote

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
View user's profile Send private message
rajeshmel

New User


Joined: 03 Nov 2008
Posts: 1
Location: India

PostPosted: Mon Nov 03, 2008 3:45 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Tue Nov 04, 2008 4:21 am
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Tue Nov 04, 2008 8:33 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Sat Nov 08, 2008 3:54 am
Reply with quote

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
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Sat Nov 08, 2008 10:25 am
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Sat Nov 08, 2008 11:03 am
Reply with quote

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
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Sat Nov 08, 2008 11:05 am
Reply with quote

Terry,

Quote:
I'd do it myself but currently don't have access to a mainframe.


Same here icon_sad.gif . It would be great if some one can test and let us know.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Nov 08, 2008 1:55 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Sat Nov 08, 2008 7:59 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Sat Nov 08, 2008 10:33 pm
Reply with quote

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 icon_confused.gif
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Sun Nov 09, 2008 12:14 pm
Reply with quote

Dick,

Quote:
ok, I tested it with enterprise cobol


Thanks Dick for testing. Now its clear.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Evaluate variable to execute a jcl step JCL & VSAM 3
No new posts Evaluate statement, when-clause in co... COBOL Programming 10
No new posts Generate report with out using IF/EVA... COBOL Programming 25
This topic is locked: you cannot edit posts or make replies. Want to put in a loop in EVALUATE COBOL Programming 24
No new posts Evaluate statement - clarification COBOL Programming 2
Search our Forums:

Back to Top