如何在ABL编码中将数据写入CSV文件

use*_*690 3 csv progress-4gl openedge

我从查询中填充了一个临时表,临时表看起来像,

ttcomp.inum
ttcomp.iname
ttcomp.iadd
Run Code Online (Sandbox Code Playgroud)

此临时表中有5000条记录,现在我想写入CSV文件.我认为它可以完成,output stream但我不知道如何实现这一点.请有人帮我解决这个问题.

Jen*_*nsd 9

出口的诀窍是:

/* Define a stream */
DEFINE STREAM str.

/* Define the temp-table. I did some guessing according datatypes... */
DEFINE TEMP-TABLE ttcomp
    FIELD inum  AS INTEGER
    FIELD iname AS CHARACTER
    FIELD iadd  AS INTEGER.

/* Fake logic that populates your temp-table is here */
DEFINE VARIABLE i AS INTEGER     NO-UNDO.
DO i = 1 TO 5000:
    CREATE ttComp.
    ASSIGN 
        ttComp.inum  = i
        ttComp.iname = "ABC123"
        ttComp.iadd  = 3.

END.
/* Fake logic done... */

/* Output the temp-table */
OUTPUT STREAM str TO VALUE("c:\temp\file.csv").
FOR EACH ttComp NO-LOCK:
    /* Delimiter can be set to anything you like, comma, semi-colon etc */
    EXPORT STREAM str DELIMITER "," ttComp.
END.
OUTPUT STREAM str CLOSE.
/* Done */
Run Code Online (Sandbox Code Playgroud)