问题
Good day
I have a 2 parts problem. currently i have a list of tables and its data needs to be exported to csv. My code is here:
def temp table tt-table
field f1 as int
field f2 as char
field . . . .
output to value(session:temp-directory + "temp.csv").
put f1 at 1
"," f2. . .
output close.
is there a way to do this automatically or to shorten this code? there are 30-40 fields each table average and 5 tables needs to be exported.
Second part:
if i imported them back to our system, is it possible to dynamically create variables based on the number of fields and their corresponding variable types?
回答1:
You can use the IMPORT
and EXPORT
statements. To export the temp table to a CSV file, use this code:
OUTPUT TO VALUE(SESSION:TEMP-DIRECTORY + "temp.csv").
FOR EACH tt-table NO-LOCK:
EXPORT tt-table.
END.
OUTPUT CLOSE.
I don't know of a way to dynamically build a temp table from the file. But to import the file into the same table, do this:
INPUT FROM VALUE(SESSION:TEMP-DIRECTORY + "temp.csv").
REPEAT:
CREATE tt-table.
IMPORT tt-table.
END.
INPUT CLOSE.
来源:https://stackoverflow.com/questions/45828926/how-to-export-fields-to-csv-in-openedge