View previous topic :: View next topic
|
Author |
Message |
Lalitha Hima Bindu
New User
Joined: 06 Jul 2007 Posts: 5 Location: Chennai
|
|
|
|
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 |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Lalitha,
Use seperate IF loops. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
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 |
|
|
Lalitha Hima Bindu
New User
Joined: 06 Jul 2007 Posts: 5 Location: Chennai
|
|
|
|
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 |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
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 |
|
|
varunvasudevan
New User
Joined: 10 Jan 2008 Posts: 4 Location: Chennai
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Lalitha,
Quote: |
I heard "EVALUATE" can handle multiple conditions also. |
Don't listen to rumors, use the manuals. |
|
Back to top |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
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 |
|
|
mnnarayankar
New User
Joined: 21 Jan 2008 Posts: 23 Location: bangalore
|
|
|
|
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 |
|
|
|