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
 

 

When OTHER in EVALUATE

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: When OTHER in EVALUATE
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

Site Director


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

PostPosted: Mon Nov 03, 2008 9:00 am    Post subject:
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    Post subject: Reply to: When OTHER in EVALUATE
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    Post subject:
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

Senior Member


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

PostPosted: Tue Nov 04, 2008 4:21 am    Post subject:
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: 1238
Location: Richfield, MN, USA

PostPosted: Tue Nov 04, 2008 8:33 pm    Post subject:
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

Senior Member


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

PostPosted: Sat Nov 08, 2008 3:54 am    Post subject:
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: 1288
Location: Chennai, India

PostPosted: Sat Nov 08, 2008 10:25 am    Post subject: Reply to: When OTHER in EVALUATE
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: 1238
Location: Richfield, MN, USA

PostPosted: Sat Nov 08, 2008 11:03 am    Post subject:
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: 1288
Location: Chennai, India

PostPosted: Sat Nov 08, 2008 11:05 am    Post subject: Reply to: When OTHER in EVALUATE
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    Post subject:
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: 1238
Location: Richfield, MN, USA

PostPosted: Sat Nov 08, 2008 7:59 pm    Post subject:
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

Site Director


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

PostPosted: Sat Nov 08, 2008 10:33 pm    Post subject:
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: 1288
Location: Chennai, India

PostPosted: Sun Nov 09, 2008 12:14 pm    Post subject: Reply to: When OTHER in EVALUATE
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Evaluate statement, when-clause in co... UmeySan COBOL Programming 10 Mon Jul 16, 2012 6:49 pm
No new posts Generate report with out using IF/EVA... bbharathiraj COBOL Programming 25 Tue May 22, 2012 10:19 am
This topic is locked: you cannot edit posts or make replies. Want to put in a loop in EVALUATE maxsubrat COBOL Programming 24 Fri Apr 06, 2012 3:35 pm
No new posts Evaluate statement - clarification Vijay Subramaniyan COBOL Programming 2 Fri Feb 03, 2012 1:53 pm
No new posts Evaluate true also true Bill Woodger COBOL Programming 6 Thu Aug 11, 2011 7:43 pm


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