Skip to Content
author's profile photo
Former Member

DI: Replication of Item Object

Hi all,

I want to create new Item based on existing Item in the database. Of course the new Item has unique ItemCode and many others fields (for example, I have main item and its variants with differences in UDF's).

My code:

Dim oItem As SAPbobsCOM.Items

Dim oMainItem As SAPbobsCOM.Items

Set oItem = oCompany.GetBusinessObject(oItems)

Set oMainItem = oCompany.GetBusinessObject(oItems)

oMainItem.GetByKey (sMainCode)

Set oItem = oMainItem

oItem.ItemCode = sCode

oItem.ItemName = sName

oItem.UserFields.Fields.Item("U_farbe").Value = ColorName

oItem.UserFields.Fields.Item("U_hauptArt").Value = ArtikelNr

oItem.UserFields.Fields.Item("U_artNr").Value = FedasCode

If oItem.Add <> 0 Then

oCompany.GetLastError ErrCode, ErrMsg

MsgBox ErrCode & " " & ErrMsg

End If

Method Add() always returns this error:

"-5002 Invalid Code [OITW.WhsCode] , 'Main_45_sjdgj '"

Can anyone help?


Libor Mego.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • author's profile photo
    Former Member
    Jul 13, 2004 at 05:19 AM


    In your code - the line <i>Set oItem = oMainItem</i> means you're pointing to the same instance with two objects. You cannot use this coding in order to "copy" Items.

    Since the is an auto-complete module,

    You can copy the data inside the properties.

    copy only the desired data and then add the <b>new</b> item.


    oItem.Manufacturer = oMainItem.Manufacturer

    oItem.PriceList = oMainItem.PriceList


    Yaniv G.

    SDK Consultant,

    SAP Manage Israel.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Jul 13, 2004 at 09:25 AM

    Hi Yaniv,

    thanks for your reply.

    But, when I need my new Item with the same data in the fields like my Main Item, with differences only in ItemCode, ItemName and a few UDF, should I make it manually? For Example my code:

    oItem.AssetItem = oMainItem.AssetItem

    oItem.AvgStdPrice = oMainItem.AvgStdPrice

    oItem.BarCode = oMainItem.BarCode

    oItem.CommissionGroup = oMainItem.CommissionGroup

    oItem.CommissionPercent = oMainItem.CommissionPercent

    oItem.CommissionSum = oMainItem.CommissionSum

    oItem.CustomsGroupCode = oMainItem.CustomsGroupCode

    oItem.DataExportCode = oMainItem.DataExportCode

    oItem.DefaultWarehouse = oMainItem.DefaultWarehouse

    oItem.DesiredInventory = oMainItem.DesiredInventory

    oItem.ECExpensesAccount = oMainItem.ECExpensesAccount

    oItem.ECRevenuesAccount = oMainItem.ECRevenuesAccount

    oItem.ExemptIncomeAccount = oMainItem.ExemptIncomeAccount

    oItem.ExpanseAccount = oMainItem.ExpanseAccount

    oItem.ForceSelectionOfSerialNumber = oMainItem.ForceSelectionOfSerialNumber

    oItem.ForeignExpensesAccount = oMainItem.ForeignExpensesAccount

    oItem.ForeignName = oMainItem.ForeignName

    oItem.ForeignRevenuesAccount = oMainItem.ForeignRevenuesAccount

    oItem.Frozen = oMainItem.Frozen

    oItem.FrozenFrom = oMainItem.FrozenFrom

    oItem.FrozenRemarks = oMainItem.FrozenRemarks

    oItem.FrozenTo = oMainItem.FrozenTo

    oItem.GLMethod = oMainItem.GLMethod


    There are too many fields. And what happend, when in next version of SBO or SDK for example new fields or new business objects comes or field-names will change?

    Thanks for reply.


    Libor Mego.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      One feature that I would like to see, that would help toward a solution would be the abilities to access properties with text names and the ability to iterate over the properties.

      Perhaps the code might look like this:

      for each sProp in oMainItem.Properties

      oNewItem.Properties(sProp) = oMainItem.Properties(sProp)

      next sProp

      I would like the properties to be referenced via strings so that I could allow the user to create configuration lists of properties that they want to use, perhaps in an export.

      We already have a similar capability for user fields.

  • author's profile photo
    Former Member
    Jul 27, 2004 at 02:40 PM

    Hi all,

    I have found some solution of this problem, but isn't very nice :o)

    Dim oItem As SAPbobsCOM.Items

    Dim oMainItem As SAPbobsCOM.Items

    dim lPriceList, lWhsInfo as Long

    Set oItem = oCompany.GetBusinessObject(oItems)

    Set oMainItem = oCompany.GetBusinessObject(oItems)

    oMainItem.GetByKey (sMainCode)

    '// first copy PriceList info

    For lPriceList = 0 To oMainItem.PriceList.count - 1

    oMainItem.PriceList.SetCurrentLine (lPriceList)

    oItem.PriceList.SetCurrentLine (lPriceList)

    oItem.PriceList.Currency = oMainItem.PriceList.Currency

    oItem.PriceList.Price = oMainItem.PriceList.Price

    Next lPriceList

    '// second copy Warehouse info

    For lWhsInfo = 0 To oMainItem.WhsInfo.count - 1

    oMainItem.WhsInfo.SetCurrentLine (lWhsInfo)


    oItem.WhsInfo.SetCurrentLine (lWhsInfo)

    oItem.WhsInfo.CostAccount = oMainItem.WhsInfo.CostAccount

    oItem.WhsInfo.DecreasingAccount = oMainItem.WhsInfo.DecreasingAccount

    oItem.WhsInfo.EUExpensesAccount = oMainItem.WhsInfo.EUExpensesAccount

    oItem.WhsInfo.EURevenuesAccount = oMainItem.WhsInfo.EURevenuesAccount

    oItem.WhsInfo.ExemptIncomeAcc = oMainItem.WhsInfo.ExemptIncomeAcc

    oItem.WhsInfo.ExpensesAccount = oMainItem.WhsInfo.ExpensesAccount

    oItem.WhsInfo.ForeignExpensAcc = oMainItem.WhsInfo.ForeignExpensAcc

    oItem.WhsInfo.ForeignRevenueAcc = oMainItem.WhsInfo.ForeignRevenueAcc

    oItem.WhsInfo.IncreasingAccount = oMainItem.WhsInfo.IncreasingAccount

    oItem.WhsInfo.InventoryAccount = oMainItem.WhsInfo.InventoryAccount

    oItem.WhsInfo.MaximalStock = oMainItem.WhsInfo.MaximalStock

    oItem.WhsInfo.MinimalOrder = oMainItem.WhsInfo.MinimalOrder

    oItem.WhsInfo.MinimalStock = oMainItem.WhsInfo.MinimalStock

    oItem.WhsInfo.PriceDifferenceAcc = oMainItem.WhsInfo.PriceDifferenceAcc

    oItem.WhsInfo.ReturningAccount = oMainItem.WhsInfo.ReturningAccount

    oItem.WhsInfo.RevenuesAccount = oMainItem.WhsInfo.RevenuesAccount

    oItem.WhsInfo.StandardAveragePrice = oMainItem.WhsInfo.StandardAveragePrice

    oItem.WhsInfo.TransferAccount = oMainItem.WhsInfo.TransferAccount

    oItem.WhsInfo.VarienceAccount = oMainItem.WhsInfo.VarienceAccount

    oItem.WhsInfo.WarehouseCode = oMainItem.WhsInfo.WarehouseCode

    Next lWhsInfo

    '// and at least copy all the necessary simple fields you need to replicate from MainItem to your new Item (there are lots of them)

    oItem.BarCode = oMainItem.BarCode

    oItem.AssetItem = oMainItem.AssetItem

    oItem.ItemsGroupCode = oMainItem.ItemsGroupCode

    You can see, it isn't very nice, but functional.



    Add comment
    10|10000 characters needed characters exceeded