Progress
Language Reference
DEFINE BUFFER Statement
Progress provides you with one buffer for each table that you use in a procedure. Progress uses that buffer to store one record at a time from the table as the records are needed during the procedure. If you need more than one record at a time from a table, you can use the DEFINE BUFFER statement to define additional buffers for that table. If you need to share buffers among procedures, use the DEFINE SHARED BUFFER statement.
SYNTAX
NEW SHARED
Defines a buffer that can be used by other procedures. When the procedure using this statement ends, the buffer is no longer available.
SHARED
Defines a buffer that was created in another procedure with the DEFINE NEW SHARED BUFFER statement.
BUFFER buffer
Identifies the name of the buffer you want to define to hold records from table.
FOR table
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.
PRESELECT
If you use the PRESELECT option with a DO or REPEAT block, Progress creates an internal list of the records selected. The PRESELECT option tells Progress to apply that internal list to the buffer you define. You can also use the PRESELECT option in the DEFINE SHARED BUFFER statement.
LABEL label
Specifies a label for the buffer. This label is used in error messages in place of the buffer name.
EXAMPLESThis procedure allows the user to create a new customer record. Initially, the City, State, and Country fields are not shown. After the user enters a Postal-Code value, the procedure searches for an existing customer with the same postal code. If such a customer is found, the City, State, and Country 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 credit-limit > 4000) and passes them as arguments to ther-defb3.p
procedure.
The
r-defb3.p
procedure:
- Lets you view the Progress 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 Progress 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 flist 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 credit-limit > 4000 in the table name. The DO PRESELECT EACH rec statement translates to DO PRESELECT EACH rec WHERE max-credit > 4000. Progress goes through the customer table and selects the records that meet the criteria. It creates a temporary 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, Progress 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.
NOTES
- 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, Progress 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 temporary table with the same name as a database table and then you define a buffer for that name, the buffer will be associated with the database table, not with the temporary table.
- For more information on using the built-in buffer name proc-text-buffer, see the Progress DataServer Guides, Progress DataServer for ODBC Guide and Progress DataServer for ORACLE Guide.
SEE ALSO
DEFINE PARAMETER Statement, RUN Statement, RUN STORED-PROCEDURE Statement
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |