SAP note 2083799 provides a composite scenarios involving posting with Accounting BAPIs. But I want to share with you more details related rounding differences in cross-company scenario using BAPIs.
1) In case of cross-company scenarios the rounding difference is distributed at:
FORM SUBST_CLEARING (here the company code clearing line items are generated)
2) If the document is not a cross-company posting, the rounding difference is distributed at:
or (depending on the AWTYP)
Important to know is that the rounding difference will always be distributed as described in note 106094 (point 2 is relevant for postings using accounting interface). This means, even on cross-company scenarios the rounding difference is distributed to the first non-tax GL line item – no matter on which company code this item is. The logic in FB01 is equal.
In the form routine get_tolerance the tolerance level is determined, which is (in most cases) basically simply 2 * number of line items of the document. If the rounding difference is higher than this, the rounding difference cannot be distributed by FI-Interface.
If rounding difference is less than tolerance, the first non-tax GL line item is determined at:
loop at accit_fi where koart ca ‘MSA’
and taxit <> ‘X’
If it cannot be distributed to those items either, it is tried to distribute it to a Customer/Vendor line. If this fails as well, error should be raised. For some countries there is even a legal requirement to create a separate rounding difference line item, which is also done in those form routines. That is done at the very end at insert_rdf_items.
I hope this helps!