Create static temp-table from dynamic temp-table

Jamie

New Member
Hello everyone,
I'm hoping that you may be able to help me out. I am currently working with 9.1E and I am wondering if it is possible to create a static temp-table from an existing dynamic temp-table. Pretty much the opposite of the CREATE-LIKE method used when creating the dynamic temp-table.

Thanks in advance!
Jamie
 
For the temp-table to be static you would need to create it at compile time.

Which means that you must already know its definition. Do you? If you don't then your question really doesn't make much sense.

If you do then go ahead and define it in your program.
 
Not without writing unwieldy, complicated reflection and 4GL/df-creating code, I suspect.

If you wait till you upgrade, there is the READ/WRITE-XMLSCHEMA() methods which would make the job easier perhaps.
 
For the temp-table to be static you would need to create it at compile time.

Which means that you must already know its definition. Do you? If you don't then your question really doesn't make much sense.

If you do then go ahead and define it in your program.

I scratched my head at first as well, as my first answer was 'no, by definition'.

However I suspect Jamie wants to use the schema of a temp-table set up at run-time in later static code. eg. the way you might use ERD.
 
Hello,
Sorry for my lackluster explanation of what I was trying to accomplish...

I scratched my head at first as well, as my first answer was 'no, by definition'.
However I suspect Jamie wants to use the schema of a temp-table set up at run-time in later static code. eg. the way you might use ERD.

Yep KnutHandsome, that is exactly what I am trying to do.

I want to reuse the schema from a dynamic temp-table that has a varying amount of fields (the number being based on the results of a subset of data (i.e. metallurgical tests)). The problem being that I can't just reference the buffer of the dynamic temp-table for what I am trying to accomplish, I have to (more-or-less) adhere to the standards of the ERP that we are using. And the ERP is expecting a static temp-table.

I'm realizing now that I may have to break down and modify more of the ERP's standard code than what I had originally wanted/thought...

Thanks for your replies!
 
If the ERP is expecting a static temp-table, then doesn't that expectation imply a static temp-table definition? And, if so, doesn't that imply that you problem is more one of copying the dynamic temp-table to the static one?
 
Not without writing unwieldy, complicated reflection and 4GL/df-creating code, I suspect.

The other comments in the thread aside, its actually not at all complicated, as you are probably aware; you just need something along the lines of the following demonstration code.

It's very rudimentary with no cleanup or error handling; proof of concept only by someone with little experience of writing dynamic code.

Code:
PROCEDURE DumpTTDef.

DEF INPUT PARAMETER htt AS HANDLE NO-UNDO.

DEFINE VARIABLE i AS INTEGER    NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE     NO-UNDO.
DEFINE VARIABLE hField AS HANDLE     NO-UNDO.

hBuffer = htt:DEFAULT-BUFFER-HANDLE.

OUTPUT TO c:\temp\dumptt.p.

PUT UNFORMATTED 
    'define temp-table ' htt:NAME SKIP
    .

DO i = 1 TO hBuffer:NUM-FIELDS
    :
    
    hField = hBuffer:BUFFER-FIELD(i):HANDLE.

    PUT UNFORMATTED 
        '    field ' hField:NAME ' as ' hField:DATA-TYPE SKIP.  

/* ... other attributes ... */


END.

/* ... index defs ... */

PUT '    .'.

OUTPUT CLOSE.

END PROCEDURE.

If you have the 'temp-table expositor' from the PEG utilities page (RIP), there is some ready made code that will dump a DF from a tt-handle which you could use in temp-db or adapt to output 4GL instead.
 
Hello again,
I really appreciate the comments you guys have left. I always seem to find answers here.

Tamhas, yes the ERP is expecting the static temp-table, but only in the sense of how it addresses it. The ERP uses this temp-table for its standard export functionality, which basically does a nice dump of this table to text, excel, crystal, etc. It gets created via an include that is different for each report. So, yes, you are correct in the sense that if the table schema was the same between the static and dynamic temp-table, I could just copy between. But for this report, I won't know the fields I need until run-time, because the amount can grow as needed.

KnutHandsome, that is an excellent idea! I completely see what you are demonstrating and will look into it further. The only downside is that the clients do not have access to a compiler with the license that is installed on the servers... I may have to look into xcode or something.

Unfortunately I didn't grab a copy of temp-table expositor and I can't seem to find a copy floating on the net anywhere. It sounds pretty intriguing and if anyone has a copy, I'd be interested in checking it out.

Thanks again!

Jamie
 
Back
Top