Skip to main content
Business Central forum
Answered

Looping through a report DataItem based on quantity

editSubscribe (0) ShareShare
ReportReport
Posted on by 543

So we are using US Business Central 19.5 on-prem. And are working on an AL report. To generate item tags. The report itself works fine, and is pulling item details based on item ledger entries. Where I am running into trouble is breaking out the item quantities. For example, if item IT0000012 has an item ledger entry for a quantity of three I want to break that out as three separate, duplicated rows in the report. When I'm handling the dataitem I can see the item quantity as an exposed field obviously, but want to loop through that the same number of times.

Any suggestions?  

Categories:
  • Greg Kujawa Profile Picture
    Greg Kujawa 543 on at
    RE: Looping through a report DataItem based on quantity

    I figured out how to properly break out that ILE temporary buffer to stow away what I needed to break out. All good now. Thanks for the suggestion!

  • Greg Kujawa Profile Picture
    Greg Kujawa 543 on at
    RE: Looping through a report DataItem based on quantity

    Good suggestion! That's the first thing I looked at. Using an ILE variable defined as temporary. But when inserting new rows into that I was getting kickbacks about duplicate row values. I'm sure I'm going about it wrong, though. And I know you can't autoincrement row values in a temporary table.

  • Verified answer
    Amit_Sharma Profile Picture
    Amit_Sharma 2,545 on at
    RE: Looping through a report DataItem based on quantity

    Hi,

    Creating one buffer table and insert values as per the quantity of ILE and then print the values as per the buffer table.

    Regards

    Amit Sharma

    www.erpconsultors.com

  • Greg Kujawa Profile Picture
    Greg Kujawa 543 on at
    RE: Looping through a report DataItem based on quantity

    Looking at this more, I think I would need to create a new, custom table. Just containing the individual item "tags," with Item No., Serial No., Item Description, Unit Price, Barcode Value, etc. As I'd iterate through the Item Ledger Entries, I'd just push those rows into this custom temporary table. And use that as the lowest-level report source.

  • Greg Kujawa Profile Picture
    Greg Kujawa 543 on at
    RE: Looping through a report DataItem based on quantity

    Thanks for the tip, as that is a cleaner way to accomplish the iteration. Although I'm still unsure how to employ this procedure in terms of breaking out the separate lines in the report. Still working through that presently.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 59,873 Super User on at
    RE: Looping through a report DataItem based on quantity

    Hi, It may be simpler to use For-to.

    For-to and for-downto control structure

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-al-control-statements#for-to-and-for-downto-control-structure

    For example,

        procedure BreakoutIle(var ILE: Record "Item Ledger Entry"): Record "Item Ledger Entry"
        var
        i: Integer;
        begin
            ILEBreakout.Init();
            Quantity := ILE.Quantity;
            for i := 1 to Quantity do begin
                ILEBreakout := ILE;
                ILEBreakout.Insert();
                Quantity -= 1;
            end
            exit(ILEBreakout);
        end;

    Hope this helps.

    Thanks.

    ZHU

  • Greg Kujawa Profile Picture
    Greg Kujawa 543 on at
    RE: Looping through a report DataItem based on quantity

    I suppose I will need to create a procedure for breaking out these quantities into separate rows. Here is a sample I came up with. Just need to figure out how to include this logic in the report itself.

    codeunit 50119 DchApi_IleBreakout
    {
        var
            ILE: Record "Item Ledger Entry";
            ILEBreakout: Record "Item Ledger Entry" temporary;
            Quantity: Decimal;
    
        procedure BreakoutIle(var ILE: Record "Item Ledger Entry"): Record "Item Ledger Entry"
        begin
            ILEBreakout.Init();
            Quantity := ILE.Quantity;
            repeat
                ILEBreakout := ILE;
                ILEBreakout.Insert();
                Quantity -= 1;
            until (Quantity = 0);
            exit(ILEBreakout);
        end;
    }

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Sundar…

Industry experts answer burning questions directly from our amazing Community…

Enabling Copilot Case and Conversation…

Agents can easily recap an ongoing chat, transcribe a voice conversation…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,030 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans