Ever had to post a large journal batch and an error was thrown just before all lines were checked? So you manage to identify the right journal line somewhere at the bottom of your batch. You fix the issue and post again. But now immediately the systems errs on the same line because of another issue.
Ever wondered why it didn't err instantly the first time? Reread the title of this blog post.
Let's have a look at the code behind. Did you ever wonder about this piece of code in the Code function-trigger in Post Batch codeunits, like codeunit 13 (Gen. Jnl.-Post Batch)?
// Check lines LineCount := 0; StartLineNo := "Line No."; REPEAT LineCount := LineCount + 1; Window.UPDATE(2,LineCount); ... GenJnlCheckLine.RunCheck(GenJnlLine5,TempJnlLineDim); ... IF NEXT = 0 THEN FINDFIRST; UNTIL "Line No." = StartLineNo;
As you probably know: before even trying to post the journal lines NAV is first checking all the journal lines - see the progress dialog!
It loops through the lines and calls for each line the RunCheck routine. What you might never have realized is that this loop does not start a the top of the lines. No, it starts with the active line (StartLine).
From that line on it:
And after tis checking are the lines posted in the same order? No, don't worry, after this all lines are posted from top to bottom.
It is sad that people don't know this, since its one of the very first things taught in the developer class. Which basically means that the people that didn't know this didn't do any training.
Training is a crucial part of becoming a Navision Professional, but these days people just want brain dumps.
In any case the perfromance logic behind this only works with Native Database and only when the database is correctly configured. I think it would be simpler (with very little performance difference) to just put the whole thing into a standard REPEAT UNTIL NEXT=0 loop.
Anyway its good to point out, but maybe also add some background as to why its done this way. Also explain the FIND('=><') command that is also a part of this.