Release 10.1A: OpenEdge Development:
Progress 4GL Handbook

> ## Temp-table buffer methods and attributes

> In addition to the default buffer handle that is an attribute of every temp-table, you can create one or more dynamic buffers for a dynamic temp-table. Use this syntax:

>     CREATE BUFFER buffer-handle FOR TABLE tt-handle:DEFAULT-BUFFER-HANDLE
>         [ BUFFER-NAME buffer-name ] [ IN WIDGET-POOL pool-name ].

> Note that it is necessary to include the reference to the `DEFAULT-BUFFER-HANDLE`. For example, you can create a second dynamic buffer for the temp-table in the current example with these statements:

>     DEFINE VARIABLE hTT  AS HANDLE     NO-UNDO.
>     DEFINE VARIABLE hTTB AS HANDLE     NO-UNDO.
>     CREATE TEMP-TABLE hTT.
>     hTT:CREATE-LIKE("Customer","Name").
>     hTT:ADD-FIELDS-FROM("SalesRep","MonthQuota").
>     hTT:ADD-LIKE-FIELD("Area", "SalesRep.Region").
>     hTT:ADD-NEW-FIELD("Sequence", "INTEGER",0,"9999",1000).
>     hTT:ADD-LIKE-INDEX("CustNum","CustNum","Customer").
>     hTT:ADD-NEW-INDEX("SeqIndex", YES).
>     hTT:ADD-INDEX-FIELD("SeqIndex", "Sequence").
>     hTT:TEMP-TABLE-PREPARE("CustSequence").
>     CREATE BUFFER hTTB FOR TABLE hTT:DEFAULT-BUFFER-HANDLE
>         BUFFER-NAME "CustSeq2".

> Now you have two dynamic buffers for the temp-table, one called `CustSeq` that you get “for free” along with the temp-table definition and a second that you created yourself.

> The dynamic buffer methods that you learned about earlier are essential to using dynamic temp-tables and their buffer. In particular, you will use the `BUFFER-CREATE` method on the buffer handle to create records in the dynamic temp-table, `BUFFER-DELETE` to delete them, `BUFFER-RELEASE` to release them, and `BUFFER-COPY` to copy fields from one or more database tables into newly created records in the temp-table.

> There are a couple of additional buffer methods and attributes specific to their association with temp-tables, however.

> ##### TABLE-HANDLE buffer attribute

> This attribute returns the handle of the temp-table the buffer is associated with. For a buffer not associated with a temp-table, it returns the Unknown value (`?`). Therefore, the temp-table’s `DEFAULT-BUFFER-HANDLE` points to its default buffer, and that buffer’s `TABLE-HANDLE` attribute points back to the temp-table. In addition, the `TABLE-HANDLE` attribute of any other buffer defined or created for the temp-table, such as `CustSeq2`, also points back to the temp-table.

> ##### EMPTY-TEMP-TABLE buffer method

> It is much more efficient to empty a temp-table in one statement rather than in a `FOR EACH` loop. To empty a static temp-table you can use the `EMPTY TEMP-TABLE` `tt-name` statement. With the handle of a buffer for the temp-table, you can also use the `EMPTY-TEMP-TABLE` method on the buffer. It takes no arguments. Remember that while you can have multiple buffers associated with a temp-table, just as you can with a database table, there is only one set of records in the temp-table. The multiple buffers simply allow you to have pointers to multiple different records in the temp-table at the same time. Thus, you can use the `EMPTY-TEMP-TABLE` method on any buffer for the temp-table and the result is the same.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095