Skip to Content
Product Information
Author's profile photo ANKIT CHAUHAN

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:

http://help.sap.com/saphelp_sbo92/helpdata/en/06/2b155358d8ff07e10000000a423f68/content.htm?frameset=/en/44/c4c1cd7ca22e17e10000000a114a6b/frameset.htm&current_toc=/en/b1/8fe14910cf46b9b2ff2de2f315e5a2/plain.htm&node_id=1658&show_children=false

 

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);

Assigned tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Manikandan. D
      Manikandan. D

      Dear Ankit,

      Thank you, Its very useful

      Author's profile photo Former Member
      Former Member

      Dear Ankit,

      Is there an option to save inventory counting as draft? Or is it only possible via SAP B1 Client?

      Kind Regards,

      Atilla

      Author's profile photo Rahul Jain
      Rahul Jain

      Hello Aniket,

      InventoryCountingsService is available in Di Server ? Please update

      Regards,

      Rahul Jain

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Hi Rahul Jain,

      Yes, you can use InventoryCountingsService in DI Server.

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support