DEFINE BUFFER statement
ABL provides you with one default buffer for each table or temp-table that you use in a procedure or class. ABL uses that buffer to store one record at a time from the table as the records are needed during the procedure or class. If you need more than one record or buffer at a time for a table, you can use this statement to define alternate buffers that are created at compile time for use in one or more procedures, or within a single class or class hierarchy.
Syntax
NEW SHARED BUFFERbuffer-name
SHARED BUFFERbuffer-name
[ PRIVATE | PROTECTED ] [ STATIC ] BUFFERbuffer-name
Defines and identifies a buffer as a data member of a class, and optionally specifies an access mode (PRIVATE or PROTECTED) and scope (instance or STATIC) for that data member. You cannot specify these options when defining a buffer as a data element of a method (including constructors, destructors, and property accessors) or a procedure.Note: The specified options are applicable only when defining a data member for a class in a class definition (.cls
) file. Note also that you cannot shadow (override) the definition of a given buffer data member in a class hierarchy.PRIVATE buffer data members can be accessed only by the defining class. PROTECTED buffer data members can be accessed by the defining class and any of its derived classes. The default access mode is PRIVATE. When you reference a buffer from another data member definition (such as a query) defined in the same class or class hierarchy, the access mode of the buffer cannot be more restrictive than the access mode of the referencing data member.A buffer defined with the STATIC option is a static data member of the class type for which it is defined and is scoped to the ABL session where it is referenced. ABL creates one copy of the specified class static buffer on first reference to the class type, and ABL creates only one such copy for any number of instances of the class that you create. You can directly reference an accessible static buffer data member from any other static or instance class member defined in the same class or class hierarchy.Without the STATIC option, ABL creates an instance buffer data member that is scoped to a single instance of the class where it is defined. ABL creates one copy of the specified instance buffer for each such class instance that you create. You cannot directly reference an instance buffer data member from a STATIC class member definition defined within the same class or class hierarchy.Within a class, ABL defines the default buffer for any database table as a PRIVATE instance buffer. Thus, for example, you can only access the default buffer for theCustomer
table of thesports2000
database wherever a PRIVATE instance buffer can be accessed. Otherwise, you must define an alternate buffer data member for the table with an appropriate access mode and scope.For more information on accessing buffers of different access modes and scopes, see the reference entry for Class-based data member access.Note: Members of a class are grouped into six namespaces, including buffers/temp-tables, methods, variables/properties/events, ProDataSets, queries, and data-sources. Buffers and temp-tables defined as members of a class share the same namespace. There can be only one class member in this namespace with a given name.For more information on where and how to define data members in a class, see the CLASS statement reference entry.BUFFERbuffer-name
FOR [ TEMP-TABLE ]table-name
Identifies the name of the table for which you are defining an additional buffer. This can also be the built-in buffer name,proc-text-buffer
, to define a buffer that returns table rows from a stored procedure.To define a buffer for a table defined for multiple databases, you might have to qualify the table name with the database name. See the Record phrase reference entry for more information.Use the TEMP-TABLE option to define a buffer for a temp-table when the temp-table has the same name as a database table. Otherwise, ABL associates the buffer with the database table by default.If you define the buffer as static, andtable-name
is the name of a temp-table, the temp-table must also be defined as a static member of a class.PRESELECTLABELlabel-name
NAMESPACE-URInamespace
NAMESPACE-PREFIXprefix
XML-NODE-NAMEnode-name
ExamplesThis procedure allows the user to create a new
Customer
record. Initially, theCity
,State
, andCountry
fields are not shown. After the user enters aPostalCode
value, the procedure searches for an existing Customer with the same postal code. If such a Customer is found, theCity
,State
, andCountry
values from that record are displayed in the fields for the new record. The user can then update those fields.
The following gather a group of records so that the user can enter any table name and any set of record selection criteria and then look at the records in the table that meet those criteria:
The
r-defb2.p
procedure gets the name of a table (such as Customer) and a condition (such as CreditLimit > 4000) and passes them as arguments to ther-defb3.p
procedure:
The
r-defb3.p
procedure:
- Lets you view the OpenEdge Data Dictionary. The _File table contains a record for each of your database tables.
- Lets you look up a record for a Customer table. For example, the user supplies Customer as a table name; the FIND statement in the
r-defb3.p
procedure translates to FIND _File Customer. The FIND statement finds, in _File, the record for the Customer table.- Lets you view the _Field table in the OpenEdge Data Dictionary. The _Field table contains a single record for each of your database fields. The FOR EACH statement reads the name of each of those fields into the first array variable. If the table name is Customer, the first array variable contains the names of each of the fields in the Customer table.
- Lets you select records. For example, the user supplies the condition
CreditLimit
> 4000 in the table name. The DO PRESELECT EACH rec statement translates to DO PRESELECT EACH rec WHEREMaxCredit
> 4000. The AVM goes through the Customer table and selects the records that meet the criteria. It creates a temp-table containing a pointer to each of those records. This list of preselected records is associated with the rec buffer.- Runs
r-defb4.p
, passing the table name (Customer) and the names of all of the fields in that table.The
r-defb4.p
procedure has access to the rec buffer (and through it to the set of preselected records). This connection is made by using PRESELECT on the DEFINE SHARED BUFFER statement. Ther-defb4.p
procedure displays those records.
Because
r-defb3.p
andr-defb4.p
use run-time argument passing, they cannot be precompiled. Having separate versions ofr-defb4.p
for each table and running the appropriate one inr-defb3.p
, should improve response time. This approach is worthwhile if there are many lines of code inr-defb4.p
a procedure.If you define a NEW SHARED BUFFER in a procedure, then call a subprocedure that puts a record into that buffer, and display the buffer in the main procedure, the AVM displays this message:
This message is displayed when the FIND statement is not in the main procedure:
To avoid this, explicitly scope the Customer record to the main procedure block. For example:
For examples of instance and static buffer data member definitions, see the descriptions of
r-CustObj.cls
,r-CustObjStatic.cls
, andr-CustObjAbstract.cls
in the CLASS statement reference entry.Notes
- You cannot define a SHARED or NEW SHARED buffer in a class definition (
.cls
) file. If you do, ABL generates a compilation error.- A buffer can be compile-time defined (often referred to as a static buffer object), where the buffer is defined and created at compile time using this statement, or it can be run-time defined (often referred to as a dynamic buffer object), where the buffer is defined and created at run time using the CREATE BUFFER statement and buffer object handle operations. A compile-time defined buffer can also be defined as a static data member of a class. In this case, it is a static buffer object that is also a class static data member.
- Every statement that uses a table name to refer to the default buffer can also use the name of a defined alternate buffer.
- All data definitions and field names are associated with a table, not a buffer. Data definitions and field names remain the same no matter what buffer you use.
- If two buffers contain the same record, a change to one of the buffers is automatically reflected in the other buffer.
- You can pass a buffer as a parameter to a procedure.
- A SHARED buffer remains in scope for an instance of a persistent procedure until the instance is deleted. This is true even if the original procedure that defined the buffer as NEW SHARED goes out of scope while the procedure instance remains persistent.
If a trigger or internal procedure of a persistent procedure executes an external subprocedure that defines a SHARED buffer, ABL includes the persistent procedure in the resolution of the corresponding NEW SHARED buffer as though the procedure were on the procedure call stack.- If you define a temp-table with the same name as a database table and you then define a buffer for that table name, by default the buffer will be associated with the database table, not with the temp-table. Use the TEMP-TABLE option to define a buffer for a temp-table when the temp-table has the same name as a database table.
- For more information on using the built-in buffer name
proc-text-buffer
, see the OpenEdge DataServer Guides (OpenEdge Data Management: DataServer for Microsoft SQL Server, OpenEdge Data Management: DataServer for ODBC, and OpenEdge Data Management: DataServer for Oracle).See alsoClass-based data member access, CREATE BUFFER statement, DEFINE PARAMETER statement, RUN statement, RUN STORED-PROCEDURE statement
OpenEdge Release 10.2B
|