Progress
Language Reference


CREATE TEMP-TABLE Statement

Interfaces
OS
SpeedScript
All
All
Yes

Creates a temp-table dynamically at run time. The temp-table that is created is empty and must be defined using ADD/CREATE methods.

SYNTAX

CREATE TEMP-TABLE widget-handle
 [ IN WIDGET-POOL widget-pool-name ] 

widget-handle

A variable of type WIDGET-HANDLE that represents the handle of the temp-table object.

IN WIDGET-POOL widget-pool-name

An expression of type CHARACTER that evaluates, at run time, to the name of the widget pool that contains the dynamic temp-table.

NOTE: Widget pool names are not case-sensitive.

EXAMPLE

The following example creates a temp-table like the order table and populates it from the order table. In addition, the corresponding sales-rep name is added from the salesrep table.

r-cretmpt.p
DEFINE VARIABLE tth AS HANDLE.
DEFINE VARIABLE bh AS HANDLE.
DEFINE VARIABLE qh AS HANDLE.
DEFINE VARIABLE buf-ord-hndl AS HANDLE.
DEFINE VARIABLE buf-rep-hndl AS HANDLE.
DEFINE VARIABLE fld1 AS HANDLE.
DEFINE VARIABLE fld2 AS HANDLE.

/* get database table handles */
buf-ord-hndl = BUFFER order:HANDLE.
buf-rep-hndl = BUFFER salesrep:HANDLE.

/* create an empty undefined temp-table */
CREATE TEMP-TABLE tth.
/* give it order table’s fields & indexes */
tth:CREATE-LIKE(buf-ord-hndl).
/* add field like Salesrep.Rep-Name */
tth:ADD-LIKE-FIELD("RepName","Salesrep.Rep-Name").
/* no more fields will be added */
tth:TEMP-TABLE-PREPARE("ordx").

/* get the buffer handle for the temp-table */
bh = tth:DEFAULT-BUFFER-HANDLE.

/* populate the temp-table from order */
FOR EACH order:
    bh:BUFFER-CREATE.
    bh:BUFFER-COPY(buf-ord-hndl).
/* add the corresponding salesrep name */
    FIND salesrep WHERE salesrep.sales-rep = order.sales-rep NO-ERROR.
    IF AVAILABLE salesrep THEN
        bh:BUFFER-COPY(buf-rep-hndl,?,"RepName,rep-name").
END.  
/* run a query to access the temp-table */
CREATE QUERY qh.
qh:SET-BUFFERS(bh).
qh:QUERY-PREPARE("for each ordx where order-num < 50 BY RepName").
qh:QUERY-OPEN(). 
fld1 = bh:BUFFER-FIELD("order-num").
fld2 = bh:BUFFER-FIELD("RepName").

/* display the order-number and the salesrep name */
REPEAT:
    qh:GET-NEXT().
    IF qh:QUERY-OFF-END THEN LEAVE.
    DISPLAY fld1:BUFFER-VALUE() FORMAT "X(10)".
    DISPLAY fld2:BUFFER-VALUE() FORMAT "X(20)".
END.

qh:QUERY-CLOSE().
bh:BUFFER-RELEASE().
DELETE OBJECT tth.
DELETE OBJECT qh. 

NOTES

SEE ALSO

DEFINE TEMP-TABLE Statement, TEMP-TABLE-PREPARE( ) Method


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