evaluate false, again
- From: "Frank Swarbrick" <Frank.Swarbrick@xxxxxxxxxxxxxx>
- Date: Tue, 14 Aug 2007 09:36:26 -0600
So I wrote some code yesterday using my wonderful new discovery of "evaluate
false". Here's the logic.
05 MSC-ISS-COUNTRY PIC 9(03).
88 ISS-COUNTRY-IS-USA VALUE 840.
05 MSC-ACQ-STATE PIC X(02).
88 NON-US-SURCHG-ALLOWED VALUES 'CO' 'CA'.
IF ICR-COUNTRY-CODE IS NUMERIC
MOVE ICR-COUNTRY-CODE TO MSC-ISS-COUNTRY
MOVE STR-REGE-ST TO MSC-ACQ-STATE
EVALUATE ISS-COUNTRY-IS-USA
OR NON-US-SURCHG-ALLOWED
WHEN FALSE
MOVE ZERO TO STR-SURCHG-AMT
MOVE 'N' TO STR-SURCHG-FLAG
END-EVALUATE
END-IF.
During peer code review the reviewer asserted that this would not work as
expected.
I then asked him if he believe that the following two sets of code were the
same as the first:
IF ICR-COUNTRY-CODE IS NUMERIC
MOVE ICR-COUNTRY-CODE TO MSC-ISS-COUNTRY
MOVE STR-REGE-ST TO MSC-ACQ-STATE
IF ISS-COUNTRY-IS-USA
OR NON-US-SURCHG-ALLOWED
CONTINUE
ELSE
MOVE ZERO TO STR-SURCHG-AMT
MOVE 'N' TO STR-SURCHG-FLAG
END-IF
END-IF.
IF ICR-COUNTRY-CODE IS NUMERIC
MOVE ICR-COUNTRY-CODE TO MSC-ISS-COUNTRY
MOVE STR-REGE-ST TO MSC-ACQ-STATE
EVALUATE ISS-COUNTRY-IS-USA
OR NON-US-SURCHG-ALLOWED
WHEN TRUE
CONTINUE
WHEN FALSE
MOVE ZERO TO STR-SURCHG-AMT
MOVE 'N' TO STR-SURCHG-FLAG
END-EVALUATE
END-IF.
He said he didn't believe so; that they were the same as each other but not
the same as the original. When asking why, it turns out he interpreted the
original kind of as the following:
IF ISS-COUNTRY-USA IS FALSE OR NON-US-SURCHG-ALLOWED IS FALSE
MOVE ZERO TO STR-SURCHG-AMT
MOVE 'N' TO STR-SURCHG-FLAG
END-IF
(Assume the above was valid Cobol, which of course it is not.)
I set him straight on how it works (it evaluates the expression, getting a
single true/false result, and then , but now my concern is that the original
statement is not as 'obvious' as I had first hoped.
(Of course there is the slight possibility that I am incorrect, but I did
test what I believe to be all possible cases and got the results I was
expecting.)
Opinions?
Frank
.
- Follow-Ups:
- Re: evaluate false, again
- From: SkippyPB
- Re: evaluate false, again
- From: Richard
- Re: evaluate false, again
- From: Richard
- Re: evaluate false, again
- From: LX-i
- Re: evaluate false, again
- From: HeyBub
- Re: evaluate false, again
- From: Pete Dashwood
- Re: evaluate false, again
- From: Alistair
- Re: evaluate false, again
- From: Doug Miller
- Re: evaluate false, again
- Prev by Date: Re: field validation (was Re: COBOL/DB2 Date edit question)
- Next by Date: Re: evaluate false, again
- Previous by thread: COBOL/DB2 Date edit question
- Next by thread: Re: evaluate false, again
- Index(es):