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 289

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?  

  • Greg Kujawa Profile Picture
    289 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
    289 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
    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
    289 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
    289 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
    79,164 Super User 2025 Season 1 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
    289 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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,947 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans