Find (current) inside for each

Posted by Rick Terrell on 10-Jun-2019 13:05

It had been the case that a find inside a for each loop on the same buffer (even a find current) was not allowed.  I just tested in OE12 and it is now allowed (at least for a find current).  Did this test against the Sports2020 db:

for each customer no-lock

   by customer.CustNum:

     if customer.CustNum < 3030 then

     do:

           customer.CustNum = customer.CustNum + 10000.

           display customer.CustNum customer.name.

     end.

    else 

       leave.

end.

And it compiles and runs correctly.  When did this change?  Even the OE12 docs still say this is not allowed.

ABL does not allow a FIND statement within a FOR EACH block unless you specify a different table than
the one referenced in the FOR EACH block. When you attempt to compile the following example, ABL
returns the error message "FIND cannot be processed for a FOR EACH mode record":

FOR EACH Customer NO-LOCK:
   FIND CURRENT Customer.
END.

 

All Replies

Posted by Marco Mendoza on 10-Jun-2019 13:26

I don't see the FIND

Posted by Rick Terrell on 10-Jun-2019 13:34

Sorry, the code should have read:

for each customer no-lock

  by customer.CustNum:

    if customer.CustNum < 3030 then

    do:

         find current customer exclusive-lock.

          customer.CustNum = customer.CustNum + 10000.

          display customer.CustNum customer.name.

    end.

   else

      leave.

end.

Posted by OctavioOlguin on 10-Jun-2019 13:51

I've used such trick for years to avoid locking lots of records...

FIND CURRENT is allowed on a FOR EACH (on the same record) to upgrade/change the locking status of the record, at least since V8 that I know....

Posted by Marco Mendoza on 10-Jun-2019 14:03
Posted by jquerijero on 10-Jun-2019 16:30

What is the transaction scope when you re-find with EXCLUSIVE-LOCK? Are all the records found in one transaction or just the record in current iteration?

Posted by Laura Stern on 10-Jun-2019 17:27

It is only the record that is currently in the buffer whose lock status is changed when you use FIND CURRENT EXCLUSIVE-LOCK.

Posted by Laura Stern on 10-Jun-2019 17:28

It is only the record that is currently in the buffer whose lock status is changed when you use FIND CURRENT EXCLUSIVE-LOCK.

Posted by onnodehaan on 10-Jun-2019 17:53

Another question. What happens in this example when the EXCLUSIVE-LOCK fails, because of a lock wait time out?

FOR EACH Customer NO-LOCK:

 FIND CURRENT Customer EXCLUSIVE-LOCK.

END.

Is this construct valid? Will Customer be available after a  lock wait time out?

FOR EACH Customer NO-LOCK:

 FIND CURRENT Customer EXCLUSIVE-LOCK NO-WAIT NO-ERROR.

 IF AVAILABLE Customer  THEN

    ....

END.

Posted by gus bjorklund on 10-Jun-2019 18:14

lock wait timeout generates a stop condition (same as if you type ctrl-c (or ctrl-break)

Posted by Laura Stern on 10-Jun-2019 18:49

Yes, but it won't generate stop if you use NO-WAIT NO-ERROR.  

The buffer is still available.  You just won't have the lock.

This is easy to test yourself :-).

Posted by Laura Stern on 10-Jun-2019 18:49

Yes, but it won't generate stop if you use NO-WAIT NO-ERROR.  

The buffer is still available.  You just won't have the lock.

This is easy to test yourself :-).

Posted by gus bjorklund on 10-Jun-2019 19:04

> On Jun 10, 2019, at 2:58 PM, Laura Stern wrote:

>

> This is easy to test yourself :-).

>

>

>

what !

you think i should test myself?

sigh. you are correct. i am lazy scum.

This thread is closed