cancel
Showing results for 
Search instead for 
Did you mean: 

SAP B1 StockTransfer API

Former Member
0 Kudos

Good Day

We are trying to do a Stock transfer through the API. It works perfectly as long as I transfer a single item. How do I transfer Multiple items through the API. I am using the following fields:

FromWarehouse, Lines.ItemCode, Lines.WarehouseCode,Lines.Quantity

I tried using Lines.SetCurrentLine and Lines.Add but none are working, If I add more than one item it will only add last item in the request.

Regards

Ruan

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,
First of all, you have to create a sql view that consists of all the items you want to transfer including its warehouseFrom, warehouseTo and Quantity.
Below code works for my DI API and I've implemented it on my web based application.
Hope this will also help you.

Public Function CreateInvTrans2(ByVal v_tmpbr As IQueryable(Of v_tmpbarcode), ByVal Wrhs As String, ByVal ToBin As String) As String
        Dim oOWTR As SAPbobsCOM.StockTransfer
        Dim tgadapter2 As New TransferGudangAdapter
        Dim angka As String
        Dim linenum As String
        Dim v_obin As v_OBIN
        Dim v_obin2 As v_OBIN
        v_obin = tgadapter2.get_Obin(ToBin).First
        Try
            oOWTR = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer)
            Dim SBO As SBOAdapter
            Dim tgadapter As New TransferGudangAdapter
            oOWTR.DocDate = DateTime.Now
            oOWTR.FromWarehouse = WhsFrom
            oOWTR.ToWarehouse = Wrhs
 
            Dim a = 0
               For Each WOR1 In v_tmpbr
                    v_obin2 = tgadapter.get_Obin(ToBin).First
                    oOWTR.Lines.ItemCode = WOR1.itemcode
                    oOWTR.Lines.FromWarehouseCode = WhsFrom
                    oOWTR.Lines.WarehouseCode = Wrhs
                    oOWTR.Lines.Quantity = WOR1.Quantity * WOR1.purpackun
                    oOWTR.Lines.Add()
                Next
 
            Dim iRetVal = oOWTR.Add
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oOWTR)
            oOWTR = Nothing
            GC.Collect()         
        Catch ex4 As Exception
            Dim msg As String
            msg = "Error : " + ex4.Message() + ""
            Return msg
        End Try
    End Function

Regards,
Marini Shen

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

Below sample is working for me:

SAPbobsCOM.StockTransfer oStockTransfer = (SAPbobsCOM.StockTransfer)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oStockTransfer);
oStockTransfer.FromWarehouse = "01";
oStockTransfer.ToWarehouse = "02";


oStockTransfer.Lines.ItemCode = "A00001";
oStockTransfer.Lines.FromWarehouseCode = "01";
oStockTransfer.Lines.WarehouseCode = "02";
oStockTransfer.Lines.Quantity = 2;


oStockTransfer.Lines.Add();
oStockTransfer.Lines.ItemCode = "A00002";
oStockTransfer.Lines.FromWarehouseCode = "01";
oStockTransfer.Lines.WarehouseCode = "02";
oStockTransfer.Lines.Quantity = 3;


int AddStockTransfer = oStockTransfer.Add();


if (AddStockTransfer != 0)
{
    MessageBox.Show(oCompany.GetLastErrorDescription());
}

Kind regards,

ANKIT CHAUHAN

SAP SME Support