Passing Temp-Tables to Functions

KMoody

Member
Progress: 10.2b SP7

I've found plenty of threads about passing temp-tables to procedures but none (so far) about passing to functions. Is this possible? Do you have to pass your temp-table's buffer or handle instead?
 
Last edited:
Sure, here's a simple example from our code base:

FUNCTION InitializeTaxFormFiles RETURNS CHAR
(p_form AS CHAR,
TABLE tmp_errors):

You can pass handles or static tables, as in this example. One thing I don't believe you can do is return a static temp-table in the RETURNS clause. But handles work. Also, you could have a OUTPUT TABLE (static table) parameter .

IMO, OUTPUT parameters from functions are questionable style, and so is functions that are complex enough that they need table inputs. But these are both issues of taste, not functionality.
 
Thanks. I tried to do that like this:

Code:
FUNCTION isSafeToReplace RETURNS LOGICAL (TABLE b) FORWARD.
DEFINE TEMP-TABLE newSPQMasterLookup LIKE SPQMASTER.
FIND newSPQMasterLookup WHERE newSPQMasterLookup.SPQ-NUM = " "
    AND newSPQMasterLookup.CUST-NUM = "1000" NO-LOCK NO-ERROR.
DISPLAY isSafeToReplace(newSPQMasterLookup).

FUNCTION isSafeToReplace RETURNS LOGICAL
  (TABLE b):
  DISPLAY b.
end function.

However, this didn't work because "TEMP TABLE b could not be found." Why does the compiler even try to find it if I'm going to pass it later?
 
Your temp-table is referenced in a static way which means it is resolved at compile time - that's why. You need to pass it dynamically ( have a look at the table-handle paramter ) but then you can't just do a display with a static reference ...

Heavy Regards, RealHeavyDude.
 
You could use it statically if you just define it first, eg. make the first line of your code snip above 'DEF TEMP-TABLE b FIELD x AS CHAR.' should do the trick.

In either scenario, you can't 'DISPLAY b' per se because 'b' is a collection of records. You have to FIND one first.
 
Back
Top