How to export Fields to CSV in OPENEDGE

那年仲夏 提交于 2019-12-23 04:42:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!