PurchOrder posting error throught code

I have two company MAC ,CAM.

I have intercomapny salesorder After posting salesorder IN" MAC" comapny, coressponding Purchase order is created in CAM. When i try to post it throught following code

purchTable _purchTable;
purchFormLetter purchFormLetter;
select * from _purchTable where _purchTable.PurchId == “000098”;
purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);

I am getting the following error

“Cannot find invoice"000098” in company MAC with parmId =."

Can you corect me where i have went worng.