cancel
Showing results for 
Search instead for 
Did you mean: 

Stock Transfer posting through DIAPI for multi-branch enabled database in SAP B1

Former Member
0 Kudos
Receipt from production is not posting inventory transfer for multiple item in multi branch database using DI/API code.Please help me out from this issue. The function for posting is following:

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;
                Double qty = 0;
                string BplId = string.Empty;
                string Branch = string.Empty;
                string seriess = string.Empty;
                string batchSer = string.Empty;
                string oErrorMsg = String.Empty;
                DataTable dt = new DataTable();
                DataTable dtBin = new DataTable();
                string postDT;
                int oErrorCode = 0;
               SAPbobsCOM.StockTransfer transfer = (SAPbobsCOM.StockTransfer)Utilities.Application.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);
                string docNum = ((SAPbouiCOM.EditText)Form.Items.Item("7").Specific).Value;
                postDT = ((SAPbouiCOM.EditText)Form.Items.Item("9").Specific).Value; ;
                Branch = ((SAPbouiCOM.EditText)Form.Items.Item("1320000092").Specific).Value.ToString().Trim();
                string _sql1;
                _sql1 = @"select BPLId from OBPL where BPLName='" + Branch + "'";
                Utilities.ExecuteSQL(ref _recordset2, _sql1);
                BplId = Convert.ToString(_recordset2.Fields.Item(0).Value);
                
                _sql1 = @"EXEC ChkBranch '" + BplId + "'";
                Utilities.ExecuteSQL(ref _recordset2,_sql1);
                string BranchWH = _recordset2.Fields.Item(0).Value;
                    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("9").Cells.Item(i).Specific).Value.ToString().Trim());
                                    parentWhs = ((SAPbouiCOM.EditText)_mtMatrix.Columns.Item("15").Cells.Item(i).Specific).Value.ToString().Trim();
                                    if (BranchWH == "process")
                                    {
                                        _sql = @"EXEC GETQCWHS '" + itmCd + "','OIGNPRD'";
                                        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.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() + "','OIGNPRD'";
                                    dt = Utilities.ExecuteDataSet(_sql).Tables[0];
                                    if (dt.Rows.Count > 0)
                                    {
                                        int ctr = 0;
                                        foreach (DataRow Row in dt.Rows)
                                        {
                                            batchSer = Row["BatchSer"].ToString();
                                            itemCode = Row["ITEMCODE"].ToString();
                                            document = Row["DOCUMENT"].ToString();
                                            docEntry = Row["DOCENTRY"].ToString();
                                            qty = Convert.ToDouble(Row["QUANTITY"]);


                                            if (IsBatchManaged(itmCd))
                                            {
                                                transfer.Lines.BatchNumbers.SetCurrentLine(ctr);
                                                transfer.Lines.BatchNumbers.BatchNumber = batchSer;
                                                transfer.Lines.BatchNumbers.Quantity = qty;
                                                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++;


                                        }
                                        //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 of matrix loop
                    }
                //}
                //else if (string.IsNullOrEmpty(BranchWH))
                //{
                //    Utilities.ShowErrorMessage("QC warehouse is not defined for the document branch.");
                //    return false;
                //}
            }


            catch (Exception ex)
            {
                Utilities.ShowErrorMessage(ex.Message);
                return false;
            }
            return true;
        }

The error occured as :

Cannot add transaction; numbering series assigned to another branch [OWTR.Series]

Please provide the solution ASAP.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member185682
Active Contributor
0 Kudos

Hi Yogeshwar,

The source warehouse and destination warehouse are warehouses from the same branch?

It's not possible to do inventory transfer between warehouses from diferents branches. In this case you should do sale document from the origin branch and a purchase document on the destination branch.

Hope it helps.

Kind Regards,

Diego Lother

Former Member
0 Kudos

Dear Diego,

The source warehouse and destination warehouse are warehouses from the same branch.

But still the issue remains same. Please check the above code and do let me know if any correction required.

Can you please provide the sample code for posting Inventory transfer in multi-branch enabled database.