Here is the help for Transaction No.
Transaction No. Field
This field shows the transaction number assigned to all the entries involved in the same transaction. If there are any G/L entries, bank account ledger entries or vendor ledger entries associated with the customer ledger entry, they are assigned the same transaction number.
The number is used to connect all entries that are created by the same posting.
----------------------------------------------------------------------------------------------------------------------------
Make sure that you are not trying to change any one of the entry no. of g/l entry or vendor lendger entry or customer ledger entry..
When coming to your question, they are created in Codeunit 12 with functions initglentry, postcust and postvend..