Use a buffer handle and buffer field handles
- Last Updated: April 30, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
In the next section, you learn how to define dynamic data management objects such as buffers, and queries. In the meantime, it is useful to know that these objects, whether static or dynamic, have handles and attributes just like any other ABL object.
To see how to use buffer handle and buffer field handles:
- Create a new internal procedure called initSelection.
- Begin the internal procedure with these definitions:
/*--------------------------------------------------------------------- Purpose: Set the selection list to a list of all the fields in the OrderLine table. Parameters: <none> ---------------------------------------------------------------------*/ DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO. DEFINE VARIABLE iField AS INTEGER NO-UNDO. - To build a list of all the fields in the OrderLine table at
run time, you need to be able to walk through a list of those fields in the
OrderLinerecord buffer.To do this, you first need to use the
HANDLEattribute to get the buffer handle:hBuffer = BUFFER OrderLine:HANDLE.Notice that you need to include the
BUFFERkeyword in the statement so that the AVM knows how to identify the literal value OrderLine. - Next, you need to know that the buffer object has an attribute called
NUM-FIELDSthat conveniently tells you how many fields there are in the buffer.Use this code to start a block that walks through all those fields:
DO iField = 1 TO hBuffer:NUM-FIELDS: - There is another ABL object that represents a single field in a buffer. You get the
handle of a particular field object using the buffer’s
BUFFER-FIELDattribute.BUFFER-FIELDtakes a single argument, which can be either the sequential field position within the buffer or the field name.In this procedure, since you just want to walk through all the fields to build up a list, use its position to identify it:
hBuffer:BUFFER-FIELD(iField) - Finally, you need to know that, like other objects, the
BUFFER-FIELDhas various attributes you can query or set. In this case you want theNAMEattribute. ABL lets you chain multiple colon-separated references together in a single expression, such as this:hBuffer:BUFFER-FIELD(iField):NAMEThe only requirement is that each of the elements in the expression until the last one must be a handle, since each element is in turn an attribute of the handle that the expression yields at that point in its evaluation. Thus the expression above represents this sequence:
Starting with the handle to the buffer, retrieve the handle of the buffer field that is in position
iField. Then retrieve theNAMEattribute of that field handle.You could even leave out the earlier step of saving off the buffer handle in a variable and put that into the expression as well, as in:
BUFFER OrderLine:BUFFER-FIELD(iField):NAMEIn this example, you did not to do this because the buffer handle is referenced in several different statements in this little procedure, so it is more efficient and makes the code a bit more readable to save the value off once and reuse it.