简体   繁体   中英

How to export Fields to CSV in OPENEDGE

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM