gpt4 book ai didi

openedge - 如何在每个循环中导出文本文件?

转载 作者:行者123 更新时间:2023-12-02 07:59:30 24 4
gpt4 key购买 nike

我编写了一个将文件导出到特定目录的程序,但我觉得我编写了一些不需要的逻辑。所以我想知道导出文件的简短且最佳的方法。让我分享一下我的尝试

DEFINE VARIABLE cData AS CHARACTER NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE icount AS INTEGER NO-UNDO.
DEFINE VARIABLE cName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.

DEFINE TEMP-TABLE ttdata
FIELD GetName AS CHARACTER
FIELD iValue AS INTEGER.

ASSIGN
icount = 2
cPath = "*******".

DO I = 1 TO icount:
IF I = 1 THEN cName = "David".
IF I = 2 THEN cName = "Macavo".


CREATE ttdata.
ASSIGN
ttdata.GetName = cName
ttdata.iValue = 100.
END.

/** ttdata has two records now*/
FOR EACH ttdata.
RUN CallProc.p (INPUT ttdata.GetName,
INPUT ttdata.iValue).
END.

PROCEDURE CallProc:

DEFINE INPUT PARAMETER getName AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER iValue AS INTEGER NO-UNDO.

OUTPUT TO cPath.
PUT UNFORMATTED ttdata.GetName ttdata.GetName.
OUTPUT CLOSE.
END PROCEDURE.

从我的逻辑来看,它运行良好,并按我的预期导出 2 个文件,但调用另一个过程是个糟糕的主意。请帮助这个案例。

最佳答案

我将在我的示例中使用sports2000 db。每个人都有一份副本,因此可以轻松运行示例。

define stream outFile.  /* using a named stream rather than the default, unnamed, stream avoids unintended conflicts if someone else's code is lazily using the unnamed stream */

function mkTemp returns character ( input tmpid as character, input extension as character ):

define variable fname as character no-undo.
run adecomm/_tmpfile.p ( tmpid, extension, output fname ).

/* create the temp file with no content
*/

output stream outFile to value( fname ).
output stream outFile close.

return fname.

end.


procedure doStuff:

define input parameter tmpfile as character no-undo.
define input parameter custid as integer no-undo.

output stream outFile to value( tmpFile ) append. /* open the existing file in append mode */

put stream outFile "customer:" custId skip.
for each order no-lock where order.custNum = custId and orderStatus <> "shipped" and salesRep = "bbb":
put stream outFile orderNum " " promised skip.
end.

output stream outFile close.

return.

end.

define variable i as integer no-undo.
define variable tmpName as character no-undo.

/* tmpName = mkTemp( "xyzzy", ".tmp" ). */ /* if you only need one temp file get the name here and comment it out below */

for each customer no-lock:

tmpName = mkTemp( "xyzzy", ".tmp" ). /* use this if every customer should get a distinct temp file */

run doStuff ( tmpName, custNum ).

/* if there is no good reason to be calling the doStuff() procedure then just remove it and do it inline like this: */

/*
*
output stream outFile to value( tmpFile ) append. /* open the existing file in append mode */

put stream outFile "customer:" customer.custNum skip.
for each order no-lock where order.custNum = customer.CustNum and orderStatus <> "shipped" and salesRep = "bbb":
put stream outFile orderNum " " promised skip.
end.

output stream outFile close.

*/

i = i + 1.
if i >= 3 then leave. /* just do 3 customers for the sample run... */

end.

关于openedge - 如何在每个循环中导出文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56455441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com