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

Notifications

Announcements

No record found.

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 583

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
    583 on at

    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;
    }

  • Suggested answer
    YUN ZHU Profile Picture
    95,548 Super User 2025 Season 2 on at

    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
    583 on at

    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.

  • Greg Kujawa Profile Picture
    583 on at

    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.

  • Suggested answer
    Amit Profile Picture
    2,559 on at

    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
    583 on at

    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.

  • Greg Kujawa Profile Picture
    583 on at

    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!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,151

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,443 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,092 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans