cancel
Showing results for 
Search instead for 
Did you mean: 

Internal Error (-10) when adding a delivery document

07-03-2013 8:03 PM
1228 views 2 comments Go to solution
0 Likes
Subscribe

Hello experts,

I'm trying to add a delivery document, but I'm getting the Internal Error (-10).

Here is my code:

private string CreateDelivery()

        {

            SAPbobsCOM.Company oCompany = (SAPbobsCOM.Company)Application["oCompany"];

            SAPbobsCOM.Recordset rs = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

            SAPbobsCOM.PickLists oPicklist = (SAPbobsCOM.PickLists)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPickLists);

            SAPbobsCOM.Documents oDelivery = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes);

            SAPbobsCOM.Documents oOrder = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);

            SAPbobsCOM.Items oItem = (SAPbobsCOM.Items)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);

            if (!oPicklist.GetByKey(Convert.ToInt32(TxNrPicking.Text)))

            {

                return "Picking não cadastrado";

            }

            oCompany.StartTransaction();

            string sSql = @"select TOP 1 T0.CardCode from

                            ORDR T0 WITH (NOLOCK) INNER JOIN RDR1 T1 WITH (NOLOCK) ON T1.DocEntry = T0.DocEntry

                            inner join PKL1 T2 WITH (NOLOCK) on T2.OrderEntry = T1.DocEntry and t2.OrderLine = T1.LineNum

                            WHERE T2.AbsEntry = {0} and T2.PickEntry = 0";

            rs.DoQuery(string.Format(sSql, oPicklist.AbsoluteEntry));

            string cardCode = rs.Fields.Item(0).Value;

            SAPbobsCOM.BusinessPartners oBP = (SAPbobsCOM.BusinessPartners)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);

            oBP.GetByKey(cardCode);

            oDelivery.CardCode = cardCode;

            oDelivery.DocDate = DateTime.Now;

            oDelivery.DocDueDate = DateTime.Now;

            oDelivery.SequenceCode = 35;

            for (int i = 0; i < oPicklist.Lines.Count; i++)

            {

                oPicklist.Lines.SetCurrentLine(i);

                if (oOrder.GetByKey(oPicklist.Lines.OrderEntry))

                    oDelivery.DocCurrency = oOrder.DocCurrency;

                sSql = @"SELECT T0.ItemCode, T0.CFOPCode, T0.TaxCode FROM RDR1 T0 WITH (NOLOCK) WHERE T0.DocEntry = {0} and T0.LineNum  = {1}";

                sSql = String.Format(sSql, oPicklist.Lines.OrderEntry, oPicklist.Lines.OrderRowID);

                rs.DoQuery(sSql);

                string itemCode = rs.Fields.Item(0).Value.ToString();

                string CFOPCode = rs.Fields.Item(1).Value.ToString();

                string taxCode = rs.Fields.Item(2).Value.ToString();

                oItem.GetByKey(itemCode);

                if (oDelivery.Lines.Count > 1) oDelivery.Lines.Add();

                oDelivery.Lines.SetCurrentLine(oDelivery.Lines.Count - 1);

                //Response.Write("Item: " + itemCode + "<BR>");

                //Response.Write("Pedido: " + oPicklist.Lines.OrderEntry + "<BR>");

                //Response.Write("Linha: " + oPicklist.Lines.OrderRowID + "<BR>");

                oDelivery.Lines.ItemCode = itemCode;

                oDelivery.Lines.CFOPCode = CFOPCode;

                //oDelivery.Lines.TaxCode = taxCode;

                oDelivery.Lines.Quantity = oPicklist.Lines.PickedQuantity;

                oDelivery.Lines.BaseEntry = oPicklist.Lines.OrderEntry;

                oDelivery.Lines.BaseLine = oPicklist.Lines.OrderRowID;

                oDelivery.Lines.BaseType = (int)SAPbobsCOM.BoObjectTypes.oOrders;

                if (oItem.ManageBatchNumbers == BoYesNoEnum.tYES)

                {

                    sSql = @"select U_Lote, SUM(U_Qtde) from [@SZ_ETIQUETA] WITH (NOLOCK) where U_NrPicking = {0} and U_ItemCode = '{1}' group by U_Lote";

                    sSql = String.Format(sSql, TxNrPicking.Text, itemCode);

                    rs.DoQuery(sSql);

                    int j = 0;

                    while (!rs.EoF)

                    {

                        if (!String.IsNullOrEmpty(oDelivery.Lines.BatchNumbers.BatchNumber))

                        {

                            oDelivery.Lines.BatchNumbers.Add();

                        }

                        oDelivery.Lines.BatchNumbers.BatchNumber = rs.Fields.Item(0).Value.ToString();

                        oDelivery.Lines.BatchNumbers.Quantity = Convert.ToDouble(rs.Fields.Item(1).Value);

                        rs.MoveNext();

                        j++;

                    }

                }

                else

                    if (oItem.ManageSerialNumbers == BoYesNoEnum.tYES)

                    {

                        sSql = @"select U_NrSerie from [@SZ_ETIQUETA] WITH (NOLOCK) where U_NrPicking = {0} and U_ItemCode = '{1}'";

                        sSql = String.Format(sSql, TxNrPicking.Text, itemCode);

                        rs.DoQuery(sSql);

                        while (!rs.EoF)

                        {

                            if (!String.IsNullOrEmpty(oDelivery.Lines.SerialNumbers.InternalSerialNumber))

                            {

                                oDelivery.Lines.SerialNumbers.Add();

                            }

                            oDelivery.Lines.SerialNumbers.InternalSerialNumber = rs.Fields.Item(0).Value.ToString();

                            rs.MoveNext();

                        }

                    }

            }

            if (oDelivery.Add() != 0)

            {

                if (oCompany.InTransaction)

                    oCompany.EndTransaction(BoWfTransOpt.wf_RollBack);

                return "Erro ao criar entrega: " + oCompany.GetLastErrorDescription();

            }

            string docNum = "";

            oCompany.GetNewObjectCode(out docNum);

            if (oCompany.InTransaction)

                oCompany.EndTransaction(BoWfTransOpt.wf_Commit);

            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oDelivery);

            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(rs);

            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oItem);

            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oBP);

            string sMsg = string.Format("Documento(s) de Entrega {0} gerado com sucesso", docNum);

            return sMsg;

        }

Any help will be appreciated.

Thanks,

Felipe Hosomi

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

I've found the error... actually it was on SerialNumbers. I've changed line #124 to:

                            oDelivery.Lines.SerialNumbers.SystemSerialNumber = (int)rs.Fields.Item("SysSerial").Value;

                            oDelivery.Lines.SerialNumbers.ManufacturerSerialNumber = rs.Fields.Item("SuppSerial").Value.ToString();

                            oDelivery.Lines.SerialNumbers.InternalSerialNumber = rs.Fields.Item("IntrSerial").Value.ToString();

Appreciate your help.

Thanks.

Answers (1)

Answers (1)

Former Member
0 Likes

Hi,

  

    Remove transaction  option and try. you change the order of posting with transaction if ok.

With regards,

Venki .A