Skip to Content
avatar image
Former Member

[SAP B1 DI API] Add Distribution Rules to [Inventory] Goods Receipts

Hi,

Im trying to create good receipts through DI API and when i use the fields COGSCostingCode,.COGSCostingCode2,.COGSCostingCode3,.COGSCostingCode4 and add the document it doesnt submit my values and saves the document with no error.

I do the same with other documents (returns, delivery both from sales and purchase) and it works!!!

im using the following code:

Dim oDoc As SAPbobsCOM.Documents
oDoc = SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry)

doc.CardCode = txtCardCode.Value.Trim
doc.Comments = txtRemarks.Value

For i = 1 To mtxLinhas.RowCount

With doc.Lines

If (.ItemCode <> "") Then .Add()

.ItemCode = FormCellEdit(ItemMatrix.LINHAS, ColunasLinhas.UID.ITEMCODE, i).Value .Quantity = SBO_Functions.FormatReadNumber(FormCellEdit(ItemMatrix.LINHAS, ColunasLinhas.UID.QUANTITY, i).Value, SBO_Company)

.WarehouseCode = FormCellEdit(ItemMatrix.LINHAS, ColunasLinhas.UID.WAREHOUSE, i).Value

.COGSCostingCode = FormCellEdit(ItemMatrix.LINHAS, ColunasLinhas.UID.DIM1, i).Value .COGSCostingCode2 = FormCellEdit(ItemMatrix.LINHAS, ColunasLinhas.UID.DIM2,i).Value

.COGSCostingCode3 = FormCellEdit(ItemMatrix.LINHAS, ColunasLinhas.UID.DIM3, i).Value

.COGSCostingCode4 = FormCellEdit(ItemMatrix.LINHAS, ColunasLinhas.UID.DIM4, i).Value

.UnitPrice = SBO_Functions.FormatReadNumber(FormCellEdit(ItemMatrix.LINHAS, ColunasLinhas.UID.PRICE, i).Value, SBO_Company)

End With

Next

doc.Add()

Thanks :)

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Mar 02, 2017 at 06:20 PM

    Hi Luis,

    The correct properties that you should use in this case is CostingCode, CostingCode2...

    A sample:

    SAPbobsCOM.Documents oDoc = oCompany.GetBusinessObject(BoObjectTypes.oInventoryGenEntry);
                    oDoc.Comments = "Teste";
    
                    oDoc.Lines.ItemCode = "PR-FN-000114-00";
                    oDoc.Lines.AccountCode = "1.01.02.01.12";
                    oDoc.Lines.WarehouseCode = "001.01";
                    oDoc.Lines.CostingCode = "01-002";
                    oDoc.Lines.CostingCode2 = "ME000001";
    
                    if(oDoc.Add() != 0)
                    {
                        MessageBox.Show(oCompany.GetLastErrorDescription());
                    }
    

    Hope it helps.

    Kind Regards,

    Diego Lother

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 02, 2017 at 10:20 PM

    Luis maybe this can help, I do something like reading an xml file and it works very well.

    using System;
    using System.Data.SqlClient;
    using ConectoresBO.Conectores;

    namespace SAPBOConector.Documentos
    {
    public class oInventoryGenExit
    {
    public oInventoryGenExit(SAPbobsCOM.Documents oInventoryGenExit,
    SAPbobsCOM.Company sapCompany, Company company, int key, int index)
    {

    SQLAdapter sqlAdapter = company.Conector.SQLAdapter;

    SAPbobsCOM.Documents InventoryGenExit = (SAPbobsCOM.Documents)sapCompany
    .GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);


    int COUNT = 0;

    SqlDataReader reader = sqlAdapter.ejecutarConsulta
    ("SELECT COUNT('A') FROM " + sapCompany.CompanyDB +
    ".dbo.OIGE WHERE U_BKV_UID='" + oInventoryGenExit.UserFields.Fields.Item("U_BKV_UID").Value + "'");

    if (reader.Read())
    {
    COUNT = reader.GetInt32(0);
    }

    // sqlAdapter.cerrarConexion();
    if (COUNT == 0)
    {

    InventoryGenExit.TaxDate = oInventoryGenExit.TaxDate;
    InventoryGenExit.DocDate = oInventoryGenExit.DocDate;
    InventoryGenExit.DocDueDate = oInventoryGenExit.DocDueDate;
    InventoryGenExit.FolioNumber = oInventoryGenExit.FolioNumber;
    InventoryGenExit.Reference2 = oInventoryGenExit.Reference2;
    InventoryGenExit.Comments = oInventoryGenExit.Comments;
    InventoryGenExit.DocObjectCode = oInventoryGenExit.DocObjectCode;
    InventoryGenExit.Series = oInventoryGenExit.Series;

    sqlAdapter.cerrarConexion();

    for (int i = 0; i < oInventoryGenExit.Lines.Count; i++)
    {
    if (i != 0) InventoryGenExit.Lines.Add();
    oInventoryGenExit.Lines.SetCurrentLine(i);
    InventoryGenExit.Lines.SetCurrentLine(i);
    char[] delimiterChars = { '.' };
    string[] cantidad = oInventoryGenExit.Lines.Quantity.ToString().Split(delimiterChars);
    InventoryGenExit.Lines.ItemCode = oInventoryGenExit.Lines.ItemCode;
    InventoryGenExit.Lines.Quantity = Convert.ToDouble(cantidad[0]);
    InventoryGenExit.Lines.AccountCode = oInventoryGenExit.Lines.AccountCode;
    InventoryGenExit.Lines.WarehouseCode = oInventoryGenExit.Lines.WarehouseCode;
    InventoryGenExit.Lines.CostingCode = oInventoryGenExit.Lines.CostingCode;
    InventoryGenExit.Lines.CostingCode2 = oInventoryGenExit.Lines.CostingCode2;
    InventoryGenExit.Lines.CostingCode3 = oInventoryGenExit.Lines.CostingCode3;
    InventoryGenExit.Lines.ProjectCode = oInventoryGenExit.Lines.ProjectCode;
    InventoryGenExit.Lines.UserFields.Fields.Item("U_GW_Cliente").Value = oInventoryGenExit.Lines.UserFields.Fields.Item("U_GW_Cliente").Value;
    InventoryGenExit.Lines.UserFields.Fields.Item("U_GW_Salida").Value = oInventoryGenExit.Lines.UserFields.Fields.Item("U_GW_Salida").Value;
    InventoryGenExit.Lines.UnitPrice = oInventoryGenExit.Lines.UnitPrice;
    InventoryGenExit.Lines.Price = oInventoryGenExit.Lines.Price;
    InventoryGenExit.Lines.UseBaseUnits = SAPbobsCOM.BoYesNoEnum.tYES;



    InventoryGenExit.Lines.Add();
    }

    InventoryGenExit.Add();


    String Status = "";

    if (sapCompany.GetLastErrorCode() != 0)
    {
    Status = "Error :" + sapCompany.GetLastErrorDescription().ToString();

    }
    else
    {

    Status = "Done";


    Greetings.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 13, 2017 at 10:16 AM

    Thank you for the solution!

    Yes you are right, SAP uses 2 diferent fields for cost centers COGSCostingCode in marketing documents and CostingCode in Inventory.

    Always learning! :)

    Best Regards,

    Luís Carmo

    Add comment
    10|10000 characters needed characters exceeded