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 :
Microsoft Dynamics AX (Archived)

While loop turn into infinite loop AX 2009

(0) ShareShare
ReportReport
Posted on by 1,559

I got a wild error, which I haven't seen since begining of my IT career.

Maybe it's just X++:-)

 

We have a batch, in class, there is a while loop on resultset of SalesTable joining with other two tables, in this case, there is  about 100 records.

Once hit this particular record, loop then keep looping on this record, turned into a infinite loop, I found out it since we have a log in loop.

Of course, once I cancelled batch, restarted again, everything is fine and this has never happened before.

This must go into root of X++, how exact of this while loop in X++ works.

Have anybody experienced this before?

 

Many thanks,

River

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    I doubt that it's the while statement what's broken. Can you show us your code and describe the exact conditions ("this particular record" etc.) when it happens?

  • Ganriver1 Profile Picture
    1,559 on at

    Hi Martin,

    Here is code and record. I double checked record, there is nothing wrong or different with others. Please understand, I changed some names for privacy.

    ------------------------------------------------------------

       while select Table1

           where Table1.SessionId == _SessionId

           join Table2

               where Table2.PickingRef == Table1.WaveReferenceId

           join salesTable

               where salesTable.salesId == Table2.transRefId

               && salesTable.Sentflag == NoYes::No

       {

           if (salesTable.checkExistLineFlag())

           {

               this.logDetail();

               salesOrdersCount++;

               salesOrder = this.exportSalesOrder(Table2, salesTable);

               salesOrderLinesCount +=  salesOrder.parmSalesOrderLine().lastIndex();

               salesOrderArray.value(salesOrdersCount,salesOrder);

               salesOrderStatusLog::logStatusChange(salesOrder.parmSalesId(),

                                                           salesStatus::Submitted,

                                                           salesOrder.parmPickingRoute(),

                                                           OEMLog,

                                                           this.getXMLForSalesOrder(salesOrder));

           }

       }

    -------------------------------------------------------

    We grab the result set, then check if there are sales lines are not sent out(xml), then

    get all lines, create xml, update status.

    Here is the record:

    -------------------------------------------------------

    <SalesOrderOutbound>

     <FileId></FileId>

     <OrderCount>0</OrderCount>

     <OrderLineCount>0</OrderLineCount>

     <SalesOrder>

       <SalesId>S04145376</SalesId>

       <PickingRoute>PRT3340569</PickingRoute>

       <Customer>40295614</Customer>

       <OrderDate>08/04/2015</OrderDate>

       <Payment>CreditCard</Payment>

       <MerchTotal>439.70</MerchTotal>

       <ShippingTotal>25.00</ShippingTotal>

       <CouponTotal>10.00</CouponTotal>

       <CouponId>TDFZ</CouponId>

       <CouponDescription>$10 Off Any Order</CouponDescription>

       <TaxTotal>0.00</TaxTotal>

       <TaxJurisdiction></TaxJurisdiction>

       <OrderTotal>464.70</OrderTotal>

       <PaymentTotal>464.70</PaymentTotal>

       <Currency>USD</Currency>

       <BillingName>John Doe</BillingName>

       <BillingStreet1>main</BillingStreet1>

       <BillingStreet2></BillingStreet2>

       <BillingCity>New York</BillingCity>

       <BillingState>NY</BillingState>

       <BillingZip>10001</BillingZip>

       <BillingCountry>US</BillingCountry>

       <DeliveryMode>FX SP</DeliveryMode>

       <ShipToName>John Doe</ShipToName>

       <ShipToStreet1>Main</ShipToStreet1>

       <ShipToStreet2></ShipToStreet2>

       <ShipToCity>New York</ShipToCity>

       <ShipToState>NY</ShipToState>

       <ShipToZip>10001</ShipToZip>

       <ShipToCountry>US</ShipToCountry>

       <ShipToPhone>0000000000</ShipToPhone>

       <SpecialHandling>0.0</SpecialHandling>

       <SpecialNotes></SpecialNotes>

       <IsReplacement>0</IsReplacement>

       <IsGift>0</IsGift>

       <GiftMessage></GiftMessage>

       <BoxType>B</BoxType>

       <PiecesTotal>0</PiecesTotal>

       <WeightTotal>0.00</WeightTotal>

       <OtherShipmentsExist>1</OtherShipmentsExist>

     </SalesOrder>

    </SalesOrderOutbound>

    -------------------------------------------------------

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    So is this the piece of code where you have the problem (and not in some code on higher or lower level? If so, please describe the exact conditions (as I asked you before) and what happens in this code. And how is the XML file responsible for the infinite loop? I can't imagine any connection.

    This code alone does nothing suspicious, but if, for example, exportSalesOrder() modifies Table2, it might break the loop. That's what you can find by debugging, not by asking in forums. Please debug your code first - when you know what actually happens (which you obviously don't know it the moment), you'll likely understand what's the problem and how to fix it. If not, please share your findings here and we'll try to fill some gaps. There is little we can do for you if you don't collect and give us enough information about the problem.

  • Ganriver1 Profile Picture
    1,559 on at

    Martin,

    As I said in my first post, it worked after I cancelled batch and restarted it. And It never happened before. This batch runs every hour, and it didn't happen when debugging, of course:-(

    Only thing updated for those 3 tables in query, is SalesTable Sentflag in exportSalesOrder() when it finishes.

    But, why would that be the cause, the resultset is in memory already, isn't it?

    River

  • Ganriver1 Profile Picture
    1,559 on at

    Well, I guess it depends how the resultset are retrieved, if it travels to DB to retrieve record one at a time, then it could happen if updating flag failed.

    But, I doubt that's the case.

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    I'm sorry, but I can't give you any additional suggestions without more information.

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    "updating flag" is probably one of things that you forgot to explain

  • Ganriver1 Profile Picture
    1,559 on at

    while loop query, it returns 100 records, I checked. Query is not a problem.

  • Ganriver1 Profile Picture
    1,559 on at

    Yeah, it will be updated to 'yes'.

  • Community Member Profile Picture
    on at

    Please show me the code and condition.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans