Temp-tables are one of the most important and useful constructs in an OpenEdge® application. A temp-table lets you define in-memory storage for any number of rows of any combination of fields you require. A temp-table can be a mirror of a single database table, or it can be the result of a join of tables. It can contain a subset of selected fields from one or more tables, or it can contain fields that don’t map to any database fields at all. And it can be any combination of these things. In general, temp-tables give you two basic capabilities:
  • A temp-table lets you create business logic that is independent of the particular structure of the underlying data source.
  • A temp-table is the mechanism you use for passing records from one OpenEdge session to another, in particular from an application server session where the database resides to a client session where the user interface for the application is.

This section expands on your knowledge of temp-tables by introducing you to dynamic temp-tables. It also introduces you to the attributes you can access and the methods you can invoke using a handle to either a static or dynamic temp-table.

Finally, this section details the various ways in which you can pass a temp-table from one procedure or one session to another.

As with other objects, you can get the handle to a static temp-table and use that handle to query its attributes, using this syntax:
tt-handle = TEMP-TABLE tt-name:HANDLE.
However, having said this, a handle to a static temp-table is less useful than a handle to most other static objects, for two reasons:
  1. There are only a few attributes you can access through a temp-table’s handle, and none of these are settable for a static table.
  2. None of the temp-table methods are usable for a static temp-table.

These methods define the fields and indexes for the temp-table. You cannot change or extend the fields or indexes for a static temp-table.

To create a dynamic temp-table, use this statement:
CREATE TEMP-TABLE tt-handle.

There are no other options on the CREATE TEMP-TABLE statement. You specify everything about the table after you create it. Thus, the CREATE statement really does nothing more than set up the tt-handle variable to be a handle for a temp-table structure to fill in later.

A dynamic temp-table can be in one of three states. When you first create it, using just the CREATE TEMP-TABLE statement, it is said to be in the clear state. That is, the temp-table handle has been allocated but there is no definition for the table yet. After you start to use the temp-table methods to define the table’s fields and indexes, the table is said to be unprepared. This means that the table definition is not yet complete and you cannot start to use the table. After you complete the definition using its methods, you use a special TEMP-TABLE-PREPARE method to signal to the ABL Virtual machine (AVM) that the definition is complete. This effectively freezes the definition and allows you to start to use the table to store data. At this point, the temp-table is in the prepared state.