Progress 4GL 嵌套块显示相关数据

Progress 4GL nesting blocks to display related data

首先,我对 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         |   ,000
        1000049     |        70        |        1         |   ,500
        1000010     |       310        |        0         |   ,000
        1000011     |       310        |        1         |   ,500

ivc_mchgs
    invoice_nbr | line_nbr | misc_seq_nbr | extension
       1000051  |     1    |      1       |   0
       1000051  |     1    |      2       |   0
       1000051  |     2    |      1       |   0
       1000049  |     1    |      1       |   0
       1000049  |     1    |      2       |   0
       1000049  |     2    |      1       |   0
       1000010  |     1    |      1       |    
       1000010  |     1    |      2       |    
       1000010  |     2    |      1       |   0
       1000011  |     1    |      1       |    
       1000011  |     1    |      2       |    
       1000011  |     2    |      1       |    

仅供参考,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 的扩展。在做了一些研究之后,我决定将总数放在变量中,而不是使用 Progress 内置的 ACCUMULATE 函数。

这是我的代码:

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 子句。

IOW 你可能想为每个内部代码编写这样的代码:

FOR EACH ivc_mchgs NO-LOCK WHERE ivc_header.invoice_nbr = ivc_mchgs.invoice_nbr 
    BREAK BY ivc_mchgs.invoice_nbr
          BY ivc_mchgs.sold_to_cust_nbr
          BY ivc_mchgs.sold_to_cust_seq:

    IF FIRST-OF(ivc_mchgs.invoice_nbr) THEN
        ASSIGN dSurchargeTotal = 0.

    IF FIRST-OF(ivc_mchgs.sold_to_cust_nbr ) THEN ...

等等

假设您希望按发票和摘要计算交换总计,那么您可以这样做:

DEFINE VARIABLE cCustNum AS CHARACTER           NO-UNDO.
DEFINE VARIABLE dInvoiceSubTotal AS DECIMAL     NO-UNDO.
DEFINE VARIABLE dSurchargeTotal AS DECIMAL      NO-UNDO.
DEFINE VARIABLE dSurchargeSubTl 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
               dSurchargeSubTl = 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"
            dSurchargeSubTL LABEL "Srchg SubTl".
    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 DO:
            DISPLAY dSurchargeTotal LABEL "Surcharge".
            ASSIGN dSurchargeSubTl = dSurchargeSubTl + dSurchargeTotal.
        END.
    END.
END.

优雅方法是使用左外连接合并两个查询,并使用 ACCUMULATE 函数,但这应该可行。