Question For Each With Rowid In Where Clasue

davidvilla

Member
I was wondering, if Progress treats a FOR EACH with ROWID in the WHERE clause not as a block.

The sample code here is for illustration only. Don't ask me why I used FOR EACH with ROWID even though it is only one record.

Code:
run pProc1.
message "three" view-as alert-box.

procedure pProc1:
    define buffer bfcustomer for customer.

    find first customer no-lock.
    message "one" view-as alert-box.

    for each bfcustomer no-lock where rowid(bfcustomer) = rowid(customer):
        leave.
    end. /* for each bfcustomer */
    message "two" view-as alert-box.

end. /* pProc1 */

I expected the output to print the messages
one
two
three

But, I got, only
one
three

The LEAVE statement actually leaves the procedure, not the FOR EACH block.

If I label the block and leave using the label, it works fine. SO, I think FOR EACH with ROWID is not considered as a block. Progress is smart enough to classify this as a FIND statement even though FOR EACH on a unique condition is used.

Any thoughts??
 

GregTomkins

Active Member
Wow. That blows my mind a bit. As far as I can tell, you're theory is correct. I'm interested to see what The Seniors say.

In our version of 'customer' we have a field 'acct' that is a unique key.

- add 'bfcustomer.acct = customer.acct', same behaviour
- replace the ROWID check with acct = acct, now you see the 'two'

So yeah it seems like the ROWID condition is the trick.
 

davidvilla

Member
Right, if you use the table unique key field in the where clause, it behaves as we expect.. i.e., one, two, three
When using ROWID, it doesn't consider the FOR as a block.

Before coming to any conclusion, lets wait for the seniors to comment.
 

GregTomkins

Active Member
I have a coworker who is a whiz with this kind of thing and he's been trying different scenarios for the last hour. UNDO, LEAVE seems different again, for example.

We were wondering if someone changes the data between the two FINDs, if the second find will retrieve the most recent version or not. Normally in a self-service local client I would assume Yes, but maybe not in this strange scenario?
 
Top