Purch. Lines Combine based on No. And Type.

Hi

Is there a function or a simple way to combine purchase lines based on "No." and "Type" values.

Thanks

 

Regards Kenneth

  • hi,

    There are many ways. Can i ask why do you want to do it?

  • In reply to ashu_bhatt13:

    Hi - and thanks for your feedback Smile

    I have done this code for the purpose :


    PurchaseLineOrg.SETCURRENTKEY("Document No.","Document Type","No.");
    PurchaseLineOrg.SETFILTER(PurchaseLineOrg."Document No.", Rec."No.");
    tmpItemNo       := '';
    tmpLineNo       := 10000000;

    IF PurchaseLineOrg.FINDSET THEN BEGIN
      REPEAT
        IF PurchaseLineOrg.Type <> PurchaseLineOrg.Type::" " THEN BEGIN
          IF tmpItemNo <> PurchaseLineOrg."No." THEN BEGIN
            tmpItemNo := PurchaseLineOrg."No.";
            tmpLineNo := tmpLineNo + 10;
            PurchaseLineCombined := PurchaseLineOrg;
            PurchaseLineCombined."Line No."           := tmpLineNo;
            PurchaseLineCombined.Quantity             := 1;
            PurchaseLineCombined."Line Amount"        := PurchaseLineOrg."Line Amount";
            PurchaseLineCombined."Direct Unit Cost"   := PurchaseLineOrg."Line Amount";
            IF PurchaseLineCombined.INSERT THEN;
          END ELSE BEGIN
              PurchaseLineCombined."Direct Unit Cost" := PurchaseLineCombined."Direct Unit Cost" + (PurchaseLineOrg."Line Amount");     
              PurchaseLineCombined."Line Amount"      := PurchaseLineCombined."Line Amount" + (PurchaseLineOrg."Line Amount");  
              PurchaseLineCombined.MODIFY;
          END;
        END;
      UNTIL PurchaseLineOrg.NEXT = 0 ;
    END;

    PurchaseLineOrg.SETFILTER(PurchaseLineOrg."Document No.", Rec."No.");
    IF PurchaseLineOrg.FINDSET(TRUE) THEN BEGIN
      REPEAT
        PurchaseLineOrg.DELETE; 
      UNTIL PurchaseLineOrg.NEXT = 0;
    END;

    PurchaseLineCombined.SETFILTER(PurchaseLineCombined."Document No.", Rec."No.");
    IF PurchaseLineCombined.FINDSET(TRUE) THEN BEGIN
      REPEAT
        PurchaseLineOrg := PurchaseLineCombined;
        PurchaseLineOrg.VALIDATE(PurchaseLineOrg."Direct Unit Cost");
        IF PurchaseLineOrg.INSERT THEN;
      UNTIL PurchaseLineCombined.NEXT = 0 ;
    END;

    Local Variables :
    PurchaseLineOrg         Record Purchase Line 
    PurchaseLineCombined Record Purchase Line 
    tmpItemNo                 Text  
    tmpLineNo                 Integer  

    I am a little newbie into NAV C/al.
    Does this code seem to be okay - or can it be compressed more, or done in another way ?

    THANKS

Related