如何在Progress 4gl中导出.csv时添加列名

时间:2017-05-26 14:41:31

标签: progress-4gl openedge

我想在从Progress DB导出数据时为.csv文件添加列名。

代码:

OUTPUT TO customer1.csv.
FOR EACH customer:
    EXPORT DELIMITER ";" customer .
END.
OUTPUT CLOSE.

1 个答案:

答案 0 :(得分:2)

您可以使用缓冲区动态循环遍历字段并构建标题行:

DEFINE VARIABLE hTable AS HANDLE NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.

hTable = BUFFER Customer:HANDLE.

OUTPUT TO customer1.csv.

/* Export header row. */
DO iLoop = 1 TO hTable:NUM-FIELDS:

    PUT UNFORMATTED hTable:BUFFER-FIELD(iLoop):NAME.

    IF iLoop < hTable:NUM-FIELDS THEN
        PUT UNFORMATTED ";".
END.

PUT SKIP.

/* Export records. */
FOR EACH Customer: 
    EXPORT DELIMITER ";" Customer. 
END.

OUTPUT CLOSE.

文件中的第一行将是数据库中的字段名称。