Define and Use Temp-tables and Create and Use Dynamic Temp-Tables and Browses describe how you can pass temp-tables from one routine to another using the static TABLE parameter form, the dynamic TABLE-HANDLE parameter form, or simply by passing the HANDLE of the temp-table. It is extremely important that you be aware of the cost of passing temp-tables by value, that is, by copying the temp-table from one procedure to another, which is the default when you use the TABLE or TABLE-HANDLE parameter form. You can avoid this overhead by passing temp-tables using the simple HANDLE parameter whenever possible, if your routine call is within the same session. When you pass the handle to a temp-table, as with any object, you are simply passing a pointer to its location elsewhere in the session. Using the HANDLE form is possible only when the procedure call is always within a single session. It also restricts you to using only dynamic language syntax to access the temp-table within the procedure that receives only its handle.

Especially when the routine receiving the temp-table is only an intermediary, which simply passes the temp-table on to some other routine, there is never a need to pass the table itself and the HANDLE parameter form is often the simplest technique for avoiding unneeded copying of the table.

Alternately, if it is important to be able to use static syntax to access the temp-table, or the call is sometimes local and sometimes remote, you can pass a temp-table by reference and avoid the copying of the table in those instances when the call is local. When you use BY-REFERENCE and the call is between different sessions, the temp-table is copied. However, when the call is within the same session, BY-REFERENCE passes just a pointer to a temp-table location rather than making a copy.

Observing these guidelines whenever you use temp-tables can greatly improve your application’s performance.

Note: These guidelines apply equally to passing ProDataSets as well as individual temp-tables.