将临时表值写入 .csv 文件

发布于 2025-01-07 05:47:19 字数 164 浏览 0 评论 0原文

我们动态创建了一个临时表。我们希望将完整的表格放入 .csv 文件中。怎么办?

DEF VAR ttH AS HANDLE NO-UNDO.
ttH:CREATE-LIKE(hBuffer).
ttH:Temp-table-prepare("tmytable")

We have created one temp-table dynamically . and we want to out put the complete table into a .csv file. how to do?

DEF VAR ttH AS HANDLE NO-UNDO.
ttH:CREATE-LIKE(hBuffer).
ttH:Temp-table-prepare("tmytable")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒与心事 2025-01-14 05:47:19

因为您动态创建了临时表,所以不能使用 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.

请注意,这可能不适用于大量表条目!

Because you created your temp-table dynamically, you cannot use the EXPORT statement (at least to my knowledge). What you can do though is dynamically output first the fieldnames and then the field values of your table. Like so:

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.

Just note that this might not perform for large quantities of table entries!

一身仙ぐ女味 2025-01-14 05:47:19

请参阅进度知识库 P4410用于范围处理语法。您可能还需要在 QUERY-PREPARE 之前将 FORWARD-ONLY=TRUE 添加到查询中,以可能提高性能。

See Progress KB P4410 for extent handling syntax. You might also want to add FORWARD-ONLY=TRUE to the query before QUERY-PREPARE to possibly boost performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文