以CSV格式输出报告的程序

时间:2018-11-21 09:17:35

标签: openedge progress-4gl progress-db

我该如何为可以接受三个输入参数的程序编写代码: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.

谢谢。

1 个答案:

答案 0 :(得分:5)

您在正确的轨道上! 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而不是整数