Working-Storage for all Examples
000340 01 PLANET. 000350 05 PLANET-NUMBER PIC 9. 000360 05 PLANET-NAME PIC X(7).
Evaluate Example Number 1 - Evaluate a PIC 9 field
004310 004320 EVALUATE PLANET-NUMBER 004330 WHEN 1 MOVE "Mercury" TO PLANET-NAME 004340 WHEN 2 MOVE "Venus " TO PLANET-NAME 004350 WHEN 3 MOVE "Earth " TO PLANET-NAME 004360 WHEN 4 MOVE "Mars " TO PLANET-NAME 004370 WHEN 5 MOVE "Jupiter" TO PLANET-NAME 004380 WHEN 6 MOVE "Saturn " TO PLANET-NAME 004390 WHEN 7 MOVE "Uranus " TO PLANET-NAME 004400 WHEN 8 MOVE "Neptune" TO PLANET-NAME 004410 WHEN 9 MOVE "Pluto " TO PLANET-NAME 004420 WHEN OTHER MOVE " " TO PLANET-NAME 004430 END-EVALUATE. 004440
Evaluate Example Number 2 - Evaluate a PIC X field
004310 004320 EVALUATE PLANET-NAME 004330 WHEN "Mercury" MOVE 1 TO PLANET-NUMBER 004340 WHEN "Venus " MOVE 2 TO PLANET-NUMBER 004350 WHEN "Earth " MOVE 3 TO PLANET-NUMBER 004360 WHEN "Mars " MOVE 4 TO PLANET-NUMBER 004370 WHEN "Jupiter" MOVE 5 TO PLANET-NUMBER 004380 WHEN "Saturn " MOVE 6 TO PLANET-NUMBER 004390 WHEN "Uranus " MOVE 7 TO PLANET-NUMBER 004400 WHEN "Neptune" MOVE 8 TO PLANET-NUMBER 004410 WHEN "Pluto " MOVE 9 TO PLANET-NUMBER 004420 WHEN OTHER MOVE 0 TO PLANET-NUMBER 004420 END-EVALUATE. 004430
Evaluate Example Number 3 - Evaluate True
004310 004320 EVALUATE TRUE 004330 WHEN PLANET-NAME = "Mercury" MOVE 1 TO PLANET-NUMBER 004340 WHEN PLANET-NAME = "Venus " MOVE 2 TO PLANET-NUMBER 004350 WHEN PLANET-NAME = "Earth " MOVE 3 TO PLANET-NUMBER 004360 WHEN PLANET-NAME = "Mars " MOVE 4 TO PLANET-NUMBER 004370 WHEN PLANET-NAME = "Jupiter" MOVE 5 TO PLANET-NUMBER 004380 WHEN PLANET-NAME = "Saturn " MOVE 6 TO PLANET-NUMBER 004390 WHEN PLANET-NAME = "Uranus " MOVE 7 TO PLANET-NUMBER 004400 WHEN PLANET-NAME = "Neptune" MOVE 8 TO PLANET-NUMBER 004410 WHEN PLANET-NAME = "Pluto " MOVE 9 TO PLANET-NUMBER 004420 WHEN OTHER MOVE 0 TO PLANET-NUMBER 004420 END-EVALUATE. 004430
|Comments Comments are left by visitors to FluffyCat.com and may or may not be accurate.|
|Comment by TheMadProfessor on 2007-11-16 Rate this Comment|
I would have to disagree with the poster regarding 88-levels in an EVALUATE. Any phrase that will evaluate to true or false at execution time is acceptable, so the following should work just fine:
|Comment by Anonymous on 2010-02-02 Rate this Comment|
The comment about using 88-levels isn't quite correct. You can use a construct such as
|Comment by Larry on 2013-05-22 Rate this Comment|
I like you indentation scheme of going in 2 for the WHEN and then going to a new line and indenting 2 more for the MOVE (or whatever will be done). Visually breaking the two up makes sense to me.
|Comment by rslitman on 2007-03-13 Rate this Comment|
I don't know if you have formatted the EVALUATEs the way you did in order to save space or if it is your style, but I prefer to put my WHENs on lines by themselves and then start what is to be done for each WHEN on a new line. I tried to illustrate it here by an example, but this software wouldn't take leading spaces, so I couldn't get it to indent properly.
|Comment by Anonymous on 2007-04-09 Rate this Comment|
You can't use 88-levels in a WHEN statement unless you're saying something like EVALUATE TRUE WHEN LIFE. But you may as well use IF.
|Comment by programmer123 on 2007-11-14 Rate this Comment|
Which is faster EVALUATE or IF? The answer is "who cares?" COBOL is not a speed language. It's value is in clarity.
|Comment by archive on 2010-11-16 Rate this Comment|
How do you interrogate a field using EVALUATE with level 88s in the input record?
|Comment by archive on 2007-04-09 Rate this Comment|
I have a doubt in an Evaluate statement. I am validating a file field with reference modification with the evaluate statement. It seems to work for valid data and not for the other caluse. Why? Any idea I would appreciate your help pls.
|Comment by archive on 2010-03-24 Rate this Comment|
We had a discussion today in a meeting about the speeds of the Evaluate and IF statements. Since this has sort of gone to the wayside because of the speed of computers some of the newer programmers like myself are not sure which is faster during runtime. Could you enlighten on which one is faster and under what type of conditions. Such as if the IF statement is structured so the most likely true statement is first would the evaluate still be faster?
|Sign in to comment on COBOL Evaluate.|