defining a temp table like another table handle.

Posted by ojfoggin on 04-Jun-2009 08:36

Continuing from my previous question about accessing tables given a char variable of the table name...  (which has now enabled me to create the best lookup program in the universe! )

Now that I have a handle to my table e.g. htable.

Is it possible to define a temp-table like the table the handle refers to?

i.e. if htable is a handle to the customer table.

can I do something like...


define temp-table tt-mytable like htable.

...?

That particular code tells me that htable is an ambiguous or unknown table.

Any help is appreciated!

Thanks

Oliver

All Replies

Posted by kevin_saunders on 04-Jun-2009 08:46

No, you can't do it like that, the reason being is that the hTable handle is unknown at COMPILE time, which is when DEFINE requires it. But, you can use the CREATE TEMP-TABLE statement and point it to the handle of your table (look at the CREATE-LIKE method).

Posted by ojfoggin on 04-Jun-2009 08:54

Brilliant!

Thanks!

Posted by ojfoggin on 04-Jun-2009 09:23

Another quick question.

I have managed to create the temp-table this way inside a procedure (thank you).

Is there any way of passing a handle to the table as an output param so that the calling procedure can access the temp-table?

Thanks very much!

Oliver

Posted by kevin_saunders on 04-Jun-2009 10:47

Yeah, that's not an issue. If both procedures are in the same session, then just pass the handle. Instead of defining the variable to store the handle of the created TT, define it as an output parameter instead.

If there is an AppServer involved then you need a TABLE-HANDLE parameter instead of a HANDLE.

Posted by jmls on 05-Jun-2009 01:07

For portability between local and appserver sessions, have a look at BY-REFERENCE

This thread is closed