以 CSV 格式输出报告的程序
A program that outputs a report, as a CSV
我如何为可以接受三个输入参数的程序编写代码:x、y 和要写入的文件名?
我应该可以这样调用程序:
运行 prog.p(输入“1”,输入5,输入“filename1.csv”)。
到目前为止,我已经编写了下面的代码,但不确定如何绕过它。
OUTPUT TO xxxxxx\filename1.csv".
DEFINE VARIABLE Profit AS DECIMAL FORMAT "->>,>>9.99":U INITIAL 0 NO-UNDO.
EXPORT DELIMITER "," "Amount" "Customer Number" "Invoice Date" "Invoice Number" "Total_Paid" "Profit".
FOR EACH Invoice WHERE Invoice.Ship-charge > 5.00
AND Invoice.Total-Paid > 0.01
AND Invoice.Invoice-Date GE 01/31/93 /* this is between also can use < >*/
AND Invoice.Invoice-Date LE TODAY NO-LOCK:
Profit = (Invoice.Invoice-Num / Invoice.Total-Paid) * 100.
EXPORT DELIMITER "," Amount Cust-Num Invoice-Date Invoice-Num Total-Paid Profit.
END.
OUTPUT CLOSE.
谢谢。
你走对了! OUTPUT TO VALUE(variable)
可能对您有所帮助。您还应该使用命名流。
我不清楚参数 x 和 y 应该做什么,所以我只是将它们作为下面的虚拟对象插入。
注意:
您在评论使用 <> 而不是 GE。这可能在逻辑上可行,但可能(将)通过强制数据库扫描整个表而不是使用索引来影响您的性能。
像这样:
DEFINE INPUT PARAMETER pcX AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER piY AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER pcFile AS CHARACTER NO-UNDO.
/* Bogus temp-table to make the program run... */
/* Remove this unless just testing without database ...*/
DEFINE TEMP-TABLE Invoice NO-UNDO
FIELD Ship-Charge AS DECIMAL
FIELD Total-Paid AS DECIMAL
FIELD Invoice-Date AS DATE
FIELD Invoice-Num AS INTEGER
FIELD Amount AS INTEGER
FIELD Cust-Num AS INTEGER.
DEFINE STREAM str.
DEFINE VARIABLE Profit AS DECIMAL FORMAT "->>,>>9.99":U INITIAL 0 NO-UNDO.
OUTPUT STREAM str TO VALUE(pcFile).
EXPORT STREAM str DELIMITER "," "Amount" "Customer Number" "Invoice Date" "Invoice Number" "Total_Paid" "Profit".
FOR EACH Invoice WHERE Invoice.Ship-charge > 5.00
AND Invoice.Total-Paid > 0.01
AND Invoice.Invoice-Date GE 01/31/93 /* this is between also can use < >*/
AND Invoice.Invoice-Date LE TODAY NO-LOCK:
Profit = (Invoice.Invoice-Num / Invoice.Total-Paid) * 100.
EXPORT STREAM str DELIMITER "," Amount Cust-Num Invoice-Date Invoice-Num Total-Paid Profit.
END.
OUTPUT STREAM str CLOSE.
现在你可以运行这个程序了,假设它被命名为"program.p":
RUN program.p("1", 5, "c:\temp\file.txt").
或
RUN program.p(INPUT "1", INPUT 5, INPUT "c:\temp\file.txt").
(INPUT 是参数的默认方向)。
编辑:
运行 示例 + 将第一个输入更改为 CHARACTER 而不是整数
我如何为可以接受三个输入参数的程序编写代码:x、y 和要写入的文件名?
我应该可以这样调用程序: 运行 prog.p(输入“1”,输入5,输入“filename1.csv”)。
到目前为止,我已经编写了下面的代码,但不确定如何绕过它。
OUTPUT TO xxxxxx\filename1.csv".
DEFINE VARIABLE Profit AS DECIMAL FORMAT "->>,>>9.99":U INITIAL 0 NO-UNDO.
EXPORT DELIMITER "," "Amount" "Customer Number" "Invoice Date" "Invoice Number" "Total_Paid" "Profit".
FOR EACH Invoice WHERE Invoice.Ship-charge > 5.00
AND Invoice.Total-Paid > 0.01
AND Invoice.Invoice-Date GE 01/31/93 /* this is between also can use < >*/
AND Invoice.Invoice-Date LE TODAY NO-LOCK:
Profit = (Invoice.Invoice-Num / Invoice.Total-Paid) * 100.
EXPORT DELIMITER "," Amount Cust-Num Invoice-Date Invoice-Num Total-Paid Profit.
END.
OUTPUT CLOSE.
谢谢。
你走对了! OUTPUT TO VALUE(variable)
可能对您有所帮助。您还应该使用命名流。
我不清楚参数 x 和 y 应该做什么,所以我只是将它们作为下面的虚拟对象插入。
注意: 您在评论使用 <> 而不是 GE。这可能在逻辑上可行,但可能(将)通过强制数据库扫描整个表而不是使用索引来影响您的性能。
像这样:
DEFINE INPUT PARAMETER pcX AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER piY AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER pcFile AS CHARACTER NO-UNDO.
/* Bogus temp-table to make the program run... */
/* Remove this unless just testing without database ...*/
DEFINE TEMP-TABLE Invoice NO-UNDO
FIELD Ship-Charge AS DECIMAL
FIELD Total-Paid AS DECIMAL
FIELD Invoice-Date AS DATE
FIELD Invoice-Num AS INTEGER
FIELD Amount AS INTEGER
FIELD Cust-Num AS INTEGER.
DEFINE STREAM str.
DEFINE VARIABLE Profit AS DECIMAL FORMAT "->>,>>9.99":U INITIAL 0 NO-UNDO.
OUTPUT STREAM str TO VALUE(pcFile).
EXPORT STREAM str DELIMITER "," "Amount" "Customer Number" "Invoice Date" "Invoice Number" "Total_Paid" "Profit".
FOR EACH Invoice WHERE Invoice.Ship-charge > 5.00
AND Invoice.Total-Paid > 0.01
AND Invoice.Invoice-Date GE 01/31/93 /* this is between also can use < >*/
AND Invoice.Invoice-Date LE TODAY NO-LOCK:
Profit = (Invoice.Invoice-Num / Invoice.Total-Paid) * 100.
EXPORT STREAM str DELIMITER "," Amount Cust-Num Invoice-Date Invoice-Num Total-Paid Profit.
END.
OUTPUT STREAM str CLOSE.
现在你可以运行这个程序了,假设它被命名为"program.p":
RUN program.p("1", 5, "c:\temp\file.txt").
或
RUN program.p(INPUT "1", INPUT 5, INPUT "c:\temp\file.txt").
(INPUT 是参数的默认方向)。
编辑: 运行 示例 + 将第一个输入更改为 CHARACTER 而不是整数