To verify how the AVM is scoping the record buffers, you can generate a listing file that contains various information about how ABL or the AVM processes the procedure when you compile or run it.
To do this, use the LISTING option on the COMPILE statement:
1. Save the procedure so that it has a name you can reference: testscope.p.
2. Open another procedure window and enter this statement:
COMPILE testscope.p LISTING testscope.lis.
3. Press F2 to run the COMPILE statement.
4. Select File > Open to open testscope.lis. You should see this code:
{} Line Blk
-- ---- ---
1 1 FOR EACH Customer NO-LOCK BY Customer.CreditLimit DESCENDING:
2 1 DISPLAY "Highest:" Customer.CustNum Customer.Name Customer.CreditLimit
3 1 WITH 1 DOWN.
4 1 LEAVE.
5 END.
6
7 FOR EACH Customer NO-LOCK WHERE Customer.State = "NH"
8 BY Customer.CreditLimit DESCENDING:
9 1 DISPLAY Customer.CustNum Customer.Name Customer.CreditLimit.
10 END.
11
File Name Line Blk. Type Tran Blk. Label
-------------------- ---- --------- ---- -------------------------------
.\testscope.p 0 Procedure No
.\testscope.p 1 For No
Buffers: sports2000.Customer
Frames: Unnamed
.\testscope.p 7 For No
Buffers: sports2000.Customer
Frames: Unnamed
This listing file tells you that line 1 of the procedure starts a FOR block and that this block does not start a transaction. The next line tells you what you need to know about scoping. The line that reads Buffers: sports2000.Customer tells you that the Customer buffer is scoped to this FOR block and that it used an unnamed frame that is also scoped to that block. Next you see that another FOR block begins at line 7. The Customer buffer is also (independently) scoped to that block and it has its own unnamed frame.
You could construct similar examples using any combination of strong- and weak-scoped buffer references. For example, here's a variation on the test procedure that uses a DO FOR block with a strong scope to the Customer buffer:
DO FOR Customer:
FIND FIRST Customer NO-LOCK WHERE Customer.CreditLimit > 60000.
DISPLAY Customer.CustNum Customer.Name Customer.CreditLimit.
END.
FOR EACH Customer NO-LOCK WHERE Customer.State = "NH"
BY Customer.CreditLimit DESCENDING:
DISPLAY Customer.CustNum Customer.Name Customer.CreditLimit.
END.
This procedure scopes the Customer buffer to each block in turn, just as the first example does.