Scoping buffers
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
Record Buffer Rule 4: If you have a free reference to a buffer, the AVM tries to scope that buffer to the nearest enclosing block with record scoping properties (that is, a FOR EACH block, a DO FOR block, or a REPEAT block). If no block within the procedure has record scoping properties, then the AVM scopes the record to the entire procedure.
The FIND statements are called free
references because they don't define a scope for the buffer, they
just reference it. Therefore, the AVM has to identify some scope
for the record beyond the FIND statement. When
a block has record scoping properties, it is a block the AVM might
try to scope a record to, when the record is referenced inside the
block.
Here's another variation on the testscope.p procedure that demonstrates this rule:
|
This procedure is perfectly valid. The first time through the FOR EACH loop,
the procedure saves off the CreditLimit for
use later in the procedure. Because the fLimit variable
is initialized to zero, checking for fLimit = 0 tells
you whether it's already been set. When you run it, you see all
the New Hampshire Customer records followed
by the first Customer with a CreditLimit higher
than the highest value for New Hampshire Customers.
Because there's no conflict with two blocks trying to use the same
buffer at the same time, it compiles and runs successfully.
But the rule that the AVM raises the scope in this situation
is a critically important one. In complex procedures, the combination
of buffer references you use might force the AVM to scope a record
buffer higher in the procedure than you expect. Though this normally
does not have a visible effect when you're just reading records,
when you get to the discussion of transactions this rule becomes
much more important. If you generate another listing file for this procedure,
you see the effect of the FIND statement:
|
This tells you that the Customer buffer
is scoped at line 0, that is, to the procedure itself. There's no
reference to the Customer buffer in the information
for the FOR block at line 3 because the AVM has
already scoped the buffer higher than that block.
Next is the rule concerning combining FIND statements
with strong-scoped, rather than weak-scoped references.