From: Pete Dashwood on
I know we've discussed EVALUATE here on a number of occasions, but I'm
wondering if anyone can shed light on the following:

evaluate MOST-SQLSTATE
when '00000' *> OK
move zero to MOST-file-status
when '02000' *> EOF or record not found
if MOST-GetRandom
move '23' to MOST-file-status
else
move '10' to MOST-file-status
when '23000' *> Duplicate primary key on insert
move '22' to MOST-file-status
when other *> Catch-all... error and meaning are in
*> the interface SQLSTATE and SQLMsg
move '90' to MOST-file-status
end-evaluate
.

The second 'when' can occur when random access is being done, in which case
it means the required record (row) was not found, or it can occur when
sequential access via a cursor is being done, in which case it indicates
EOF.

I was kind of surprised when the Fujitsu compiler threw this code out saying
that I couldn't use a conditional statement (IF) here as an imperative one
was required.

Fair enough. I changed it to read as follows:

evaluate MOST-SQLSTATE
when '00000' *> OK
move zero to MOST-file-status
when '02000' *> EOF or record not found
evaluate TRUE
when MOST-Getrandom
move '23' to MOST-file-status
when other
move '10' to MOST-file-status
end-evaluate
when '23000' *> Duplicate primary key on insert
move '22' to MOST-file-status
when other *> Catch-all... error and meaning are in
*> the interface SQLSTATE and SQLMsg
move '90' to MOST-file-status
end-evaluate
.

This was accepted OK and the code executes as expected.

Now, please correct me if I'm wrong, but isn't EVALUATE a conditional
statement? (It requires a terminator or scope delimiter).

It seems inconsistent to me that the original code was not accepted, but a
different conditional was. I don't know whether this is the Fujitsu
implementation, or whether it is the COBOL standard, but I would've thought
that at the time the standard syntax for this was being considered
very little would be gained by NOT allowing conditions to be checked within
the "arms" of an EVALUATE. I tend to use EVALUATE as a CASE statement and
so I keep them very simple (never use ALSO) and find them very useful for
separating mutually exclusive processes at a fairly high level. I'm
surprised they don't accommodate IF statements, and I can't see why they
wouldn't.

Any comments?

Pete.
--
"I used to write COBOL...now I can do anything."


From: Robert on
On Mon, 7 Jul 2008 22:04:25 +1200, "Pete Dashwood" <dashwood(a)removethis.enternet.co.nz>
wrote:

>I know we've discussed EVALUATE here on a number of occasions, but I'm
>wondering if anyone can shed light on the following:
>
> evaluate MOST-SQLSTATE
> when '00000' *> OK
> move zero to MOST-file-status
> when '02000' *> EOF or record not found
> if MOST-GetRandom
> move '23' to MOST-file-status
> else
> move '10' to MOST-file-status
> when '23000' *> Duplicate primary key on insert
> move '22' to MOST-file-status
> when other *> Catch-all... error and meaning are in
> *> the interface SQLSTATE and SQLMsg
> move '90' to MOST-file-status
> end-evaluate
> .
>
>The second 'when' can occur when random access is being done, in which case
>it means the required record (row) was not found, or it can occur when
>sequential access via a cursor is being done, in which case it indicates
>EOF.
>
>I was kind of surprised when the Fujitsu compiler threw this code out saying
>that I couldn't use a conditional statement (IF) here as an imperative one
>was required.

The compiler thinks you are using WHEN inside IF. You'll get a clean compile by adding
END-IF.

The diagnostic message is misleading.



From: Pete Dashwood on


"Robert" <no(a)e.mail> wrote in message
news:6ts374prmvs4aiuatssc450vkdt864tovj(a)4ax.com...
> On Mon, 7 Jul 2008 22:04:25 +1200, "Pete Dashwood"
> <dashwood(a)removethis.enternet.co.nz>
> wrote:
>
>>I know we've discussed EVALUATE here on a number of occasions, but I'm
>>wondering if anyone can shed light on the following:
>>
>> evaluate MOST-SQLSTATE
>> when '00000' *> OK
>> move zero to MOST-file-status
>> when '02000' *> EOF or record not found
>> if MOST-GetRandom
>> move '23' to MOST-file-status
>> else
>> move '10' to MOST-file-status
>> when '23000' *> Duplicate primary key on insert
>> move '22' to MOST-file-status
>> when other *> Catch-all... error and meaning are in
>> *> the interface SQLSTATE and SQLMsg
>> move '90' to MOST-file-status
>> end-evaluate
>> .
>>
>>The second 'when' can occur when random access is being done, in which
>>case
>>it means the required record (row) was not found, or it can occur when
>>sequential access via a cursor is being done, in which case it indicates
>>EOF.
>>
>>I was kind of surprised when the Fujitsu compiler threw this code out
>>saying
>>that I couldn't use a conditional statement (IF) here as an imperative one
>>was required.
>
> The compiler thinks you are using WHEN inside IF. You'll get a clean
> compile by adding
> END-IF.

Oh, excellent, Robert!

I can't believe I missed the scope delimiter and then just misinterpreted
the compiler diagnostic... :-)

My only excuse is that I wrote it late at night... but there's really no
excuse...
>
> The diagnostic message is misleading.

Thank you for sparing my blushes, but it really is a classic case of just
not checking it out properly. I looked at the diagnostic, looked at the IF
statement, and never bothered to check the syntax.

Actually, I'm glad COBOL allows an IF there, because it makes sense.

Thanks for pointing out the error. :-)

Pete.
--
"I used to write COBOL...now I can do anything."


From: Anonymous on
In article <6deb9uF25i32U1(a)mid.individual.net>,
ftp 158.72.96.181Pete Dashwood <dashwood(a)removethis.enternet.co.nz> wrote:
>
>
>"Robert" <no(a)e.mail> wrote in message
>news:6ts374prmvs4aiuatssc450vkdt864tovj(a)4ax.com...
>> On Mon, 7 Jul 2008 22:04:25 +1200, "Pete Dashwood"
>> <dashwood(a)removethis.enternet.co.nz>
>> wrote:
>>
>>>I know we've discussed EVALUATE here on a number of occasions, but I'm
>>>wondering if anyone can shed light on the following:
>>>
>>> evaluate MOST-SQLSTATE
>>> when '00000' *> OK
>>> move zero to MOST-file-status
>>> when '02000' *> EOF or record not found
>>> if MOST-GetRandom
>>> move '23' to MOST-file-status
>>> else
>>> move '10' to MOST-file-status

[snip]

>> The compiler thinks you are using WHEN inside IF. You'll get a clean
>> compile by adding
>> END-IF.
>
>Oh, excellent, Robert!
>
>I can't believe I missed the scope delimiter and then just misinterpreted
>the compiler diagnostic... :-)
>
>My only excuse is that I wrote it late at night... but there's really no
>excuse...

On 'reasons' versus 'excuses': decades on back a German project director
interrupted my explanation of a technical matter with 'I don't want to
hear excuses, I want to be told things are working!'... and I recalled
reading Wittgenstein asking about the difference between a symptom and a
criterion so I replied 'You are not being given excuses, you are being
given reasons... perhaps the difference between the two is that a 'reason'
is what a subordinate says and an 'excuse' is what a superior hears.'

On the mixing of IF and EVALUATE: whenever possible I use this technique,
first one, then the other; I've yet to run across anyone, either reviewing
or maintaining the code, who has said it complicates matters.

On the error codes being used... I do not know how MOST-SQLSTATE relates
to the SQLCODES of my youth but as I recall it the notfound/end condition
was +100, not 200.

DD

From: Frank Swarbrick on
>>> On 7/7/2008 at 6:45 AM, in message <g4t35a$lde$1(a)reader1.panix.com>,
<docdwarf(a)panix.com> wrote:
> On the error codes being used... I do not know how MOST-SQLSTATE relates
> to the SQLCODES of my youth but as I recall it the notfound/end
> condition
> was +100, not 200.

He is checking for SQLSTATE '02000', not SQLCODE +100.

Both mean the same thing.

db2 => ? sql100


SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of
a query is an empty table.

Explanation:

One of the following conditions is true:
* No row was found that meets the search conditions specified in an
UPDATE or DELETE statement.
* The result of a SELECT statement was an empty table.
* A FETCH statement was executed when the cursor was positioned after
the last row of the result table.
* The result of the SELECT used in an INSERT statement is empty.

No data was retrieved, updated, or deleted.

User response:

No action is required. Processing can continue.

sqlcode: +100

sqlstate: 02000
 |  Next  |  Last
Pages: 1 2 3 4
Prev: END-PERFORM scope terminator
Next: How competent are we?