Hi Manuel,
The below works for me :
private static void CreatePosting(SAPbobsCOM.Company oC) { SAPbobsCOM.CompanyService oCS = oC.GetCompanyService(); SAPbobsCOM.InventoryPostingsService oPS = oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryPostingsService) as SAPbobsCOM.InventoryPostingsService; SAPbobsCOM.InventoryPosting oP = oPS.GetDataInterface(SAPbobsCOM.InventoryPostingsServiceDataInterfaces.ipsInventoryPosting) as SAPbobsCOM.InventoryPosting; SAPbobsCOM.InventoryPostingParams oPP = null; SAPbobsCOM.InventoryPostingLine oPL = oP.InventoryPostingLines.Add(); oPL.ItemCode = "B10001"; oPL.WarehouseCode = "01"; oPL.CountedQuantity = 6; SAPbobsCOM.InventoryPostingBatchNumber oPLB = oPL.InventoryPostingBatchNumbers.Add(); oPLB.BaseLineNumber = 1; oPLB.Location = "01"; oPLB.BatchNumber = "B1234"; oPLB.Quantity = -10; oPLB = oPL.InventoryPostingBatchNumbers.Add(); oPLB.BaseLineNumber = 1; oPLB.Location = "01"; oPLB.BatchNumber = "C1234"; oPLB.Quantity = -4; String sXML = oP.ToXMLString(); try { oPP = oPS.Add(oP); System.Console.WriteLine("Posted " + oPP.DocumentNumber.ToString()); } catch (Exception Ex) { System.Console.WriteLine(Ex.Message); } }
Note the batch quantity are negative if you have less counted qty.
My scenario : Item Code =B1001, Existing SAP Record QTY = Batch 'B1234' = 10 + Batch 'C1234' = 10
Counted Qty = Batch 'B1234' = 0 + Batch 'C1234' = 6
Regards
Edy
Hi Manuel,
Are you adding inventory counting or inventory posting ? Sorry, a bit confused because your post mixes the two terms.
Your logic should be correct for posting object, not for counting object.
Or you can try creating counting document, then create the posting object based on the counting document.
Regards
Edy
Hi Edy,
I meant a inventory posting document, not a inventory counting document: our customer wanted to post the counting differences directly, when the external system sends the final count results.
In the end, if we can't figure out the problem, we can analyze the alternative way you suggest: first post the inventory counting and immediately next, copy it to inventory posting...
However, either our inventory posting algorithm is wrong or the DI-API has a bug...
Thanks,
mdias
Hi Edy,
Thanks for the example.
It allowed us to realize the problem was related to another issue: the inventory posting was sent several days after the physical counting which lead to different stock figures in SAP since the posting algorythm takes into account the current SAP stock figures, thus originating the typical "Cannot add row without complete selection of batch/serial numbers" error...
mdias
Add comment