Re: Regarding EVALUATE TRUE



In article <1187204587.545493.218790@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
klshafer@xxxxxxx <klshafer@xxxxxxx> wrote:
Usually I follow the Doc's prescription for whatever ails me in COBOL,
as in...
'What is *this* stuff? EVALUATE TRUE WHEN cond-1 imperative
statement... you call this COBOL?!?'
'Oh, please, Mr Standards-and-Practises Reviewmeister, it is exactly what
is allowed by the ANSI '85 Standard.'

Eh? Such praise would cause me to blush, Mr Shafer, were I able to
remember how - it's been so long! - but that is not a 'prescription', it
is a paraphrasing of interchanges I've had with folks who are confronted
by some of the constructs I use.


But allow me to put forth something about EVALUATE TRUE which causes
me, uh, discomfort... Is it that I nearly swallowed too much of the
Doc's medicine :-) ? More likely, the prescription was just a lil' too
hard for me to read... gotta upgrade those glasses from a 1.75 power
to a 2.00 power, ya know...


Anyway, consider the following -
_two_ distinct "indicator" data elements IND-SNOW and IND-SKY, each
with multiple 88-levels, and a numeric TEMP.

Looking at -
EVALUATE TRUE
WHEN TEMP > 80
PERFORM 100-SWEAT
WHEN SKY-IS-BLUE (an 88 on IND-SKY)
PERFORM 200-SMILE
WHEN SNOW-IS-FALLING (an 88 on IND-SNOW)
PERFORM 300-EXTEND-UMBRELLA
WHEN OTHER
PERFORM 400-STAY-HOME
END-EVALUATE

Because there is an implicit exit from the EVALUATE after a when-
imperative is executed, the above code has a coding-order-dependency
for the WHEN's and their imperatives.

Ahhhhhh... with all due respect, Mr Shafer, I would argue that this is a
flaw of specs/design or implementation - not one inherent to EVALUATE -
just as coding a check of two different data elements by IF/ELSE would be:

IF TEMP > 80
PERFORM 100-SWEAT
ELSE
IF SKY-IS-BLUE (an 88 on IND-SKY)
PERFORM 200-SMILE
ELSE
IF SNOW-IS-FALLING (an 88 on IND-SNOW)
PERFORM 300-EXTEND-UMBRELLA
ELSE
PERFORM 400-STAY-HOME.

[snip]

Now I'm OK with EVALUATE TRUE if care is taken to construct a clean
and exhaustive WHEN partitioning... like...
EVALUATE TRUE
WHEN TEMP < 21
PERFORM 100-SHIVER
WHEN (TEMP >20 AND TEMP < 76)
PERFORM 200-COMFORTABLE
WHEN (TEMP > 75 AND TEMP < 101)
PERFORM 300-SWEAT
WHEN OTHER
PERFORM 999-CHECK-LIFE-SUPPORT
END-EVALUATE

Some folks dislike 88s, Mr Shafer... me, I prefer them to PROCEDURE
DIVISION hardcoded values. Consider a classic:

EVALUATE TRUE
WHEN WS-STATE = 'AL' OR 'AZ' OR 'AR'... OR 'WY'
PERFORM A71352-CONUS-RTN THRU A71352-EX
WHEN WS-STATE = 'AK' OR 'HI'
PERFORM A73152-AK-OR-HI THRU A73152-EX
WHEN WS-STATE = 'AS' OR 'GU' OR 'MH'... OR 'VI'
PERFORM A75213-US-TERR THRU A75213-EX
WHEN OTHER
PERFORM A37512-INVALID-ST THRU A37512-EX
END-EVALUATE

....versus..

MOVE CUSTMAST-CUST-ST-RESIDNC TO WS-TEST-ST
EVALUATE TRUE
WHEN LOWER-48
PERFORM A71352-CONUS-RTN THRU A71352-EX
WHEN ALASKA-OR-HAWAII
PERFORM A73152-AK-OR-HI THRU A73152-EX
WHEN US-TERRITORY
PERFORM A75213-US-TERR THRU A75213-EX
WHEN OTHER
PERFORM A37512-INVALID-ST THRU A37512-EX
END-EVALUATE.

[snip]

Yes, I know that the language definition of EVALUATE includes the
order of the WHEN statements; but depending on the ordering in an
EVALUATE just seems to me to be not in the spirit of what a "case"
construct should be about.

What should be considered the case when using a 'case' construct, then,
seems to be worthy of more than passing examination... LEFT-HANDED does
not rule out BROWN-EYED does not rule out HAS-SIX-TOES.


All in all, I think that it is a very bad idea to use EVALUATE TRUE
with WHEN condition-1 and WHEN condition-2 and WHEN condition-3 where
condition-1, condition-2, and condition-3 refer to separate data-
elements.

'Hey, it hurts when I do this.'

'Then don't do that!'

DD

.



Relevant Pages

  • Re: Regarding EVALUATE TRUE
    ... with multiple 88-levels, and a numeric TEMP. ... for the WHEN's and their imperatives. ... WHEN NO-OUTPUT-TRAN ... continue with output transaction processing... ...
    (comp.lang.cobol)
  • Regarding EVALUATE TRUE
    ... Usually I follow the Doc's prescription for whatever ails me in COBOL, ... with multiple 88-levels, and a numeric TEMP. ... for the WHEN's and their imperatives. ... continue with output transaction processing... ...
    (comp.lang.cobol)