Skip to Content
avatar image
Former Member

Inventory transfer posting through DIAPI with multiple batches

Hello all,

On adding GRPO, I need automatic Inventory transfer posting through DIAPI. Sometimes it works successful but sometimes it throws the error as

"Cannot add row without complete selection of batch/serial numbers".

If I create batch through automatic batch creation option, then posting is successful. In case of manual batch creation, sometimes error throws as mentioned above.

Please resolve the issue ASAP.

 #region POST INVENTORY TRANSFER
        public bool PostInventoryTransfer(string DcEntry)
        {
            try
            {
                string itemCode = string.Empty;
                string document = string.Empty;
                string docEntry = string.Empty;
                string qcWhs = string.Empty;
                string parentWhs = string.Empty;
                string BplId,series;
                Double qty = 0;
                string batchSer = string.Empty;
                string oErrorMsg = String.Empty;
                DataTable dt = new DataTable();
                DataTable dtBin = new DataTable();
                int oErrorCode = 0;
                string BranchWH=string.Empty;
                string _sql1;
                int SERIES=0;
                if (!Utilities.Application.Company.InTransaction)
                    Utilities.Application.Company.StartTransaction();
                //_sql = @"exec GETITEMCODE '" + DcEntry.Trim() + "'";
                //Utilities.ExecuteSQL(ref _recordSet, _sql);
                //string itmCd = _recordSet.Fields.Item(0).ToString();
                SAPbobsCOM.StockTransfer transfer = (SAPbobsCOM.StockTransfer)Utilities.Application.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);
                string docNum = ((SAPbouiCOM.EditText)Form.Items.Item("8").Specific).Value;
                BplId = ((SAPbouiCOM.ComboBox)Form.Items.Item("2001").Specific).Value.ToString().Trim();


                
                _sql = @"select MltpBrnchs from OADM";
                Utilities.ExecuteSQL(ref _recordSet, _sql);
                string IsBranch = _recordSet.Fields.Item(0).Value;
                if (IsBranch.Trim() == "Y")
                {
                    _sql = @"SELECT U_IsBranch FROM [@KBR_QMCONFIG]";
                    Utilities.ExecuteSQL(ref _recordSet, _sql);
                    string BranchEnable = _recordSet.Fields.Item(0).Value;
                    if (!string.IsNullOrEmpty(BranchEnable.Trim()) && BranchEnable.Trim() == "Y")
                    {
                        _sql1 = @"EXEC ChkBranch1 '" + BplId + "'";
                        Utilities.ExecuteSQL(ref _recordset2, _sql1);
                        BranchWH = _recordset2.Fields.Item(0).Value;
                        Int32.TryParse(_recordset2.Fields.Item(1).Value, out SERIES);
                    }
                    else
                    {
                        _sql = @"SELECT U_InvTrSer FROM [@KBR_QMCONFIG1] WHERE U_Stage='GRPO'";
                        Utilities.ExecuteSQL(ref _recordSet, _sql);
                        Int32.TryParse(_recordSet.Fields.Item(0).Value, out SERIES);
                    }
                    
                }
               
                    if (_mtMatrix.VisualRowCount > 0)
                    {
                        for (int i = 1; i <= _mtMatrix.VisualRowCount; i++)
                        {
                            Double itmQty = 0;
                            string itmCd = ((SAPbouiCOM.EditText)_mtMatrix.Columns.Item("1").Cells.Item(i).Specific).Value.ToString().Trim();
                             _sql = @"select U_QCReqd from OITM where itemcode='"+itmCd+"'";
                            Utilities.ExecuteSQL(ref _recordSet, _sql);
                            string _QcReq = Convert.ToString(_recordSet.Fields.Item(0).Value);
                            if (_QcReq == "Y")
                            {
                                if (itmCd != "")
                                {
                                    itmQty = Convert.ToDouble(((SAPbouiCOM.EditText)_mtMatrix.Columns.Item("11").Cells.Item(i).Specific).Value.ToString().Trim());
                                    parentWhs = ((SAPbouiCOM.EditText)_mtMatrix.Columns.Item("24").Cells.Item(i).Specific).Value.ToString().Trim();
                                    if (string.IsNullOrEmpty(BranchWH))
                                    {
                                        _sql = @"EXEC GETQCWHS '" + itmCd.Trim() + "','GRPO'";
                                        Utilities.ExecuteSQL(ref _recordSet, _sql);
                                        if (_recordSet.RecordCount > 0)
                                        {
                                            qcWhs = Convert.ToString(_recordSet.Fields.Item(0).Value);
                                        }
                                    }
                                    else
                                    {
                                        qcWhs = BranchWH;
                                    }
                                    transfer.DocDate = DateTime.Now;
                                    transfer.FromWarehouse = parentWhs;
                                    transfer.ToWarehouse = qcWhs;


                                    transfer.Series = SERIES;


                                    transfer.Lines.SetCurrentLine(0);
                                    transfer.Lines.ItemCode = itmCd;
                                    transfer.Lines.FromWarehouseCode = parentWhs;
                                    transfer.Lines.WarehouseCode = qcWhs;
                                    transfer.Lines.Quantity = itmQty;
                                    transfer.UserFields.Fields.Item("U_PrntTrfr").Value = DcEntry;
                                    transfer.UserFields.Fields.Item("U_PrntDcNm").Value = docNum;


                                    _sql = @"exec GetPostInventoryData '" + DcEntry.Trim() + "','" + itmCd.Trim() + "','GRPO'";
                                    dt = Utilities.ExecuteDataSet(_sql).Tables[0];
                                    if (dt.Rows.Count > 0)
                                    {
                                        int ctr = 0;
                                        foreach (DataRow Row in dt.Rows)
                                        {
                                            batchSer = Row["BatchSer"].ToString();//Convert.ToString(Form.DataSources.UserDataSources.Item("BatchSer").ValueEx).Trim();
                                            itemCode = Row["ITEMCODE"].ToString();
                                            document = Row["DOCUMENT"].ToString();
                                            docEntry = Row["DOCENTRY"].ToString();
                                            // parentWhs = Row["WHARE HS CODE"].ToString();
                                            qty = Convert.ToDouble(Row["QUANTITY"]);


                                            if (IsBatchManaged(itmCd))
                                            {
                                                transfer.Lines.BatchNumbers.ManufacturerSerialNumber = batchSer;
                                                transfer.Lines.BatchNumbers.InternalSerialNumber = batchSer; 
                                                transfer.Lines.BatchNumbers.SetCurrentLine(ctr);
                                                transfer.Lines.BatchNumbers.BatchNumber = batchSer;
                                                transfer.Lines.BatchNumbers.Quantity = qty;


                                                //transfer.Lines.BatchNumbers.ManufacturerSerialNumber = batchSer;
                                                //transfer.Lines.BatchNumbers.InternalSerialNumber = batchSer;
                                                transfer.Lines.BatchNumbers.Add();
                                            }
                                            else
                                            {
                                                if (IsSerialManaged(itmCd))
                                                {
                                                    transfer.Lines.SerialNumbers.SetCurrentLine(ctr);
                                                    transfer.Lines.SerialNumbers.ManufacturerSerialNumber = batchSer;
                                                    transfer.Lines.SerialNumbers.InternalSerialNumber = batchSer;
                                                    transfer.Lines.SerialNumbers.Quantity = qty;
                                                    transfer.Lines.SerialNumbers.Add();
                                                }
                                            }
                                            _sql = @"EXEC GETBIN '" + docEntry + "','" + itemCode + "','" + parentWhs + "','" + batchSer + "','" + document + "'";
                                            dtBin = Utilities.ExecuteDataSet(_sql).Tables[0];


                                            int ctrBin = 0;
                                            if (dtBin.Rows.Count > 0)
                                            {
                                                foreach (DataRow dr in dtBin.Rows)
                                                {
                                                    transfer.Lines.BinAllocations.SetCurrentLine(ctrBin);
                                                    transfer.Lines.BinAllocations.BinActionType = SAPbobsCOM.BinActionTypeEnum.batFromWarehouse;
                                                    transfer.Lines.BinAllocations.BinAbsEntry = Convert.ToInt32(dr["BinAbs"]);
                                                    transfer.Lines.BinAllocations.Quantity = Convert.ToDouble(dr["Quantity"]);
                                                    transfer.Lines.BinAllocations.SerialAndBatchNumbersBaseLine = ctr;
                                                    transfer.Lines.BinAllocations.Add();
                                                    ctrBin++;
                                                }
                                            }
                                            ctr++;
                                            ////transfer.lines.binallocations.setcurrentline(0);
                                            ////transfer.lines.binallocations.binactiontype = sapbobscom.binactiontypeenum.batfromwarehouse;
                                            ////transfer.lines.binallocations.binabsentry = fromlocation;
                                            ////transfer.lines.binallocations.quantity = quantity;
                                            ////transfer.lines.binallocations.add();


                                            ////transfer.lines.binallocations.setcurrentline(1);
                                            ////transfer.lines.binallocations.binactiontype = sapbobscom.binactiontypeenum.battowarehouse;
                                            ////transfer.lines.binallocations.binabsentry = tolocation;
                                            ////transfer.lines.binallocations.quantity = quantity;
                                            ////transfer.lines.binallocations.add();


                                        }
                                        //end of foreach
                                    }
                                    // end of datatable if
                                    transfer.Lines.Add();


                                    int returnCode = transfer.Add();


                                    if (returnCode != 0)
                                    {
                                        // If process is in transaction, then the transaction is rolled back. 
                                        if (Utilities.Application.Company.InTransaction)
                                            Utilities.Application.Company.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);


                                        Utilities.Application.Company.GetLastError(out oErrorCode, out oErrorMsg);
                                        Utilities.ShowErrorMessage(oErrorMsg); // Showing error message


                                        return false; // Returning false 
                                    }


                                }
                            }//end qc check
                        }
                        //end of matrix loop
                    }
                    if (Utilities.Application.Company.InTransaction)
                        Utilities.Application.Company.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                //}
                //else
                //{
                //    Utilities.ShowErrorMessage("QC warehouse is not defined for the document branch.");
                //    return false;
                //}
            }


            catch (Exception ex)
            {
                Utilities.ShowErrorMessage(ex.Message);
                return false;
            }
            return true;
        }
        #endregion
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Feb 23 at 07:56 AM

    Above issue has been resolved.

    Thanks

    Add comment
    10|10000 characters needed characters exceeded