首先我對進程4GL非常陌生,仍然試圖探索如何嵌套FOR EACH塊。我有以下兩個表我得到的信息出來,ivc_header和ivc_mchgs:進度4GL嵌套塊顯示相關數據
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中的信息就是發票line_nbr的雜項費用。
我想要得到的是總的invoice_amt和由sold_to_cust_nbr + sold_to_cust seq擴展。在做了一些研究後,我決定把總數放在變量中,而不是使用ACCUMULATE函數中的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獲得總計延長。
任何幫助表示讚賞。
謝謝
感謝您對多個BY子句的建議,您是對的,我不知道。 – CuriousOne