简体   繁体   English

如何在OPENEDGE中将字段导出为CSV

[英]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. 目前,我有一个表列表,其数据需要导出到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. 每个表平均有30-40个字段,需要导出5个表。

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. 您可以使用IMPORTEXPORT语句。 To export the temp table to a CSV file, use this code: 要将临时表导出到CSV文件,请使用以下代码:

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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