Doubt codeunit.run

gonzy1981gonzy1981 Member Posts: 156
Hello,
I've done two codeunits which do these things:
codeunit 50000
CD50001.RUN;
table50000.i := 333333;
Table50000.localtime := TIME;
Table50000.INSERT;
Here is the code of the codeunit 50001:
FOR i := 0 TO 2000 DO BEGIN
TABLE50000.I := i;
TABLA50000.localtime := TIME;
TABLA50000.INSERT;
END;
Then I realize after running this that the record 333333 is the oldest (according to the TIME), If I'm running the cd50001 in run (not runmodal). Why firstly is running all the code of the cd50001 and the system is waiting?? And after have finished whole the cd50001 carry on with the following code of the codeunit 50000.
Codeunit 50000 is like, It would have been run in runmodal.

Do you catch me???

Comments

  • Alex_ChowAlex_Chow Member Posts: 5,063
    No, I don't catch you. :(

    To resolve a problem like this, run your code using the debugger and step through. You'll be able to figure out the answer you need.

    Once you find the answer, remember to come back here and post your findings.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    It might be related to buffered inserts.
  • krikikriki Member, Moderator Posts: 9,112
    For codeunit, there is not something like RUNMODAL. Only RUN exists and it behaves as RUNMODAL.

    If you do something like this with forms/pages or reports, you will have the same result because a NAV-session can only run 1 set of statements at the time, so when you launch a RUN, this one starts and does everything it has to do and when it finishes (but does not close if you use RUN) the calling object can continue to do its things.

    So what you saw is perfectly normal both for codeunits and other objects.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • vaprogvaprog Member Posts: 1,141
    Alex Chow wrote:
    To resolve a problem like this, run your code using the debugger and step through. You'll be able to figure out the answer you need.
    You might get different results stepping through the debugger than running normally. This has to do with the commit buffer (and possibly asynchronous execution on the database server). And, of course, with time.
    It might be related to buffered inserts.
    I can't see how this would happen in this particular case. Nothing is read back from the db and timestamps are set by code, not by the database. Furthermore, nothing gets modified or overwritten. Just plain inserts.
    kriki wrote:
    Only RUN exists and it behaves as RUNMODAL
    That's right. If so, and given (assumed) buffering does not alter anything in this case, the outcome is truly astonishing.

    Is this on SQL Server? What are the SQL statements generated?
Sign In or Register to comment.