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:
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:
- CREATE–LIKE( ) — copies the field definitions from a source table and establishes all the indexes of the source table unless specified otherwise.
- ADD–FIELDS–FROM( ) — copies the specified fields from a source table. No indexes are established. This method can be used multiple times on the same temp–table and is especially useful when the rows of the temp–table need to represent a join.
- ADD–LIKE–FIELD( ) — copies the single field specified from a source table.
- ADD–NEW–FIELD( ) — adds a field with the specified properties.
The following code fragment illustrates creating a dynamic temp–table and adding fields to it:
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:
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:
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |