Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageI'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
Post Follow-up to this messageSome 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.
Post Follow-up to this messageChris 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
Post Follow-up to this messageIn 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
Post Follow-up to this messageOn 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"
Post Follow-up to this messageOn 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.
Post Follow-up to this messageThe 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
Post Follow-up to this message.. 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
Post Follow-up to this messageJust 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. >
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.