How to grouping by item category code in C/AL

Hello all,
I have sum Amount Including Vat of Sales Line grouping by Item Category Code in C/AL. How to group it?

Best Answer

  • KishormKishorm Member Posts: 921
    Answer ✓
    Try something like this...
    Salesline.reset
    Salesline.setfilter("document no", "No.")
    If salesline.findset then repeat
      TempSales.reset
      TempSales.setrange("item category code", salesline."item category code")
      If TempSales.findfirst then begin
        TempSales."amount including vat" += Salesline."amount including vat";
        TempSales.modify;
      End Else begin
        TempSales:=SalesLine
        TempSales.insert;
      End;
    Until SalesLine.next=0
    

Answers

  • postsauravpostsaurav Member Posts: 708
    Hi @undy0602 ,
    Where you want to group it - In report , page or during a custom code?

    Thanks & Regards,
    Saurav Dhyani

    Do you Know this About NAV?


    Connect - Twitter | Facebook | Google + | YouTube

    Follow - Blog | Facebook Page | Google + Page
  • undy0602undy0602 Member Posts: 67
    edited 2016-09-18
    Hi @postsaurav,
    I want it to group in page and codeunit
  • KishormKishorm Member Posts: 921
    For codeunit...

    1) create temp record for sales line
    2) loop through sales lines you want to group on
    3) check if temp sales line exists with same item category code as current sales line
    4) if no then add current sales line to temp sales line
    5) if yes then add amount incl vat to temp sales line
    6) repeat above for each sales line

    Now you have a set of temp sales lines - 1 per item category code,

    For page, it depends what you need, you could do something similar to the above and then have a page running the temp sale line
  • undy0602undy0602 Member Posts: 67
    Thanks @Kishorm,
    I tried it on below code

    Salesline.reset
    Salesline.setfilter("doc no", "No.")
    If salesline.findset then repeat
    TempSales.reset
    TempSales.setrange("item category code", salesline."item category code")
    If TempSales.findset then repeat
    TempSales.Amount+=Salesline.Amount
    Until TempSales.next=o
    Else TempSales:=SalesLine
    Until SalesLine.next=o

    But tempsales.amount isnt sumamount per item category code. It repeats per line and sumamount is wrong.
    Please correct it

    Regards,
    Undy
  • KishormKishorm Member Posts: 921
    Answer ✓
    Try something like this...
    Salesline.reset
    Salesline.setfilter("document no", "No.")
    If salesline.findset then repeat
      TempSales.reset
      TempSales.setrange("item category code", salesline."item category code")
      If TempSales.findfirst then begin
        TempSales."amount including vat" += Salesline."amount including vat";
        TempSales.modify;
      End Else begin
        TempSales:=SalesLine
        TempSales.insert;
      End;
    Until SalesLine.next=0
    
Sign In or Register to comment.