Try OpenEdge Now
skip to main content
ABL Essentials
Record Buffers and Record Scope : Record scope : Self-contained references to a buffer
 

Self-contained references to a buffer

Record Buffer Rule 1: Each strong-scoped or weak-scoped reference to a buffer is self-contained.

You can combine multiple such blocks in a procedure, and each one scopes the buffer to its own block. This rule holds as long as no other reference forces the buffer to be scoped to a higher level outside these blocks. Here's an example:
FOR EACH Customer NO-LOCK BY Customer.CreditLimit DESCENDING:
  DISPLAY "Highest:" Customer.CustNum Customer.Name Customer.CreditLimit
    WITH 1 DOWN.
  LEAVE.
END.

FOR EACH Customer NO-LOCK WHERE Customer.State = "NH"
  BY Customer.CreditLimit DESCENDING:
  DISPLAY Customer.CustNum Customer.Name Customer.CreditLimit.
END.
This code has two FOR EACH blocks each with a weak-scoped reference to the Customer buffer. This is perfectly valid. First, the AVM scopes the Customer buffer to the first FOR EACH block. When that block terminates, the AVM scopes the buffer to the second FOR EACH block.
The first block identifies the Customer with the highest CreditLimit. To do this, it sets up a FOR EACH block to cycle through all the Customers. The statement sorts the Customers by their CreditLimit in descending order. After it reads and displays the first of these records, the one with the highest CreditLimit, the LEAVE statement forces the block to terminate.
The qualifier WITH 1 DOWN on the DISPLAY statement for the first block tells the AVM that it only needs to define a frame with space for one Customer. Otherwise it would allocate the entire display space. The literal Highest: makes it clear in the output what you're looking at.
The second block then independently displays all the Customers in the state of New Hampshire in order by their CreditLimit, with the highest value first. Because these two blocks occur in sequence, The AVM can scope the Customer buffer to each one in turn and reuse the same Customer buffer in memory, without any conflict. That's why this form is perfectly valid.
The following figure shows what you see when you run the procedure.
Figure 28. Result of record buffer Rule 1 example