如何在OPENEDGE中将字段导出为CSV [英] How to export Fields to CSV in OPENEDGE
问题描述
美好的一天
我有两个部分的问题.目前,我有一个表列表,其数据需要导出到csv.我的代码在这里:
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.
有没有一种方法可以自动执行此操作或缩短此代码?每个表平均有30-40个字段,需要导出5个表.
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.
第二部分:
如果我将它们导入到我们的系统中,是否可以根据字段数及其对应的变量类型动态创建变量?
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?
推荐答案
您可以使用IMPORT
和EXPORT
语句.要将临时表导出到CSV文件,请使用以下代码:
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.
这篇关于如何在OPENEDGE中将字段导出为CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!