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

Can "EVALUATE" execute all conditions


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

New User


Joined: 06 Jul 2007
Posts: 5
Location: Chennai

PostPosted: Mon Jan 21, 2008 12:07 pm
Reply with quote

Here is my question?

Q1. What will be the output for the below code:
:

working-storage section.

77 A PIC 9 VALUE IS 1.

:

:

PROCEDURE DIVISION.

EVALUATE TRUE

WHEN A <2

DISPLAY "CASE2"

WHEN A = 1

DISPLAY "CASE1"

WHEN OTHER

DISPLAY "OTHER"

END-EVALUATE.

A: CASE2

Q2. What will be the output for the below code:

:

:

working-storage section.

77 A PIC 9 VALUE IS 1.

:

PROCEDURE DIVISION.

EVALUATE TRUE

WHEN A = 1

DISPLAY "CASE1"

WHEN A <2

DISPLAY "CASE2"

WHEN OTHER

DISPLAY "OTHER"

END-EVALUATE.

A: CASE1

But in my Program, I like to change the way how EVALUATE statement functions. i.e. I like to execute EVALUATE all conditions and like to take the last satisfied condition.

Is it possible, if so how ?

Thanks in Advance
Lalitha.
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Mon Jan 21, 2008 12:15 pm
Reply with quote

Hi.

Quote:
I like to change the way how EVALUATE statement functions. i.e. I like to execute EVALUATE all conditions and like to take the last satisfied condition


What does this mean?

EVALUATE always evaluates the satisifed condition. It can be first one or last one. If first one only satisfies, other condition won't be executed.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Mon Jan 21, 2008 12:33 pm
Reply with quote

Lalitha,

Use seperate IF loops.
Back to top
View user's profile Send private message
Aaru

Senior Member


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

PostPosted: Mon Jan 21, 2008 1:15 pm
Reply with quote

Lalitha,

Hi and welcome to the forums.

Quote:
What will be the output for the below code:


Why don't you test by coding the same?

As told, the control comes out of the EVALUATE loop as soon as the condition is satisfied. Use IF/THEN or EVALUATE based on your requirements.
Back to top
View user's profile Send private message
Lalitha Hima Bindu

New User


Joined: 06 Jul 2007
Posts: 5
Location: Chennai

PostPosted: Mon Jan 21, 2008 1:27 pm
Reply with quote

I heard "EVALUATE" can handle multiple conditions also. In the sense for Q1 even though the first When satisfies, still it will execute the second when and it will display the O/P as "CASE1". But I donot knowhow to achieve this using Evaluate.
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Mon Jan 21, 2008 2:16 pm
Reply with quote

Hi Lalitha,

As mentioned by Aaru

Quote:
As told, the control comes out of the EVALUATE loop as soon as the condition is satisfied.


In order to acheive o/p as "CASE1"
- Either u have to change the order of when clause in Evaluate
- Or use IF- ELSE
Back to top
View user's profile Send private message
varunvasudevan

New User


Joined: 10 Jan 2008
Posts: 4
Location: Chennai

PostPosted: Mon Jan 21, 2008 5:30 pm
Reply with quote

Hi Lalitha,
u have heard that EVALUATE will handle multiple condition.That s true but u have taken it in wrong meaning.Normally the IF condion can handle only two condions ie true or false.
if (cond)
........
else
.....
end-if.
otherwise u can use AND/OR with if statment.Other option is u should go for nested if statements.

But EVALUATE will handle multiple conditions by specifying conditions in WHEN clause.You can use one EVALUTE statement with multiple when coditions.
And regarding ur question, once a WHEN condition satisfies ,the control will exit from EVALUATE statment and it will go to next statement.So i think u should go for another command to take only the last satisfied condition.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Mon Jan 21, 2008 7:57 pm
Reply with quote

Hi Lalitha,

Quote:
I heard "EVALUATE" can handle multiple conditions also.


Don't listen to rumors, use the manuals.
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Mon Jan 21, 2008 8:56 pm
Reply with quote

hi Lalitha,
as far as a single EVALUATE statement is concerned, it can execute only one successful WHEN clause. if there are more than one WHEN clauses in the EVALUATE structure which satisfies the condition mentioned with the EVALUATE clause, the first satisfying WHEN clause is executed and the control moves to the END-EVALUATE statement. it does not check the other WHEN clauses as soon as one WHEN clause is executed.
Back to top
View user's profile Send private message
mnnarayankar

New User


Joined: 21 Jan 2008
Posts: 23
Location: bangalore

PostPosted: Thu Jan 24, 2008 3:44 pm
Reply with quote

Hi Lalitha,

In EVELUTE if any of the WHEN CONDITION is satisfied then pointer automatically come out of the END-EVALUATE statement.
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 Execute secondary panel of sdsf with ... CLIST & REXX 1
No new posts How to load to DB2 with column level ... DB2 6
No new posts PuTTY - "User is not a surrogate... IBM Tools 5
No new posts Fetch data from programs execute (dat... DB2 3
This topic is locked: you cannot edit posts or make replies. How To Write, Compile and Execute Cob... COBOL Programming 5
Search our Forums:

Back to Top