Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem updating line items in an Order

Hi, can you please help me understand why this code isn't working?

        public int UpdateOrder(oOrder oOrder)
        {
            int docEntry = GetDocEntryFromDocNum("ORDR", oOrder.DocNum);

            sapOrder = ((SAPbobsCOM.Documents)(sapCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)));
            sapOrder.GetByKey(docEntry);

            // Add fields for whats required
            sapOrder.DocDate = oOrder.DocDate;
            sapOrder.DocDueDate = oOrder.DocDueDate;

            bool firstLineItemAdded = false;
            int lineNum = 0;

            foreach (oOrderLineItem oOrderLineItem in oOrder.DocumentLines)
            {
                if (firstLineItemAdded)
                {
                    sapOrder.Lines.Add();
                }

                sapOrder.Lines.SetCurrentLine(lineNum);

                sapOrder.Lines.ItemCode = oOrderLineItem.ItemCode;
                sapOrder.Lines.ItemDescription = oOrderLineItem.ItemDescription;
                sapOrder.Lines.Quantity = oOrderLineItem.Quantity;

                if (!firstLineItemAdded)
                {
                    firstLineItemAdded = true;
                }

                lineNum++;
            }

            lRetCode = sapOrder.Update();

            if (lRetCode != 0)
            {
                sapCompany.GetLastError(out lErrCode, out sErrMsg);
            }

            return lRetCode;
        }

This code generates this error:

"Item no. is missing [RDR6.InsTotalSy][line: 1]"

That is error -5002

If I comment out this code, the update on the ORDR table data works fine. I comment this out:

            bool firstLineItemAdded = false;
            int lineNum = 0;

            foreach (oOrderLineItem oOrderLineItem in oOrder.DocumentLines)
            {
                if (firstLineItemAdded)
                {
                    sapOrder.Lines.Add();
                }

                sapOrder.Lines.SetCurrentLine(lineNum);

                sapOrder.Lines.ItemCode = oOrderLineItem.ItemCode;
                sapOrder.Lines.ItemDescription = oOrderLineItem.ItemDescription;
                sapOrder.Lines.Quantity = oOrderLineItem.Quantity;

                if (!firstLineItemAdded)
                {
                    firstLineItemAdded = true;
                }

                lineNum++;
            }

These are the definitions for the oOrder and oOrderLineItem objects:

    public class oOrder
    {
        public int DocNum { get; set; }
        public string CardCode { get; set; }
        public string CardName { get; set; }
        public DateTime DocDate { get; set; }
        public DateTime DocDueDate { get; set; }
        public int CntctCode { get; set; }
        public ArrayList DocumentLines { get; set; }

        public oOrder()
        {
            this.DocumentLines = new ArrayList();
        }
    }

    public class oOrderLineItem
    {
        public int LineNum { get; set; }
        public string ItemCode { get; set; }
        public string ItemDescription { get; set; }
        public double Price { get; set; }
        public double Quantity { get; set; }
        public string WhsCode { get; set; }
        public string Project { get; set; }
    }

Please let me know what may be wrong here.

Thank you,

Mike

Not what you were looking for? View more on this topic or Ask a question