Search code examples
hanaadd-onsapb1sap-business-one-di-api

Cannot add row without complete selection of batch/serial numbers


ERROR: (-4014) Cannot add row without complete selection of batch/serial numbers.

The default function of DI API SaveDraftToDocument() is working fine on MS SQL Database but not SAP HANA.

I am posting the Delivery document with Serial Numbers.

SAPbobsCOM.Documents oDrafts;
oDrafts = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts);
oDrafts.GetByKey(Convert.ToInt32(EditText27.Value));
var count = oDrafts.Lines.Count;
var linenum = oDrafts.Lines.LineNum;
//Validation
#region
var RsRecordCount = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
var sQryRecordCount = String.Format("Select * from \"SANTEXDBADDON\".\"@TEMPITEMDETAILS\" where \"U_DraftNo\" = '{0}'", EditText27.Value);
RsRecordCount.DoQuery(sQryRecordCount);
#endregion

if (count == RsRecordCount.RecordCount)
{
    //LINES
    string ItemCode = "", WhsCode = ""; double Quantity = 0; int index = 0;
    for (int i = 0; i < oDrafts.Lines.Count; i++)
    {
        oDrafts.Lines.SetCurrentLine(index);
        ItemCode = oDrafts.Lines.ItemCode;
        //SERIAL NUMBERS
        var RsSerial = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
        string table = "\"@TEMPSERIALS\"";
        var sQrySerial = String.Format(
            "Select \"U_ItemCode\" , \"U_DistNumber\" from \"SANTEXDBADDON\".\"@TEMPSERIALS\" where " +
            "\"U_DraftNo\" = '{0}' and \"U_ItemCode\" = '{1}'", EditText27.Value, ItemCode);
            RsSerial.DoQuery(sQrySerial);
        int serialindex = 1, lineindex = 0;
        #region
        if (RsSerial.RecordCount > 0)
        {
            while (!RsSerial.EoF)
            {
                //OSRN SERIALS
                var RsSerialOSRN = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                var sQrySerialOSRN = String.Format(
                    "Select * from OSRN where \"DistNumber\" = '{0}' and \"ItemCode\" = '{1}'"
                    , RsSerial.Fields.Item("U_DistNumber").Value.ToString(), ItemCode);
                RsSerialOSRN.DoQuery(sQrySerialOSRN);

                oDrafts.Lines.SerialNumbers.SetCurrentLine(0);

                oDrafts.Lines.SerialNumbers.BaseLineNumber = oDrafts.Lines.LineNum;

                oDrafts.Lines.SerialNumbers.SystemSerialNumber =
                    Convert.ToInt32(RsSerialOSRN.Fields.Item("SysNumber").Value.ToString());

                oDrafts.Lines.SerialNumbers.ManufacturerSerialNumber =
                    RsSerialOSRN.Fields.Item("DistNumber").Value.ToString();

                oDrafts.Lines.SerialNumbers.InternalSerialNumber =
                    RsSerialOSRN.Fields.Item("DistNumber").Value.ToString();

                oDrafts.Lines.SerialNumbers.Quantity = 1;
                
                if (RsSerial.RecordCount != serialindex)
                {
                    Application.SBO_Application.StatusBar.SetText("INTERNAL NO  " + oDrafts.Lines.SerialNumbers.InternalSerialNumber, SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
                    oDrafts.Lines.SerialNumbers.Add();
                    serialindex++;
                    lineindex++;
                }
                RsSerial.MoveNext();
            }
        }
        #endregion
        index++;
    }
    var status = oDrafts.SaveDraftToDocument();

    if (status == 0)
    {
        oDrafts.Remove();
        Application.SBO_Application.StatusBar.SetText("Delivery Posted Successfully !", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
    }
    else
    {
        int code = 0; string message = "";
        oCompany.GetLastError(out code, out message);
        Application.SBO_Application.SetStatusBarMessage(message, SAPbouiCOM.BoMessageTime.bmt_Medium, true);
    }
}`

Solution

  • The error you have posted explains the problem. You are trying to deliver products but have not included all of the serial/batch numbers.

    I don't think there's enough information to be sure where this problem happens, but here are some pointers:

    You are reading the serial numbers from a custom table. Are the values you are reading valid? For example, could another user have added them to a different order? Could the values be for a different product?

    Are you specifying the correct quantity of serial numbers? Is it possible that the item quantity on the line is more than the number of serial numbers you are adding?

    Believe the error message until you can prove it's wrong. It doesn't seem like this is a HANA issue (we use HANA extensively) it's a logical problem with the data you are providing.

    You may want to capture more debugging information to help you if you can't easily identify where the problem is.