Try OpenEdge Now
skip to main content
ABL Essentials
Record Buffers and Record Scope : Record scope : Nested, weak-scoped references to the same buffer
 

Nested, weak-scoped references to the same buffer

Record Buffer Rule 2: You cannot nest two weak-scoped references to the same buffer.

For example, this procedure violates this rule:
DEFINE VARIABLE fLimit AS DECIMAL NO-UNDO.

FOR EACH Customer NO-LOCK WHERE Customer.State = "NH"
  BY Customer.CreditLimit DESCENDING:
  DISPLAY Customer.CustNum Customer.Name Customer.CreditLimit.
  fLimit = Customer.CreditLimit.

  FOR EACH Customer NO-LOCK WHERE Customer.CreditLimit > fLimit:
    DISPLAY Customer.CustNum Customer.Name Customer.CreditLimit.
  END.
END.
If you try to run this procedure, you get the error shown in the following figure that tells you that your buffer references are invalid.
Figure 29. Invalid buffer references error message
When you think about it, this is perfectly sensible and necessary. Picture this situation:
The AVM is using the Customer buffer for the current Customer record in the outer FOR EACH block. The first time through the block, it contains the New Hampshire Customer with the highest CreditLimit. Now suddenly the AVM gets a request to use that same buffer to start another FOR EACH block, while it's still in the middle of processing the outer one. This could not possibly work. If the AVM replaced the New Hampshire Customer with whatever Customer was the first one to satisfy the selection of Customers with higher CreditLimits and then you had another reference to the first Customer later on in the outer block (which would be perfectly valid), that Customer record would no longer be available because the AVM would have used the same buffer for the inner FOR EACH block. Because this can't be made to work with both blocks sharing the same buffer at the same time, this construct is invalid.