web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Looping through a report DataItem based on quantity

(0) ShareShare
ReportReport
Posted on by 436

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?  

I have the same question (0)
  • Greg Kujawa Profile Picture
    436 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
    436 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.

  • Suggested answer
    Amit Profile Picture
    2,557 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
    436 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
    436 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
    89,839 Super User 2025 Season 2 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
    436 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;
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,899 Super User 2025 Season 2

#2
Sumit Singh Profile Picture

Sumit Singh 2,444

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,304

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans