The table where the Inventory posting data is stored is called InventPosting. To fetch the inventory balance main account that is typically used on a purchase order for an item, use something like the following.
LedgerDimension ledgerDimension;
ledgerDimension = InventPosting::accountItemLedgerDimension(
InventAccountType::PurchReceipt,
purchLine.ItemId,
purchLine.inventTable().itemGroupId(),
purchLine.ProcurementCategory,
purchLine.VendAccount,
purchLine.VendGroup,
purchLine.TaxGroup);
Examples of this code can be found in class InventMov_Purch method accountItem(..).
Unfortunately, the ledgerDimension that is returned is what is called a "default account" and cannot be directly stored on a LedgerJournalTrans record in the LedgerDimension field. Typically in AX it would then be combined with additional financial dimensions, i.e. a DefaultDimension field, to construct a final LedgerDimension.
While this is not the only way, you can convert that default account to a useful LedgerDimension with the following code.
ledgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(
ledgerDimension);
The ::serviceCreateLedgerDimension(..) static function has additional optional parameters for providing more than one DefaultDimension values, representing financial dimension, which it will merge with the main account for you, or you can use it as shown to convert just the main account by itself.
Notice that the DimensionDefaultingService class has many other interesting methods, such as ::serviceMergeLedgerDimensions(..) and :: serviceMergeDefaultDimensions(..).
This code is provided for education purposes only. Use at your own risk and test fully before deploying any code changes to a production environment.
Regards Hossein