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

Using Inventory Revaluation in SAP Business One SDK

About Inventory Revaluation:

If your company runs a perpetual inventory system, you may need to perform inventory revaluation. It is also known as “Material Revaluation”. Valuation is based on the calculation methods like Moving Average, Standard, FIFO, or Serial/Batch.

For more information on Inventory Revaluation, you can refer to following link:

http://help.sap.com/saphelp_sbo92/helpdata/en/45/2365519e152b31e10000000a1553f7/content.htm?frameset=/en/44/c4c1cd7ca22e17e10000000a114a6b/frameset.htm&current_toc=/en/b1/8fe14910cf46b9b2ff2de2f315e5a2/plain.htm&node_id=1698&show_children=false

Inventory Revaluation/Material Revaluation in SAP Business One DI API:

“MaterialRevaluation” is a business object that enables you to update the items’ price (average price or standard price only), revaluate the stock, and create journal entries accordingly.

This object applies only to the companies that manage their stock using Continuous Stock system.

Below are some samples to use this object in DI API:

Add a Material Revaluation Document for the Items managed by ‘Batches’ and having Valuation method as ‘Serial/Batch’ using DI API:

SAPbobsCOM.MaterialRevaluation oMaterialRevaluation = default(SAPbobsCOM.MaterialRevaluation);
SAPbobsCOM.SNBLines oMaterialRevaluationSNBLines = default(SAPbobsCOM.SNBLines);
oMaterialRevaluation = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oMaterialRevaluation);
oMaterialRevaluation.DocDate = System.DateTime.Now;
oMaterialRevaluation.RevalType = "P";
oMaterialRevaluation.Comments = "Added through DIAPI";
oMaterialRevaluation.Lines.ItemCode = "TEST01";
oMaterialRevaluation.Lines.WarehouseCode = "02";
oMaterialRevaluation.Lines.RevaluationDecrementAccount = "_SYS00000000134";
oMaterialRevaluation.Lines.RevaluationIncrementAccount = "_SYS00000000135";
oMaterialRevaluationSNBLines = oMaterialRevaluation.Lines.SNBLines;
oMaterialRevaluationSNBLines.SetCurrentLine(0);
oMaterialRevaluationSNBLines.SnbAbsEntry = 80; //AbsEntry from OBTN Table
oMaterialRevaluationSNBLines.NewCost = 900;
oMaterialRevaluationSNBLines.Add();
oMaterialRevaluationSNBLines.SetCurrentLine(1);
oMaterialRevaluationSNBLines.SnbAbsEntry = 81; //AbsEntry from OBTN Table
oMaterialRevaluationSNBLines.NewCost = 1000;
int RetVal = oMaterialRevaluation.Add();
if (RetVal != 0)
{
oCompany.GetLastError(out RetVal, out ErrStr);
MessageBox.Show(ErrStr.ToString().Trim());
}
else
{
oMaterialRevaluation.SaveXML(@"C:\MYFOLDER\MaterialRevaluation.xml");
}

Add a Material Revaluation Document for the Items managed by ‘Serial Numbers’ and having Valuation method as ‘Serial/Batch’ using DI API:

SAPbobsCOM.MaterialRevaluation oMaterialRevaluation = default(SAPbobsCOM.MaterialRevaluation);
SAPbobsCOM.SNBLines oMaterialRevaluationSNBLines = default(SAPbobsCOM.SNBLines);
oMaterialRevaluation = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oMaterialRevaluation);
oMaterialRevaluation.DocDate = System.DateTime.Now;
oMaterialRevaluation.RevalType = "P";
oMaterialRevaluation.Comments = "Added through DIAPI";
oMaterialRevaluation.Lines.ItemCode = "MYITEM";
oMaterialRevaluation.Lines.WarehouseCode = "01";
oMaterialRevaluationSNBLines = oMaterialRevaluation.Lines.SNBLines;
oMaterialRevaluationSNBLines.SetCurrentLine(0);
oMaterialRevaluationSNBLines.SnbAbsEntry = 587; //AbsEntry from OSRN
oMaterialRevaluationSNBLines.NewCost = 15;
oMaterialRevaluationSNBLines.Add();
int RetVal = oMaterialRevaluation.Add();

if (RetVal != 0)
{
    oCompany.GetLastError(out RetVal, out ErrStr);
    MessageBox.Show(ErrStr.ToString().Trim());
}
else
{
    oMaterialRevaluation.SaveXML(@"C:\MYFOLDER\MaterialRevaluation.xml");
}

Add a Material Revaluation Document for the Item having Valuation method as ‘FIFO’ using DI API:

SAPbobsCOM.MaterialRevaluation oMaterialRevaluation = (SAPbobsCOM.MaterialRevaluation)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oMaterialRevaluation);
SAPbobsCOM.MaterialRevaluation_lines oMaterialRevaluationLines = oMaterialRevaluation.Lines;
SAPbobsCOM.FIFOLayers oFIFOLayers = oMaterialRevaluationLines.FIFOLayers;
SAPbobsCOM.CompanyService oCompanyService = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
SAPbobsCOM.MaterialRevaluationFIFOService oMRVFIFOService = (SAPbobsCOM.MaterialRevaluationFIFOService)oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.MaterialRevaluationFIFOService);
SAPbobsCOM.MaterialRevaluationFIFOParams oMRVFIFOParam = (SAPbobsCOM.MaterialRevaluationFIFOParams)oMRVFIFOService.GetDataInterface(SAPbobsCOM.MaterialRevaluationFIFOServiceDataInterfaces.mrfifosMaterialRevaluationFIFOParams);
SAPbobsCOM.MaterialRevaluationFIFO oMRVFIFO;

oMaterialRevaluation.DocDate = DateTime.Now;
oMaterialRevaluation.RevalType = "P";
oMaterialRevaluationLines.SetCurrentLine(0);
oMaterialRevaluationLines.ItemCode = "TEST2";
oMRVFIFOParam.ItemCode = "TEST2";
oMRVFIFOParam.LocationCode = "01";
oMRVFIFOParam.LocationType = "64";
oMRVFIFOParam.ShowIssuedLayers = SAPbobsCOM.BoYesNoEnum.tNO;
oMRVFIFO = oMRVFIFOService.GetMaterialRevaluationFIFO(oMRVFIFOParam);
oFIFOLayers.LayerID = oMRVFIFO.Layers.Item(0).LayerID;
oFIFOLayers.TransactionSequenceNum = oMRVFIFO.Layers.Item(0).TransactionSequenceNum;
oFIFOLayers.Price = 60;
int LayerNum = oMRVFIFO.Layers.Count;

for (int i = 1; i < LayerNum; ++i)
{
    oFIFOLayers.Add();
    oFIFOLayers.SetCurrentLine(i);
    oFIFOLayers.LayerID = oMRVFIFO.Layers.Item(i).LayerID;
    oFIFOLayers.TransactionSequenceNum = oMRVFIFO.Layers.Item(i).TransactionSequenceNum;
    oFIFOLayers.Price = 60;
}
int Add = oMaterialRevaluation.Add();

Assigned tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo William Grant
      William Grant

      Hi Ankit,

      Thanks for providing the code example.

      I did found use for Inventory Revaluation for an client.

      I'm working on a code example with the SDK for Inventory Revaluation in VB. When I try to execute the below code, I get Interneal 5002 error. Do you think there something wrong with the below code that is causing the error?

       

       

       

       Dim oMaterialRevaluation As SAPbobsCOM.MaterialRevaluation
              Dim oMaterialRevaluationSNBLines As SAPbobsCOM.SNBLines
      
              oMaterialRevaluation = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oMaterialRevaluation)
              oMaterialRevaluation.DocDate = System.DateTime.Now
              oMaterialRevaluation.RevalType = "P"
              oMaterialRevaluation.Comments = "Added through DIAPI"
              oMaterialRevaluation.Lines.ItemCode = "TEST227"
              oMaterialRevaluation.Lines.WarehouseCode = "44"
              oMaterialRevaluation.Lines.RevaluationDecrementAccount = "_SYS00100000784"
              oMaterialRevaluation.Lines.RevaluationIncrementAccount = "_SYS00100000784"
              oMaterialRevaluationSNBLines = oMaterialRevaluation.Lines.SNBLines
              oMaterialRevaluationSNBLines.SetCurrentLine(0)
              oMaterialRevaluationSNBLines.SnbAbsEntry = 315 'AbsEntry from OBTN Table
              oMaterialRevaluationSNBLines.NewCost = price
              oMaterialRevaluationSNBLines.Add()
              retVal = oMaterialRevaluation.Add()

       

      Regards,

       

       

      William

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

      Hi William,

      Try to add the same document using SAP Business One Client. Also make sure all the master data information (Item Code, Account Code, AbsEntry from OBTN) is correctly entered in DI API program.

      Kind regards,

      ANKIT CHAUHAN

      SAP SME Support

      Author's profile photo William Grant
      William Grant

      Hi Ankit,

      I can add the item using the B1 Client with no issue.

      I notice for increase and decrease account, it uses _SYS00000000780 .  I notice when I use the B1 Client to add the item for Inventory Revaluation, the item code does not exist OBTN.  Any other suggestions I can do to troubleshoot this issue?

      Regards,

       

      William

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

      Hi William,

      Item Code does not exist in OBTN, it means no batches exist for the Item Code. Am I getting it right?

      Batches should be there in order to add the Inventory Revaluation document.

      If that is not the case, please explain it in details.

      Kind regards,

      ANKIT CHAUHAN

      SAP SME Support

       

      Author's profile photo William Grant
      William Grant

      Hi Ankit,

      This is correct, no batches was not created.

      For the example I'm trying to build, I'm not using batch tracking. Instead, I want to assign a price to an item in a warehouse that doesn't have a price. What revision would I need to make to achieve something like this?

      Regards,

       

      William

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

      Hi William,

      Are you asking about the item which is managed by ‘Batches’ and having Valuation method as ‘Standard’ and then you would like to update the Item Cost?

      If that is the case, you can use the following sample code:

      SAPbobsCOM.MaterialRevaluation oMaterialRevaluation = default(SAPbobsCOM.MaterialRevaluation);
      oMaterialRevaluation = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oMaterialRevaluation);
      oMaterialRevaluation.DocDate = System.DateTime.Now;
      oMaterialRevaluation.RevalType = "P";
      oMaterialRevaluation.Comments = "Added through DIAPI";
      oMaterialRevaluation.Lines.ItemCode = "BATCHITEM2";
      oMaterialRevaluation.Lines.WarehouseCode = "01";
      oMaterialRevaluation.Lines.Price = 30;
      int RetVal = oMaterialRevaluation.Add();

      Kind regards,

      ANKIT CHAUHAN

      SAP SME Support

      Author's profile photo William Grant
      William Grant

      Hi Ankit,

      The last code example you shared is what I needed. Thanks for the help.

      Regards,

       

      William

      Author's profile photo Luiis Alberto Rodríguez
      Luiis Alberto Rodríguez

      Hi Ankit,

      I've tried that code but I´m getting: Invalid row number on this line:  oFIFOLayers.LayerID = oMRVFIFO.Layers.Item(0).LayerID;

      Could you help me? This is the complete code

      try
      {
      SAPbobsCOM.MaterialRevaluation oMaterialRevaluation = (SAPbobsCOM.MaterialRevaluation)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oMaterialRevaluation);
      SAPbobsCOM.MaterialRevaluation_lines oMaterialRevaluationLines = oMaterialRevaluation.Lines;
      SAPbobsCOM.FIFOLayers oFIFOLayers = oMaterialRevaluationLines.FIFOLayers;
      SAPbobsCOM.CompanyService oCompanyService = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
      SAPbobsCOM.MaterialRevaluationFIFOService oMRVFIFOService = (SAPbobsCOM.MaterialRevaluationFIFOService)oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.MaterialRevaluationFIFOService);
      SAPbobsCOM.MaterialRevaluationFIFOParams oMRVFIFOParam = (SAPbobsCOM.MaterialRevaluationFIFOParams)oMRVFIFOService.GetDataInterface(SAPbobsCOM.MaterialRevaluationFIFOServiceDataInterfaces.mrfifosMaterialRevaluationFIFOParams);
      SAPbobsCOM.MaterialRevaluationFIFO oMRVFIFO;

      oMaterialRevaluation.DocDate = DateTime.Now;
      oMaterialRevaluation.RevalType = "P";
      oMaterialRevaluationLines.SetCurrentLine(0);
      oMaterialRevaluationLines.ItemCode = "502701";
      oMaterialRevaluation.Lines.WarehouseCode = "1037";
      oMRVFIFOParam.ItemCode = "502701";
      oMRVFIFOParam.LocationCode = "01";
      oMRVFIFOParam.LocationType = "64";
      oMRVFIFOParam.ShowIssuedLayers = SAPbobsCOM.BoYesNoEnum.tNO;
      oMRVFIFO = oMRVFIFOService.GetMaterialRevaluationFIFO(oMRVFIFOParam);
      oFIFOLayers.LayerID = oMRVFIFO.Layers.Item(0).LayerID;
      oFIFOLayers.TransactionSequenceNum = oMRVFIFO.Layers.Item(0).TransactionSequenceNum;
      oFIFOLayers.Price = 60;

      int LayerNum = oMRVFIFO.Layers.Count;
      Console.WriteLine(LayerNum);

      for (int i = 1; i < LayerNum; ++i)
      {
      oFIFOLayers.Add();
      oFIFOLayers.SetCurrentLine(i);
      oFIFOLayers.LayerID = oMRVFIFO.Layers.Item(i).LayerID;
      oFIFOLayers.TransactionSequenceNum = oMRVFIFO.Layers.Item(i).TransactionSequenceNum;
      oFIFOLayers.Price = 60;
      }
      int Add = oMaterialRevaluation.Add();
      Console.WriteLine("Operación exitosa Se creó la revalorización - " + oCompany.GetNewObjectKey());
      }

      catch (Exception er)
      {
      Console.WriteLine(er.ToString());
      }

       

      Thanks in advance