Create a table using a variable?

rip73

New Member
Hello,

I am doing a dump of tables from a section of our system. Given who the customer is that we are dumping tables for, they may or may not have the full set of tables that are used in this section of the system so I am trying to be able to do this dynamically.

If I have two data dumps

table1.d
table2.d

Is there a way to extract "table1" from the name of the data file into a variable xtable-name to be used to create the table and then import the information in the .d into the table?

import stream of the .d files using the example here

assign xtable-name = "table1" (extract from the file name)

INPUT FROM table1.d.
REPEAT:
CREATE xtable-name.
IMPORT xtable-name.
END.
INPUT CLOSE.

Can something like this be done or do you have to explicitly name the table?
 

Stefan

Well-Known Member
Import works on a static buffer handle.
There is no import method for a dynamic buffer handle.

If the site where you need to run the load has a compile license available, then you can use run time compile time or whatever they are called arguments {1}.

Depending on how large your datasets are you could consider using json as format. The read-json and write-json methods both work on a dynamic buffer handle, the only caveat being that you must use an intermediate (dynamic) temp-table.
 
Hello,

I am doing a dump of tables from a section of our system. Given who the customer is that we are dumping tables for, they may or may not have the full set of tables that are used in this section of the system so I am trying to be able to do this dynamically.

If I have two data dumps

table1.d
table2.d

Is there a way to extract "table1" from the name of the data file into a variable xtable-name to be used to create the table and then import the information in the .d into the table?

import stream of the .d files using the example here

assign xtable-name = "table1" (extract from the file name)

INPUT FROM table1.d.
REPEAT:
CREATE xtable-name.
IMPORT xtable-name.
END.
INPUT CLOSE.

Can something like this be done or do you have to explicitly name the table?

I don't fully understand your question, but maybe this example can give you some ideas, (be sure you are not using -q parameter)
Code:
DEF VAR xtable-name AS CHAR NO-UNDO.
xtable-name = "table1".
OUTPUT TO temp.p.
PUT UNFORMATTED
"INPUT FROM table1.d."  SKIP
" REPEAT:" SKIP
"  CREATE " xtable-name  "." SKIP
"   IMPORT " xtable-name "."  SKIP
" END." SKIP
" INPUT CLOSE." SKIP
.
RUN temp.p.
 
Top