Download and install the ExecIt DataBlade which lets you generate dynamic SQL. For example, using the demo stores database you could create this, not overly useful FUNCTION, but it serves to illistrate the point.
CREATE FUNCTION createDynamicTempTable() RETURNING CHAR(30);
DEFINE returnValue LVARCHAR ;
DEFINE dynamicQuery LVARCHAR ;
DEFINE v_company CHAR(30) ;
DEFINE aValue INTEGER;
LET aValue=1;
LET dynamicQuery="SELECT * FROM customer INTO temp a" ||
aValue || ";";
CALL Exec(dynamicQuery) RETURNING returnValue ;
FOREACH SELECT company INTO v_company
FROM customer
RETURN v_company WITH RESUME ;
END FOREACH ;
END FUNCTION ;
This will create a temp table called a1 (the result of String Cat above). You could cat together any list of values, up to 128 to create a temp table name.
Hope that helps