我们已动态创建了一个临时表。我们希望将完整的表放入.csv文件中。怎么办?
DEF VAR ttH AS HANDLE NO-UNDO.
ttH:CREATE-LIKE(hBuffer).
ttH:Temp-table-prepare("tmytable")
答案 0 :(得分:1)
因为您动态创建了临时表,所以不能使用EXPORT语句(至少据我所知)。你可以做的是首先动态输出字段名,然后输出表的字段值。像这样:
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE ttH AS HANDLE NO-UNDO.
/* Define a new output stream */
DEFINE STREAM s1.
OUTPUT stream s1 to "myCSV.csv".
/* Create a query for the contents of your temp-table */
CREATE QUERY hQuery.
/* Important: we need to use the temp-tables default buffer handle,
/* not the hBuffer handle to the original table! */
hQuery:SET-BUFFERS (ttH:DEFAULT-BUFFER-HANDLE).
/* Use the name you created before for the FOR EACH clause */
hQuery:QUERY-PREPARE("FOR EACH tmytable").
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().
/* Write out the names of the fields as header in the first row */
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO ttH:DEFAULT-BUFFER-HANDLE:NUM-FIELDS:
PUT STREAM s1 UNFORMATTED ttH:DEFAULT-BUFFER-HANDLE:buffer-field(i):name + ",".
END.
PUT STREAM s1 UNFORMATTED SKIP.
/* Walk through the query and output each field seperately. */
REPEAT:
hQuery:GET-NEXT().
IF hQuery:QUERY-OFF-END THEN LEAVE.
DO i = 1 TO ttH:DEFAULT-BUFFER-HANDLE:NUM-FIELDS:
PUT STREAM s1 UNFORMATTED ttH:DEFAULT-BUFFER-HANDLE:buffer-field(i):buffer-value ",".
END.
PUT STREAM s1 UNFORMATTED SKIP.
END.
OUTPUT stream s1 close.
请注意,这可能不适用于大量的表条目!
答案 1 :(得分:1)
有关范围处理语法,请参阅Progress KB P4410。您可能还希望在QUERY-PREPARE之前向查询添加FORWARD-ONLY = TRUE,以提高性能。