Identical twins that aren't - codeunits 228 and 229

rocatisrocatis Member Posts: 163
I recently had to do some modifications to codeunits 228 ("Test Report-Print") and 229 ("Document-Print"), specifically to the way Invoice Discount was calculated. In doing so, I was surprised to find that the functionality of the two codeunits (which is essentially identical) has actually been implemented in distinctly different ways.

Take the PrintSalesOrder function in codeunit 229. It essentially does the following:

Calculates Invoice Discount
Prints report using REPORT.RUNMODAL


Sounds about right!

Codeunit 228 pretty much mirrors codeunit 229, except it deals with test reports instead of documents.

Take a look at the PrintSalesHeader function. It essentially does this:

Prints report using REPORT.RUN
Calculates Invoice Discount


A somewhat up-side-down way of doing things (and quite illogical to me). Still, it works because the calculation finishes before the report is actually executed by the user (if you replace RUN with RUNMODAL the calculation won't be done until the report has finished printing).

So what if you were to execute some (very) time consuming code between the two parts? Could you actually risk printing the report without calculating the invoice discount? The answer (again: weirdly) is no. Even though the report has been called using RUN and not RUNMODAL, it is not "released" to the user before the remaining code (i.e. the discount calculation) has been executed. This surprised me somewhat.

In conclusion, both codeunits do what they were designed to do. But I see no conceivable reason why you would ever structure your code the way it has been done in codeunit 228 - it's simply counter-intuitive.

Any thoughts?
Brian Rocatis
Senior NAV Developer
Elbek & Vejrup

Comments

  • SogSog Member Posts: 1,023
    rocatis wrote:
    So what if you were to execute some (very) time consuming code between the two parts? Could you actually risk printing the report without calculating the invoice discount? The answer (again: weirdly) is no. Even though the report has been called using RUN and not RUNMODAL, it is not "released" to the user before the remaining code (i.e. the discount calculation) has been executed. This surprised me somewhat.
    Any thoughts?

    I think why the report.run is executed after the discount calculation, is because the calculations locks the tables on which the report should run, so the report waits until the locks are released.
    However, I do agree that this is an odd way of written code.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
Sign In or Register to comment.