cancel
Showing results for 
Search instead for 
Did you mean: 

Inventory transfer posting through DIAPI with multiple batches

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

hendraprakasa
Participant
0 Kudos

Please info how you solve this issue ?

how to post branch in DI API ? for stock transfer

Former Member
0 Kudos

Above issue has been resolved.

Thanks

former_member869198
Discoverer
0 Kudos

hello, can you pls help me ...i have same problem

former_member869198
Discoverer
0 Kudos

how pls tell me..?

anne-petteroe
Community Manager
Community Manager
0 Kudos

Hello Vishal,

While we're happy that you've come to SAP Community to get an answer to your question, you posted your question as an answer in an old thread. Posting in older threads is not the best way to get guidance.

If you're looking for help, you should ask a new question: https://answers.sap.com/questions/ask.html.

Here are some tips to help you craft an effective question for our community: https://community.sap.com/resources/questions-and-answers, https://developers.sap.com/tutorials/community-qa.html, https://groups.community.sap.com/t5/welcome-corner-discussions/advice-from-sap-champions-questions-a....

I encourage you to follow this guidance, as I'd really like to see you get a solution to your problem.

Kind regards,
Anne