Passing Codeunits as Parameters

I have recently discovered that it is possible to pass a codeunit to another function as a parameter and that the codeunit in the called function is the same instance as in the calling function (i.e. the values of any global variables are retained). This is very cool and I have never seen any documentation or discussion about this. An example of where this is useful would be if you need to post some additional inventory transactions as part of sales posting. In order to avoid errors about inserting item ledger entries and item application entries where the entry number already exists and in order to have a single item register for all the transactions it is necessary that all inventory postings go through the same instance of codeunit 22. Since there is already an instance of codeunit 22 created in codeunit 80 it is necessary that all inventory posting go through this instance of codeunit 22. Because it is possible to pass this same instance of codeunit 22 to another function in another codeunit it is possible to keep all the code for posting the additional transactions in another codeunit and the only change required in codeunit 80 is a simple call (passing codeunit 22 as one of the parameters) to this other function.

THANK YOU Jack! This is indeed cool and saves hours. 10 years with C/AL and not knowing this…[xx(] So many hours that could have been saved…