cancel
Showing results for 
Search instead for 
Did you mean: 

Document Delivery (Note) based on existing open order (-2010 "Internal Error")

Former Member
0 Kudos
134

Dear experts,

I'm using the DI API version 9.0 on a SAP 9.0.

I'm trying to add a new document delivery based on an open order which contains multiple rows.

On addition attempt I receive the following error: Internal Error (-2010) occured.

The problem occurs only when the document delivery contains multiple lines, i.e, more than 1 line.

Code sample:


try

{

     // Header

     oDocument                            = oCompany.GetBusinessObject(BoObjectTypes.oDeliveryNotes) as Documents;    

     oDocument.DocNum              = 12345;

     oDocument.CardCode            = "CUSTOMER123";

     oDocument.SalesPersonCode = -1;

     oDocument.DocType              = BoDocumentTypes.dDocument_Items;

     oDocument.Comments           = "Test insertion";                              

     oDocument.DiscountPercent   = 0.0;                  

     oDocument.PickRemark         = "Test insertion for pickup remark";                                  

     oDocument.Confirmed            = BoYesNoEnum.tYES; 

     // Lines

     foreach (ODocumentDeliveryDetails line in DocumentDeliveryDetailsList)

     {

          oDocument.Lines.SetCurrentLine(line.LineNumber);

          oDocument.Lines.ItemCode             = line.ItemCode;

          oDocument.Lines.Quantity               = line.Quantity;

          oDocument.Lines.LineType              = BoDocLineType.dlt_Regular;

          oDocument.Lines.DiscountPercent   = 0.0;                                                                          

          oDocument.Lines.UnitPrice              = line.UnitPrice;

          oDocument.Lines.Price                    = line.LinePrice;

          oDocument.Lines.SalesPersonCode = -1;

          oDocument.Lines.WarehouseCode   = "01";


          if (DocumentDeliveryHeader.BaseNumber > 0)

          {   // Optional

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

               oDocument.Lines.BaseEntry = DocumentDeliveryHeader.BaseNumber;

               oDocument.Lines.BaseLine   = line.LineNumber;

          }

          // Add line

          oDocument.Lines.Add();

     }

     // Add document delivery

     int addResult  = oDocument.Add();

     if (addResult != 0)

     {

          MessageBox.Show("Error occurred");

     }

}

catch (Exception ex)

{

     MessageBox.Show("Error occurred");

}

I can't seem to find an explanation to the problem.

Would be more than glad to have your assistance.

Kind regards,

View Entire Topic
pedro_magueija
Active Contributor
0 Kudos

Hi Barak,

Is oDocument.Lines.SetCurrentLine(line.LineNumber); zero based? Is should be since oDocument.Lines.SetCurrentLine is zero based.

Also you are adding a line for each line of yours, which leaves one empty line on the last iteration. You should remove that last line.

Finally you can ask for more details on the error that occurs with Company.GetLastErrorDescription().

This contains a description of the error (80% of the times it's a useful one). Notice that you should only call it if the result of Add is not zero.


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer is helpful or correct, marking it as such is a form of saying thank you.

Former Member
0 Kudos

Hi Pedro, Thank you for the reply.

Yes, the my object's lines are zero based.

The second .Add(); is for the document it self, not the line, so as far as I can see, no extra lines are added at the last iteration.

I'm checking the error description using GetLastError method.

The error I get is, as the title says: Internal Error (-2010), so no much help there.

When I add 1 line (1 line in the DetailsList object) document is added fine, when I attempt to add 2 or more lines I get this weird error - I don't think this is "trailing line" error.

Do you have any extra thoughts?

pedro_magueija
Active Contributor
0 Kudos

Hi Or,

I've tried your code out, and even with a trailing line it seems to work just fine (I meant the oDocument.Lines.Add which will leave a trailing line on the document). side note: Thanks for that, I wasn't aware of it.

However, I tried it with fixed values. Have you tried to use fixed values and check if it works (for more than one line)?


    // Header

    var oDocument = b1.Company.GetBusinessObject(BoObjectTypes.oDeliveryNotes) as Documents;

    oDocument.CardCode = "C23900";

    oDocument.SalesPersonCode = -1;

    oDocument.DocType = BoDocumentTypes.dDocument_Items;

    oDocument.Comments = "Test insertion";

    oDocument.DiscountPercent = 0.0;

    oDocument.PickRemark = "Test insertion for pickup remark";

    oDocument.Confirmed = BoYesNoEnum.tYES;

    int lineNumber = 0;

    // Lines

    for(int i=0; i<2; i++)

    {

        oDocument.Lines.SetCurrentLine(lineNumber);

        oDocument.Lines.ItemCode = "C00001";

        oDocument.Lines.Quantity = 1;

        oDocument.Lines.LineType = BoDocLineType.dlt_Regular;

        oDocument.Lines.DiscountPercent = 0.0;

        oDocument.Lines.UnitPrice = 100;

        oDocument.Lines.Price = 100;

        oDocument.Lines.SalesPersonCode = -1;

        oDocument.Lines.WarehouseCode = "01";

        if (false)

        {   // Optional

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

            oDocument.Lines.BaseEntry = 4;

            oDocument.Lines.BaseLine = 1;

        }

        // Add line

        oDocument.Lines.Add();

        lineNumber++;

    }

    // Add document delivery

    int addResult = oDocument.Add();

    if (addResult != 0)

    {

        MessageBox.Show(b1.Company.GetLastErrorDescription());

    }

}

catch (Exception ex)

{

    MessageBox.Show(ex.ToString());

}


Pedro Magueija


LinkedIn Logo View Pedro Magueija's profile on LinkedIn
Follow @pedromagueija on Twitter

If this answer is helpful or correct, marking it as such is a form of saying thank you.

Former Member
0 Kudos

I just wrote a samll console application containing only fixed values in order to check if my original program has anything wrong with it and it has failed again with the same error: Internal Error(-2010) occured

Might be a bug in a the SAP 9.0 for multiple rows document delivery based on an existing open order?

Worth mentioning, the document delivery contains all items of the order (no missing rows in the dn).

I can't seem to upload a rar file nor a solution file, so here is the program I wrote (2 separate files)

Just create a new solution, add the SAPbobsCOM DLL version 9.0 (9.00.057) and you're all set to run the application

Program.cs


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using SAPbobsCOM;

using System.Windows.Forms;

namespace ConsoleApplication1

{

    class Program

    {

        const short  IND_SUCCESS           = 0;

        const int    IND_BASE_NUMBER       = 68;

        const int    IND_COMPANY_ID        = 4;

        const string STR_WAREHOUSE_CODE    = "01";

        const string STR_TABLE_NAME        = "ODLN";

        const string STR_COMPANY_ID_COLUMN = "U_Company_ID";

        static void Main(string[] args)

        {

            Company oCompany = new Company()

            {

                Server       = @"",

                CompanyDB    = "",

                DbUserName   = "",

                DbPassword   = "",

                UserName     = "",

                Password     = "",

                DbServerType = BoDataServerTypes.dst_MSSQL2012,

                language     = BoSuppLangs.ln_Hebrew,

                UseTrusted   = false

            };

            if (IND_SUCCESS == oCompany.Connect())

            {

                try

                {

                    short  sCurrentLine = 0;

                    string strErrorMsg  = String.Empty;

                    // Header

                    Documents oDocument       = oCompany.GetBusinessObject(BoObjectTypes.oDeliveryNotes) as Documents;

                    oDocument.DocNum          = 1996;

                    oDocument.NumAtCard       = oDocument.DocNum.ToString();

                    oDocument.DiscountPercent = 0.0;

                    oDocument.DocDueDate      = DateTime.Today.AddDays(1);

                    oDocument.Comments        = String.Format("{0} {1}", "Insertion test for test. Today is ", DateTime.Today.ToString("dd/MM/yyyy"));

                    oDocument.SalesPersonCode = -1;

                    oDocument.CardCode        = "C30000";

                    oDocument.PickRemark      = String.Format("{0} {1}", "Pick up test for test. Today is", DateTime.Today.ToString("dd/MM/yyyy"));

                    oDocument.DocType         = BoDocumentTypes.dDocument_Items;

                    if (!Utils.IsUserDefinedFieldValueValid(oDocument.UserFields, STR_COMPANY_ID_COLUMN, IND_COMPANY_ID, true, out strErrorMsg))

                    {

                        Console.WriteLine("Addition failure");

                        MessageBox.Show(String.Format("{0}: {1}", "Failed creating user defined field", strErrorMsg));

                        return;

                    }

                    // Line 1:

                    oDocument.Lines.SetCurrentLine(sCurrentLine); 

                    oDocument.Lines.ItemCode        = "C00001";

                    oDocument.Lines.Quantity        = 3.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                               

                    oDocument.Lines.UnitPrice       = 3600.000000;

                    oDocument.Lines.Price           = 3.000000 * 3600.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;  

                    }

                    oDocument.Lines.Add();

                    // Line 2:

                    oDocument.Lines.SetCurrentLine(++sCurrentLine);

                    oDocument.Lines.ItemCode        = "C00004";

                    oDocument.Lines.Quantity        = 8.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                              

                    oDocument.Lines.UnitPrice       = 315.000000;

                    oDocument.Lines.Price           = 8.000000 * 315.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;

                    }

                    oDocument.Lines.Add();

                    // Line 3:

                    oDocument.Lines.SetCurrentLine(++sCurrentLine);

                    oDocument.Lines.ItemCode        = "P10003";

                    oDocument.Lines.Quantity        = 5.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                                     

                    oDocument.Lines.UnitPrice       = 2700.000000;

                    oDocument.Lines.Price           = 5.000000 * 2700.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;

                    }

                    oDocument.Lines.Add();

                    // Line 4:

                    oDocument.Lines.SetCurrentLine(++sCurrentLine);

                    oDocument.Lines.ItemCode        = "LM4029MC";

                    oDocument.Lines.Quantity        = 6.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                                        

                    oDocument.Lines.UnitPrice       = 450.000000;

                    oDocument.Lines.Price           = 6.000000 * 450.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;

                    }

                    oDocument.Lines.Add();

                    // Line 5:

                    oDocument.Lines.SetCurrentLine(++sCurrentLine);

                    oDocument.Lines.ItemCode        = "C00002";

                    oDocument.Lines.Quantity        = 8.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                                        

                    oDocument.Lines.UnitPrice       = 2700.000000;

                    oDocument.Lines.Price           = 8.000000 * 2700.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;

                    }

                    oDocument.Lines.Add();

                    // Line 6:

                    oDocument.Lines.SetCurrentLine(++sCurrentLine);

                    oDocument.Lines.ItemCode        = "C00003";

                    oDocument.Lines.Quantity        = 12.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                                        

                    oDocument.Lines.UnitPrice       = 1170.000000;

                    oDocument.Lines.Price           = 12.000000 * 1170.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;

                    }

                    oDocument.Lines.Add();

                    // Line 7:

                    oDocument.Lines.SetCurrentLine(++sCurrentLine);

                    oDocument.Lines.ItemCode        = "C00005";

                    oDocument.Lines.Quantity        = 3.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                                        

                    oDocument.Lines.UnitPrice       = 540.000000;

                    oDocument.Lines.Price           = 3.000000 * 540.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;

                    }

                    oDocument.Lines.Add();

                    // Line 8:

                    oDocument.Lines.SetCurrentLine(++sCurrentLine);

                    oDocument.Lines.ItemCode        = "C00006";

                    oDocument.Lines.Quantity        = 2.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                                        

                    oDocument.Lines.UnitPrice       = 135.000000;

                    oDocument.Lines.Price           = 2.000000 * 135.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;

                    }

                    oDocument.Lines.Add();

                    // Line 9:

                    oDocument.Lines.SetCurrentLine(++sCurrentLine);

                    oDocument.Lines.ItemCode        = "C00007";

                    oDocument.Lines.Quantity        = 3.000000;

                    oDocument.Lines.LineType        = BoDocLineType.dlt_Regular;

                    oDocument.Lines.DiscountPercent = 0.0;                                                                                        

                    oDocument.Lines.UnitPrice       = 135.000000;

                    oDocument.Lines.Price           = 3.000000 * 4500.000000;

                    oDocument.Lines.SalesPersonCode = oDocument.SalesPersonCode;

                    oDocument.Lines.WarehouseCode   = STR_WAREHOUSE_CODE;

                    if (true)

                    {

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

                        oDocument.Lines.BaseEntry = IND_BASE_NUMBER;

                        oDocument.Lines.BaseLine  = sCurrentLine;

                    }

                    oDocument.Lines.Add();

                   

                    if (IND_SUCCESS != oDocument.Add())

                    {

                        strErrorMsg = String.Format("{0} ({1})", oCompany.GetLastErrorDescription(), oCompany.GetLastErrorCode().ToString());

                        Console.WriteLine("Addition failure");

                        MessageBox.Show(strErrorMsg);

                    }

                }

                catch (Exception ex)

                {

                    Console.WriteLine(String.Format("{0}{1}", ex.Message, Environment.NewLine));

                    MessageBox.Show(String.Format("{0}{1}", ex.Message, Environment.NewLine));

                }

                finally

                {

                    if (oCompany.Connected)

                    {

                        oCompany.Disconnect();

                    }

                }

            }

        }

    }

}

Utils.cs



using SAPbobsCOM;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

    public static class Utils

    {

        /// <summary>

        /// Determines whether given string is date

        /// </summary>

        /// <param name="str_value">String value</param>

        /// <returns>True if given string is date, otherwise false</returns>

        public static bool IsDateTime(string str_value)

        {

            DateTime value;

            return DateTime.TryParse(str_value, out value);

        }

        /// <summary>

        /// Determines whether given string is a decimal

        /// </summary>

        /// <param name="str_value">String value</param>

        /// <returns>True if given string is a decimal number, otherwise false</returns>

        public static bool IsDecimal(string str_value)

        {

            double value = -1.0;

            return Double.TryParse(str_value, out value);

        }

        /// <summary>

        /// Determines whether given value is assignable to to given field according to the field's demands.

        /// Assigns value to the field if add_if_valid is set to true

        /// </summary>

        /// <param name="fields">The fields to look for the requested field</param>

        /// <param name="field_name">The field name to look for</param>

        /// <param name="value">The value to assign to requested field</param>

        /// <param name="add_if_valid">Add value to field indicator</param>

        /// <param name="error_msg">Error description is filled if error has occurred</param>

        /// <returns>True on success, otherwise false with an output parameter of error description</returns>

        public static bool IsUserDefinedFieldValueValid(UserFields fields, string field_name, object value, bool add_if_valid, out string error_msg)

        {

            return IsUserDefinedFieldValueValid(fields, field_name, value, add_if_valid, false, out error_msg);

        }

        public static bool IsUserDefinedFieldValueValid(UserFields fields, string field_name, object value, bool add_if_valid, bool is_allow_null, out string error_msg)

        {

            try

            {

                error_msg = String.Empty;

                if (String.IsNullOrEmpty(field_name))

                {   // Field name is empty

                    error_msg = "Field name is empty.";

                    return false;

                }

                foreach (Field f in fields.Fields)

                {

                    if (f.Name.ToLower().Equals(field_name.ToLower()))

                    {

                        if (BoYesNoEnum.tYES == f.Mandatory && null == value)

                        {   // No value provided for requested mandatory field

                            error_msg = String.Format("{0} (Field Name: {1}).", "Requested value is NULL. NULL is not valid for mandatory field", f.Name);

                            return false;

                        }

                        switch (f.Type)

                        {

                            case BoFieldTypes.db_Memo:

                            case BoFieldTypes.db_Alpha:

                                if (f.Size < (null == value ? 0 : (value.ToString().Length)))

                                {   // Given value is too long

                                    error_msg = String.Format("Requested string ({0}) value is too long for requested column ({1}). Max column length is {2}", null == value ? "NULL" : value.ToString(), field_name, f.Size.ToString());

                                    return false;

                                }

                                break;

                            case BoFieldTypes.db_Date:

                                if (!Utils.IsDateTime(null == value ? String.Empty : value.ToString()))

                                {   // Given value is not a valid DateTime object

                                    error_msg = String.Format("Requested value ({0}) is not a valid Date.", null == value ? "NULL" : value.ToString());

                                    return false;

                                }

                                break;

                            case BoFieldTypes.db_Numeric:

                            case BoFieldTypes.db_Float:

                                if (BoFldSubTypes.st_Time == f.SubType)

                                {   // Sub type is of date type

                                    if (!IsDateTime(null == value ? String.Empty : value.ToString()))

                                    {   // Given value is not a valid DateTime object

                                        error_msg = String.Format("Requested value ({0}) is not a valid Date.", null == value ? "NULL" : value.ToString());

                                        return false;

                                    }

                                }

                                else if (!IsDecimal(null == value ? String.Empty : value.ToString()))

                                {   // Given value is not numeric. Does not fit to current column

                                    error_msg = String.Format("Requested value ({0}) is not a valid decimal. Requested field ({1}) requires a Decimal value.", null == value ? " NULL" : value.ToString(), field_name);

                                    return false;

                                }

                                break;

                            default:

                                // Undefined field type

                                error_msg = String.Format("Undefined value type ({0}). No value is assigned.", field_name);

                                return false;

                        }

                        if (add_if_valid)

                        {   // Value insertion is requested

                            f.Value = value;

                        }

                        // Requested value is valid for insertion in requested field

                        return true;

                    }

                }

                // Requested field is not found or not mandatory

                error_msg = String.Format("Requested field ({0}) is not found. No value is assigned.", field_name);

                return false;

            }

            catch (Exception ex)

            {

                error_msg = ex.Message;

                return false;

            }

        }

    }

}

Former Member
0 Kudos

I found the cause of the problem,

the base line number in the given details object was not correct - it wasn't the same as the actual line number of the 'parent' in the lines table. Too bad the error notation in this manner is pretty poor and only present a generic error.