Temp-tables
- Last Updated: October 29, 2020
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
A temporary table (temp-table) is a very important ABL construct that allows you to define a set of data. Temp-tables are relational-based structures, visible to the OpenEdge session that creates them, and only last the duration of the session. Temp-tables may represent data from one or more tables in your database or they may contain different data.
Use cases
There are two main use cases for temp-tables. You can use a temp-table to represent data from one or more tables in your database. In this use case you perform similar operations on the temp-table, as you would on a database table, however the database itself is not affected. This allows operations to take place in the application logic, without any involvement from the database server. You initially fill the temp-table with data from one or more tables in the database, You can then manipulate the data in the temp-table without tying up the database. The database can be updated with changes from the temp-table at a later time, although care must be given to data integrity since the database might have changed during this time.
The second use case is when you want to work with a set of local data and even pass this set of data to another procedure or session. You can think of a temp-table in this case as a columnar structure where each row uses the same local schema definition.
Static temp-tables
ttCustomer with two fields (columns),
creates a record, assigns values to the fields, and displays the record.
|
You can pass a static temp-table to another procedure using the TABLE parameter. In this case the table data is copied from
one procedure to the other. Static temp-tables require a complete, static definition of
the table on each side of the transfer, because the schema is not passed as part of the
parameter. For more information see Using a temp-table as a parameter.
Dynamic temp-tables
Dynamic temp-tables are used when the schema of the table is not known until runtime. You use the CREATE TEMP-TABLE statement to create an empty temp-table at runtime. You then define the schema using ADD methods such as ADD-NEW-FIELD( ) and ADD-NEW-INDEX( ). Once the definition for the dynamic temp-table is complete, you call TEMP-TABLE-PREPARE( ) to signal that the table definition is complete. The temp-table is now ready to hold data.
The following example code demonstrates creating a dynamic temp-table.
|
To pass a dynamic temp-table you pass the handle itself. You can also pass a
dynamic temp-table using the TABLE-HANDLE parameter.
For more information see Parameter passing syntax.