cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot create a new StockTransfer object in SDK DI

Former Member
0 Kudos

I'm having a problem using the V6.7 DI SDK with VB 6.

My code loops through a collection, creating stock transfer entries in SAP BO. The User requirement is to add detail lines to the stock transfer until the from warehouse code changes after which a new stock transfer is created for all items originating from this warehouse, etc.

So I have declared a stock transfer object:

Private SAPStockTransfer As SAPbobsCOM.StockTransfer

Set SAPStockTransfer = SAPCompany.GetBusinessObject(oStockTransfer)

After which I set the appropriate properties of the stock transfer object and add the stock transfer lines as appropriate.

When the warehouse changes I firstly call the add() method of the stock transfer object then I reset the stock transfer object as follows:

Set SAPStockTransfer = Nothing

Set SAPStockTransfer = SAPCompany.GetBusinessObject(oStockTransfer)

The problem is at this stage, the SAPStockTransfer is not re-initialized, as I would have expected, but persists the previously held values.

Am I doing something wrong?

Accepted Solutions (1)

Accepted Solutions (1)

barend_morkel2
Active Contributor
0 Kudos

Hi Marinos,

Try calling the garbage collector before re-inistialising the Objects.

Try this:

Set SAPStockTransfer = Nothing

GC.Collect

Set SAPStockTransfer = SAPCompany.GetBusinessObject(oStockTransfer)

If this doesn't work try passing the parameters of the stock transfer into a procedure that will create the Stock Obj, instanciate it, do the stock transfer and the kill the stock obj

<b>

(Set SAPStockTransfer = Nothing

GC.Collect)</b>

Call this procedure for each transfer. This must work.

Answers (2)

Answers (2)

Former Member
0 Kudos

Try to use:

System.Runtime.InteropServices.Marshal.ReleaseComObject(SAPStockTransfer)

instead of:

Set SAPStockTransfer = Nothing

Hope this helps.

Dulce.

Former Member
0 Kudos

Hello Marinos,

I think there is no problem with the idea, setting the object variable into Nothing. Why don't you try to declare it as Dim SAPStockTransfer As SAPbobsCOM.StockTransfer if you are not using it globally in a module. Hope this helps...