首先,我对 Progress 4GL 非常陌生,并且仍在尝试了解嵌套 FOR EACH 块的工作原理。我有以下两个表,我从中获取信息,ivc_header 和 ivc_mchgs:
ivc_header
invoice_nbr | sold_to_cust_nbr | sold_to_cust_seq | invoice_amt
1000051 | 70 | 0 | $1,000
1000049 | 70 | 1 | $1,500
1000010 | 310 | 0 | $2,000
1000011 | 310 | 1 | $2,500
ivc_mchgs
invoice_nbr | line_nbr | misc_seq_nbr | extension
1000051 | 1 | 1 | $300
1000051 | 1 | 2 | $200
1000051 | 2 | 1 | $100
1000049 | 1 | 1 | $400
1000049 | 1 | 2 | $100
1000049 | 2 | 1 | $150
1000010 | 1 | 1 | $50
1000010 | 1 | 2 | $50
1000010 | 2 | 1 | $100
1000011 | 1 | 1 | $75
1000011 | 1 | 2 | $80
1000011 | 2 | 1 | $90
仅供参考,ivc_header 的主键是 invoice_nbr,而 ivc_mchgs 的主键是由 invoice_nbr、line_nbr 和 misc_seq_nbr 组成的复合键。外键是 invoice_nbr。
只是关于数据的注释,ivc_mchgs 中的信息是按发票行_nbr 的杂项费用。
我想要得到的是总 invoice_amt 和 sold_to_cust_nbr + sold_to_cust seq 的扩展。在做了一些研究之后,我决定将总数放入变量中,而不是使用内置的累积函数 Progress'。
这是我拥有的代码:
DEFINE VARIABLE cCustNum AS CHARACTER NO-UNDO.
DEFINE VARIABLE dInvoiceSubTotal AS DECIMAL NO-UNDO.
DEFINE VARIABLE dSurchargeTotal AS DECIMAL NO-UNDO.
FOR EACH ivc_header
NO-LOCK
WHERE (ivc_header.sold_to_cust_nbr = "000070")
OR (ivc_header.sold_to_cust_nbr = "000310")
BREAK BY ivc_header.sold_to_cust_nbr:
IF FIRST-OF(ivc_header.sold_to_cust_nbr) THEN
ASSIGN dInvoiceSubTotal = 0.
ASSIGN dInvoiceSUbTotal = dInvoiceSUbTotal + ivc_header.invoice_amt.
IF LAST-OF(ivc_header.sold_to_cust_nbr) THEN
DISPLAY ivc_header.sold_to_cust_nbr + ivc_header.sold_to_cust_seq FORMAT "x(9)" LABEL "CustNum"
dInvoiceSUbTotal LABEL "SubTotal".
FOR EACH ivc_mchgs WHERE ivc_header.invoice_nbr = ivc_mchgs.invoice_nbr
NO-LOCK
BREAK BY ivc_mchgs.invoice_nbr:
IF FIRST-OF(ivc_mchgs.invoice_nbr) THEN
ASSIGN dSurchargeTotal = 0.
ASSIGN dSurchargeTotal = dSurchargeTotal + ivc_mchgs.extension.
IF LAST-OF (ivc_mchgs.invoice_nbr) THEN
DISPLAY
dSurchargeTotal LABEL "Surcharge".
END.
END.
此代码将为我提供按 sold_to_cust_nbr + sold_to_cust_seq 的总 invoice_amt,并按 invoice_nbr 计算扩展名。我不知道该怎么做是通过 sold_to_cust_nbr + sold_to_cust_seq 获得总扩展。
任何帮助表示赞赏。
谢谢