For Programmers: Free Programming Magazines  


Home > Archive > Cobol > August 2005 > question concerning evaluate.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author question concerning evaluate.
Pat Hall

2005-08-25, 6:55 pm

A friend emailed me this question today:

I think this is the case, but I want to confirm it. On the AS/400 when
you have two consecutive WHEN clauses of a EVALUATE, like below, the
first won't do anything and the second will do the code.

Evaluate Color

When 'Blue '
When 'Green'
Compute Z = X * Y
Compute A = Z * Z
Compute B = A - 25

End Evaluate


For some reason I thought there would be an implied "and" between the
two when statements but I can find no basis for this assumption.

PatH
Chris

2005-08-25, 6:55 pm

I'm not on an AS400, I'm using MF products on HP-UX, but I don't
believe that is relevant, as this should be the standard:

"If a WHEN phrase is selected, execution continues with the first
imperative statement following the selected WHEN phrase."

So - there's not really an implied AND, there's an implied OR.

In your example, the code will get executed if Color = 'Blue' OR Color
= 'Green'.

If you don't want it to do anything when Color = 'Blue', you'd need
something like this:

Evaluate Color

When 'Blue'

Continue

When 'Green'

Compute Z = X * Y
Compute A = Z * Z
Compute B = A - 25

End-evaluate



Hope that helps!

Chris

bfwd

2005-08-25, 6:55 pm

Some versions allow for the reserved word ALSO between conditions for a
single WHEN. If you have time, put your code in a test program and try
it out.

Pat Hall

2005-08-25, 6:55 pm

Chris wrote:
> I'm not on an AS400, I'm using MF products on HP-UX, but I don't
> believe that is relevant, as this should be the standard:
>
> "If a WHEN phrase is selected, execution continues with the first
> imperative statement following the selected WHEN phrase."
>
> So - there's not really an implied AND, there's an implied OR.
>
> In your example, the code will get executed if Color = 'Blue' OR Color
> = 'Green'.
>
> If you don't want it to do anything when Color = 'Blue', you'd need
> something like this:
>
> Evaluate Color
>
> When 'Blue'
>
> Continue
>
> When 'Green'
>
> Compute Z = X * Y
> Compute A = Z * Z
> Compute B = A - 25
>
> End-evaluate
>
>
>
> Hope that helps!
>
> Chris
>

Thanks Chris I'll pass that on.

PatH
docdwarf@panix.com

2005-08-25, 6:55 pm

In article <11grnght6t0ntad@corp.supernews.com>,
Pat Hall <phall@notsospam.certcoinc.com> wrote:
>A friend emailed me this question today:
>
>I think this is the case, but I want to confirm it. On the AS/400 when
>you have two consecutive WHEN clauses of a EVALUATE, like below, the
>first won't do anything and the second will do the code.
>
>Evaluate Color
>
>When 'Blue '
>When 'Green'
> Compute Z = X * Y
> Compute A = Z * Z
> Compute B = A - 25
>
>End Evaluate
>
>
>For some reason I thought there would be an implied "and" between the
>two when statements but I can find no basis for this assumption.


As I understand it there is an OR between the conditions, not an AND...
what you post would be equivalent to:

If Color = 'Blue ' or Color = 'Green'
Compute Z = X * Y
Compute A = Z * Z
Compute B = A - 25
End-If

.... assuming, of course, that the compiler does not have 'Color' as a
reserved word.

DD

Howard Brazee

2005-08-25, 6:55 pm


On 25-Aug-2005, Pat Hall <phall@notsospam.certcoinc.com> wrote:

> I think this is the case, but I want to confirm it. On the AS/400 when
> you have two consecutive WHEN clauses of a EVALUATE, like below, the
> first won't do anything and the second will do the code.
>
> Evaluate Color
>
> When 'Blue '
> When 'Green'
> Compute Z = X * Y
> Compute A = Z * Z
> Compute B = A - 25
>
> End Evaluate


What happens with each of the following:

Blue is true and Green is false.
Blue is false and green is true.
Blue is false and green is false.
Blue is true and green is true.

I suspect you will find out that the first When is *not* ignored.


> For some reason I thought there would be an implied "and" between the
> two when statements but I can find no basis for this assumption.


It should be an implied "or"
Howard Brazee

2005-08-25, 6:55 pm


On 25-Aug-2005, "bfwd" <bforward@texarkanacollege.edu> wrote:

> Some versions allow for the reserved word ALSO between conditions for a
> single WHEN. If you have time, put your code in a test program and try
> it out.


Those aren't quite the same thing.
Chris

2005-08-25, 6:55 pm

The ALSO condition is used when evaluating multiple variables.


For example:


Evaluate Color-1 ALSO Color-2

When 'BLACK' ALSO 'White'

Display "Black & White'

When 'Black' ALSO 'Blue'

Display "Black & Blue"

End-Evaluate

This would be equivalent to:


If Color-1 = 'Black' and Color-2 = 'White'
Display "Black & White"
End-if

If Color-1 = 'Black' and Color-2 = 'Blue'
Display "Black & Blue"
End-if

Lueko Willms

2005-08-25, 6:55 pm

.. On 25.08.05
wrote phall@notsospam.certcoinc.com (Pat Hall)
on /COMP/LANG/COBOL
in 11grnght6t0ntad@corp.supernews.com
about question concerning evaluate.


PH> When 'Blue '
^
PH> When 'Green'
PH> Compute Z = X * Y
PH> Compute A = Z * Z
PH> Compute B = A - 25
PH>
PH> End Evaluate


Is that blank in "Blue " in the data, too?


Besides, as has been explained before, the sequence of WHEN clauses
acts like a OR combination of the clauses.



Yours,
Lüko Willms http://www.willms-edv.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --

Man stattete ihm sehr heißen, schon etwas verbrannten Dank ab. -G.C.Lichtenberg
William M. Klein

2005-08-25, 6:55 pm

Just so it is clear, allowing and the meaning of ALSO is part of the '85
Standard. One of the EARLIER drafts of that Standard didn't include it, so some
VERY OLD compilers (e.g. VS COBOL II, R1) didn't allow it, but all conforming
compilers do. It *could* be used to create an "AND" situation, but I have never
seen code like this in the real-world,

"ALSO as AND" example

Evaluate Color Also Color
When "Bule" also "Black"
Display "This is an impossible 'AND' situation"
...

--
Bill Klein
wmklein <at> ix.netcom.com
"bfwd" <bforward@texarkanacollege.edu> wrote in message
news:1124985049.959491.21780@g14g2000cwa.googlegroups.com...
> Some versions allow for the reserved word ALSO between conditions for a
> single WHEN. If you have time, put your code in a test program and try
> it out.
>



Lueko Willms

2005-08-25, 6:55 pm

.. On 25.08.05
wrote ctaliercio@yahoo.com (Chris)
on /COMP/LANG/COBOL
in 1124991122.345963.257830@g44g2000cwa.googlegroups.com
about Re: question concerning evaluate.


c> Evaluate Color-1 ALSO Color-2
c> When 'BLACK' ALSO 'White'
c> Display "Black & White'
c> When 'Black' ALSO 'Blue'
c> Display "Black & Blue"
c> End-Evaluate
c>
c> This would be equivalent to:

Semantically yes, seen the values compared, formally not, but
equivalent to:

c> If Color-1 = 'Black' and Color-2 = 'White'
c> Display "Black & White"
ELSE
c> If Color-1 = 'Black' and Color-2 = 'Blue'
c> Display "Black & Blue"
c> End-if
END-IF


Except that when it is part of _one_ EVALUATE statement, the
compiler can (I repeat: CAN, or MAY) produce a more efficient object
code, e.g. some code which would rather correspond to this IF/ELSE-
construct:


IF Color-1 = 'Black'
IF Color-2 = 'White'
DISPLAY "Black & White"
ELSE
IF Color-2 = 'Blue'
DISPLAY "Black & Blue"
END-IF
END-IF
END-IF



Yours,
Lüko Willms http://www.willms-edv.de
/--------- L.WILLMS@jpberlin.de -- Alle Rechte vorbehalten --

Es ist eine ganz bekannte Sache, daß die Viertel_stündchen_ größer sind als die Viertel_stunden_. -G.C.Lichtenberg
LX-i

2005-08-25, 6:55 pm

Pat Hall wrote:
> A friend emailed me this question today:
>
> I think this is the case, but I want to confirm it. On the AS/400 when
> you have two consecutive WHEN clauses of a EVALUATE, like below, the
> first won't do anything and the second will do the code.
>
> Evaluate Color
>
> When 'Blue '
> When 'Green'
> Compute Z = X * Y
> Compute A = Z * Z
> Compute B = A - 25
>
> End Evaluate
>
>
> For some reason I thought there would be an implied "and" between the
> two when statements but I can find no basis for this assumption.


That would be because it is an incorrect assumption. :) When a WHEN
clause is satisfied, control passes to the next *executable* statement
in the program. (It's an OR.) A second WHEN is a conditional
statement, not an executable one.

Now, once you hit one that works, execution will continue to the next
WHEN clause at the same nesting level, then jump to the termination of
the EVALUATE. So, given

evaluate this
when "that"
when "the-other-thing"
display "hi"
when "something-else"
display "bye"
end-evaluate

If this is equal to "that", you'll see "hi" and nothing else.


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ daniel@thebelowdomain ~
~ _____ / \ | ~ http://www.djs-consulting.com ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~
~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~
~ h---- r+++ z++++ ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
Chris

2005-08-26, 6:55 pm

I completely agree with Luko on this one - whenever possible I use
EVALUATE as opposed to nesting multiple IF - ELSE conditions.

In my experience, the larger the nested IF statements become, the
greater improvement in application performance I have gained by
converting them to EVALUATE statements instead.

Howard Brazee

2005-08-26, 6:55 pm


On 26-Aug-2005, "Chris" <ctaliercio@yahoo.com> wrote:

> In my experience, the larger the nested IF statements become, the
> greater improvement in application performance I have gained by
> converting them to EVALUATE statements instead.


And large IF and EVALUATE statements don't tend to shrink over time. The more
likely the logic is to need maintenance, the bigger the gain is in using
EVALUATE.
Chuck Stevens

2005-08-29, 6:55 pm

> That would be because it is an incorrect assumption. :) When a WHEN
> clause is satisfied, control passes to the next *executable* statement
> in the program. (It's an OR.) A second WHEN is a conditional
> statement, not an executable one.


As I read the standard, right idea, wrong terminology. If the criteria for
a given WHEN clause are met, execution continues with the first *imperative*
statement following the WHEN (one might even say *contained within*) the
WHEN clause, and from there to the statement following END-EVALUATE (or the
implicit end of the EVALUATE statement). Note that *an* imperative
statement may consist of a *sequence of* imperative statements.

Thus, WHEN is not a *statement* at all, it's a clause of the EVALUATE. It
isn't because it's a "conditional statement" that it's not executed, it's
that the rules for WHEN basically say when you're done executing the
imperative statements associated with a WHEN you're done executing the
EVALUATE.

-Chuck Stevens


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com