Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

question concerning evaluate.
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

Report this thread to moderator Post Follow-up to this message
Old Post
Pat Hall
08-25-05 11:55 PM


Re: question concerning evaluate.
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


Report this thread to moderator Post Follow-up to this message
Old Post
Chris
08-25-05 11:55 PM


Re: question concerning evaluate.
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.


Report this thread to moderator Post Follow-up to this message
Old Post
bfwd
08-25-05 11:55 PM


Re: question concerning evaluate.
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

Report this thread to moderator Post Follow-up to this message
Old Post
Pat Hall
08-25-05 11:55 PM


Re: question concerning evaluate.
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


Report this thread to moderator Post Follow-up to this message
Old Post
docdwarf@panix.com
08-25-05 11:55 PM


Re: question concerning evaluate.
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"

Report this thread to moderator Post Follow-up to this message
Old Post
Howard Brazee
08-25-05 11:55 PM


Re: question concerning evaluate.
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Howard Brazee
08-25-05 11:55 PM


Re: question concerning evaluate.
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


Report this thread to moderator Post Follow-up to this message
Old Post
Chris
08-25-05 11:55 PM


Re: question concerning evaluate.
..    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.Lichtenb
erg

Report this thread to moderator Post Follow-up to this message
Old Post
Lueko Willms
08-25-05 11:55 PM


Re: question concerning evaluate.
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 conformin
g
compilers do.  It *could* be used to create an "AND" situation, but I have n
ever
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.
>



Report this thread to moderator Post Follow-up to this message
Old Post
William M. Klein
08-25-05 11:55 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:54 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.