Progress
Programming
Handbook


Creating a Dynamic Temp–table

There are several steps to creating a dynamic temp–table:

Creating the Temp–table Object

You can create a dynamic temp–table by using the CREATE TEMP–TABLE statement which creates an empty temp–table object. You must use the ADD/CREATE type methods to add fields and indexes to the table. For example, the following statement creates an empty temp–table that can be referred to by its handle, tthandle:

CREATE TEMP-TABLE tthandle. 

Adding Fields to the Dynamic Temp–table

Once you have created the empty temp–table object, you must add fields to it to make it useful. There are four methods you can use to add fields to the temp–table:

The following code fragment illustrates creating a dynamic temp–table and adding fields to it:

DEFINE VARIABLE tthandle AS HANDLE.

/* create an "empty" undefined temp-table */
CREATE TEMP-TABLE tthandle.

/* give it customer table’s fields and indexes */
tthandle:CREATE-LIKE("customer").

/* add all fields from salesrep table except for month-quota */
tthandle:ADD-FIELDS-FROM("salesrep","month-quota").

/* give it a single extra integer field */
tthandle:ADD-NEW-FIELD("f1","integer").
. . . 

Adding Indexes to the Dynamic Temp–table

There are several ways of creating indexes for dynamic temp–tables. The CREATE–LIKE( ) method described above creates all the indexes of the source table by default. If you specify a single index in the CREATE–LIKE( ) method, however, you will get only that index. In addition, the following methods also create indexes in the dynamic temp–table:

The following code fragment adds an index to the previous example:

DEFINE VARIABLE tthandle AS HANDLE.

CREATE TEMP-TABLE tthandle.

tthandle:CREATE-LIKE("customer").
tthandle:ADD-FIELDS-FROM("salesrep","month-quota").
tthandle:ADD-NEW-FIELD("f1","integer"). 

/* add a new index "rep" and add the "rep-name" to the new index */
tthandle:ADD-NEW-INDEX("rep")
tthandle:ADD-INDEX-FIELD("rep","rep-name")
. . . 

Completing the Dynamic Temp–table

Once you have added all the fields and indexes for your dynamic temp–table, you must signal the 4GL that the temp–table definition is complete by using the TEMP–TABLE–PREPARE( ) method. This method causes the pending list of fields and index definitions to become part of the actual temp–table object, making it ready for use. TEMP–TABLE–PREPARE( ) must be called before any non–ADD/CREATE method can be called.

The following code fragment completes the previous examples:

DEFINE VARIABLE tthandle AS HANDLE.

CREATE TEMP-TABLE tthandle.

tthandle:CREATE-LIKE("customer").
tthandle:ADD-FIELDS-FROM("salesrep","month-quota").
tthandle:ADD-NEW-FIELD("f1","integer"). 

/* add an index like the salesrep.sales-rep index and call it "srep" */
tthandle:ADD-LIKE-INDEX("srep","sales-rep","salesrep").

/* the definition of temp-table, "newcust", is complete */
tthandle:TEMP-TABLE-PREPARE("newcust").
. . . 


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