2016-09-15 3 views
0

Tout d'abord, je suis très nouveau à Progress 4GL et toujours essayer de comprendre comment fonctionne l'imbrication pour tous les blocs. Je les deux tableaux qui suivent que je reçois des informations sur, ivc_header et ivc_mchgs:Progresser 4GL blocs d'imbrication pour afficher les données connexes

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 

Juste Pour votre information, la clé primaire pour ivc_header est invoice_nbr et ivc_mchgs primaire est une clé composite constitué de invoice_nbr, line_nbr , et misc_seq_nbr. La clé étrangère est facture_nbr.

Juste une note sur les données, les informations dans ivc_mchgs sont des frais divers par facture line_nbr. Ce que j'essaie d'obtenir est le total facture_amt et l'extension par sold_to_cust_nbr + sold_to_cust seq. Après avoir fait des recherches, j'ai décidé de mettre les totaux dans les variables au lieu d'utiliser la fonction ACCUMULATE de Progress.

Voici le code que j'ai:

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. 

Ce code me donnera la invoice_amt totale par sold_to_cust_nbr + sold_to_cust_seq et totalise l'extension par invoice_nbr. Ce que je ne peux pas comprendre, c'est obtenir un total d'extension de sold_to_cust_nbr + sold_to_cust_seq.

Toute aide est appréciée.

Merci

Répondre

0

Dans l'hypothèse que vous voulez à la fois le total de change par facture et résumé, alors vous pouvez faire ceci:

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. 

la manière élégante serait de combiner les deux requêtes à l'aide d'une jointure externe gauche et utilisez le ACCUMU Les fonctions de RETARD, mais cela devrait fonctionner.

2

Je pense que vous pourriez ne pas être au courant que vous pouvez spécifier plusieurs clauses BY.

OIEau vous pourriez vouloir coder l'intérieur POUR CHAQUE quelque chose comme ceci:

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 ... 

etc.

+0

Merci pour le conseil sur plusieurs clauses BY, vous aviez raison, je n'étais pas au courant. – CuriousOne