/* 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 */
FOR EACH ttComp NO-LOCK:
PUT STREAM str UNFORMATTED SUBSTITUTE("&1;&2;&3 \n", ttComp.inum, ttcomp.iname, ttcomp.iadd).
END.
0
这是一个没有流的替代方案 .
/* Using the temp-table. of Jensd*/
DEFINE TEMP-TABLE ttcomp
FIELD inum AS INTEGER
FIELD iname AS CHARACTER
FIELD iadd AS INTEGER.
OUTPUT TO somefile.csv APPEND.
FOR EACH ttcomp:
DISPLAY
ttcomp.inum + ",":U
ttcomp.iname + ",":U
ttcomp..iadd SKIP.
END.
OUTPUT CLOSE.
3 回答
出口的诀窍是:
还有另一种方式 . EXPORT很好,因为格式无关紧要,因为EXPORT忽略格式 . 例如,您不希望日期格式为mm / dd / yy . 在这种情况下,最好使用PUT STREAM并明确指定格式 .
这是一个没有流的替代方案 .