Product Information
Inventory Counting in SAP Business SDK
About Inventory Counting:
Inventory counting (also known as Stock Taking/Stock Counting) helps you to keep track of your inventory.
Inventory counting is crucial to any company that manages an inventory, be it perpetual or periodic. By matching the actual inventory to the quantities saved in the database, companies can adjust existing inventory records, detect unusual or unacceptable discrepancies, and improve inventory management.
After creating an Inventory Counting document to record the counting results, you must post the inventory changes to effect the adjustments in the system. For this, you need to create an Inventory Posting document based on the Inventory Counting document.
For more details on Inventory Counting, you can refer to following link:
Using Inventory Counting in SAP Business One SDK:
Inventory Counting is exposed as a service type Object (InventoryCountingsService) in SAP Business One SDK.
Add an Inventory Counting Document using DI API:
SAPbobsCOM.CompanyService oCS = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
SAPbobsCOM.InventoryCountingsService oICS = oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryCountingsService);
SAPbobsCOM.InventoryCounting oIC = oICS.GetDataInterface(SAPbobsCOM.InventoryCountingsServiceDataInterfaces.icsInventoryCounting);
DateTime dt = DateTime.Now;
oIC.CountDate = DateTime.Now;
SAPbobsCOM.InventoryCountingLines oICLS = oIC.InventoryCountingLines;
SAPbobsCOM.InventoryCountingLine oICL = oICLS.Add();
oICL.ItemCode = "A00001";
oICL.CountedQuantity = 4;
oICL.WarehouseCode = "01";
oICL.Counted = SAPbobsCOM.BoYesNoEnum.tYES;
SAPbobsCOM.InventoryCountingParams oICP = oICS.Add(oIC);
Update an Inventory Counting Document using DI API:
SAPbobsCOM.CompanyService oCS = oCompany.GetCompanyService();
SAPbobsCOM.InventoryCountingsService oICS = (SAPbobsCOM.InventoryCountingsService)oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryCountingsService);
SAPbobsCOM.InventoryCountingParams oICP = (SAPbobsCOM.InventoryCountingParams)oICS.GetDataInterface(SAPbobsCOM.InventoryCountingsServiceDataInterfaces.icsInventoryCountingParams);
oICP.DocumentEntry = 1;
SAPbobsCOM.InventoryCounting oIC = oICS.Get(oICP) as SAPbobsCOM.InventoryCounting;
SAPbobsCOM.InventoryCountingLine line = oIC.InventoryCountingLines.Item(0);
line.CountedQuantity = 2;
oICS.Update(oIC);
Remove the lines/rows from an Inventory Counting Document using DI API:
SAPbobsCOM.CompanyService oCS = SBOCompany.GetCompanyService();
SAPbobsCOM.InventoryCountingsService oICS = (SAPbobsCOM.InventoryCountingsService)oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryCountingsService);
SAPbobsCOM.InventoryCountingParams oICP = (SAPbobsCOM.InventoryCountingParams)oICS.GetDataInterface(SAPbobsCOM.InventoryCountingsServiceDataInterfaces.icsInventoryCountingParams);
SAPbobsCOM.InventoryCountingLine oICl;
oICP.DocumentEntry = 1;
SAPbobsCOM.InventoryCounting oIC = oICS.Get(oICP) as SAPbobsCOM.InventoryCounting;
int i = 0;
while ((i < oIC.InventoryCountingLines.Count))
{
oICl = oIC.InventoryCountingLines.Item(i);
if ((oICl.CountedQuantity == 0))
{
oIC.InventoryCountingLines.Remove(i);
}
i = (i + 1);
}
oICS.Update(oIC);
Close an Inventory Counting Document using DI API:
SAPbobsCOM.CompanyService oCS = SBOCompany.GetCompanyService();
SAPbobsCOM.InventoryCountingsService oICS = (SAPbobsCOM.InventoryCountingsService)oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryCountingsService);
SAPbobsCOM.InventoryCountingParams oICP = (SAPbobsCOM.InventoryCountingParams)oICS.GetDataInterface(SAPbobsCOM.InventoryCountingsServiceDataInterfaces.icsInventoryCountingParams);
SAPbobsCOM.InventoryCountingLine oICl;
oICP.DocumentEntry = 1;
SAPbobsCOM.InventoryCounting oIC = oICS.Get(oICP) as SAPbobsCOM.InventoryCounting;
oICS.Close(oICP);
Dear Ankit,
Thank you, Its very useful
Dear Ankit,
Is there an option to save inventory counting as draft? Or is it only possible via SAP B1 Client?
Kind Regards,
Atilla
Hello Aniket,
InventoryCountingsService is available in Di Server ? Please update
Regards,
Rahul Jain
Hi Rahul Jain,
Yes, you can use InventoryCountingsService in DI Server.
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
Hello ANKIT CHAUHAN ,
How do you add and update a inventory counting with multiple counters?
Kind regards,
Nicole.
Hi Nicole Fabian,
Refer to the following sample code:
Hope it helps!
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
Hello ANKIT CHAUHAN,
Thank you for the above, but how do you update lines quantity linked to multiple individual counters?
Kind regards,
Nicole.
Hi Nicole Fabian,
Unfortunately, I didn't understand the question.
Can you please share few screenshots? Also, whether the same operation is possible manually using SAP Business One client?
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
Hello ANKIT CHAUHAN,
I currently have a service that creates inventory counting's that has multiple individual counters. Adding this inventory counting works 100% but now I need to update said inventory counting lines counted quantity for each individual counter.
If you look at the below image for reference, I need to update "Nicole - Counted Qty".
Kind regards,
Nicole.
Hi Nicole Fabian,
Kindly confirm whether the same operation is possible manually using SAP Business One client?
Also, what is the issue when using DI API?
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
Hello ANKIT CHAUHAN,
Yes, it is possible to do the same operation in SAP.
The issue is that I cant find any examples on how to do the update? Is it possible to provide example code please?
Kind regards,
Nicole.
Hello ANKIT CHAUHAN,
Please note that I got it right - no need to send example.
Kind regards,
Nicole.
Hi Nicole Fabian,
I would appreciate if you can share the solution so that others are benefited.
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
Hello ANKIT CHAUHAN,
Please see example below:
Company SAP_Company = SAPConnection.diCompany;
CompanyService oCS = SAP_Company.GetCompanyService();
InventoryCountingsService oICS = (InventoryCountingsService)oCS.GetBusinessService(ServiceTypes.InventoryCountingsService);
InventoryCountingParams oICP = (InventoryCountingParams)oICS.GetDataInterface(InventoryCountingsServiceDataInterfaces.icsInventoryCountingParams);
oICP.DocumentEntry = DocEntry;
InventoryCounting oIC = oICS.Get(oICP) as InventoryCounting;
while (i < oIC.InventoryCountingLines.Count)
{
InventoryCountingLine line = oIC.InventoryCountingLines.Item(i);
foreach (DataRow row in dt.Rows)
{
if (line.CounterID == CounterID && line.ItemCode == Convert.ToString(row["U_ItemCode"].ToString()) && line.WarehouseCode == Convert.ToString(row["U_Warehouse"].ToString()) && line.BinEntry == Convert.ToInt32(row["U_BinEntry"].ToString()))
{
line.CountedQuantity = double.Parse(row["U_CountedQty"].ToString().Trim(), CultureInfo.InvariantCulture);
}
if (row["U_Counted"].ToString() == "Y")
line.Counted = BoYesNoEnum.tYES;
else
line.Counted = BoYesNoEnum.tNO;
if (row["U_Freeze"].ToString() == "Y")
line.Freeze = BoYesNoEnum.tYES;
else
line.Freeze = BoYesNoEnum.tNO;
}
i++;
}
oICS.Update(oIC);
Kind regards,
Nicole.