cancel
Showing results for 
Search instead for 
Did you mean: 

Copying a document of a company A in a company B

Former Member
0 Kudos

Hi,

I'm trying to copy an orders document of one company, for example, A, into another company, for example, B. But when adding the document it gives me the error code -2028. Could someone tell me what does this error means?

The code is in VB. Here is it:


Dim oPedidoA As SAPbobsCOM.Documents
Dim oPedidoB As SAPbobsCOM.Documents
Dim lineasA As SAPbobsCOM.Document_Lines
Dim lineasB As SAPbobsCOM.Document_Lines
oPedidoA = companiaA.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
oPedidoA.GetByKey(txtCodigo.Text)
lineasA = oPedidoA.Lines
oPedidoB = companiaB.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
lineasB = oPedidoB.Lines
With oPedidoA
    oPedidoB.DocType = .DocType
    oPedidoB.CardCode = .CardCode
    oPedidoB.DocDueDate = .DocDueDate
    oPedidoB.Comments = .Comments
    Dim i, fin As Integer
    fin = lineasA.Count
    For i = 0 To (fin - 1)
        lineasA.SetCurrentLine(i)
        lineasB.SetCurrentLine(i)
        lineasB.ItemCode = lineasA.ItemCode
        lineasB.ItemDescription = lineasA.ItemDescription
        lineasB.Quantity = lineasA.Quantity
        lineasB.DiscountPercent = lineasA.DiscountPercent
        If i <> (fin - 1) Then
             lineasB.Add()
        End If
    Next
End With
Dim n As Integer
n = oPedidoB.Add()
If n <> 0 Then
   MessageBox.Show("Not introduced")
Else
   MessageBox.Show("Introduced")
End If
MessageBox.Show(n)

Thanks in advance,

Vane

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Vanesa,

Don´t really know what 2028 error means, but I see no errors in your code. Could be something about consistency with the data.

Are you sure that the BP and the items you add in the B company exist?

Regards,

Ibai Peñ

Answers (1)

Answers (1)

Former Member
0 Kudos

Try something like this


Dim oPedidoA As SAPbobsCOM.Documents
Dim oPedidoB As SAPbobsCOM.Documents

oPedidoA = companiaA.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)

oPedidoA.GetByKey(txtCodigo.Text)lineasA = 
oPedidoB = companiaB.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)lineasB = oPedidoB.Lines

oPedidoB.DocType = oPedidoA.DocType
oPedidoB.CardCode = oPedidoA.CardCode
oPedidoB.DocDueDate = oPedidoA.DocDueDate
oPedidoB.Comments = oPedidoA.Comments

For i = 0 To (fin - 1)
    if i>0 then
       oPedidoB.Lines.Add
    endif
    oPedidoA.Lines.SetCurrentLine(i)
    oPedidoB.Lines.SetCurrentLine(i)
    oPedidoB.Lines.ItemCode = oPedidoA.Lines.ItemCode
    ....
    ....
    
Next