cancel
Showing results for 
Search instead for 
Did you mean: 

Purchase Order

Former Member
0 Kudos

Hi All,

How to add purchase order using code (not using object-id of PO form)

1.I want to create Purchase order dynamically.

I tried with following code


Dim RetVal As Long
        Dim ErrCode As Long
        Dim ErrMsg As String
        'Create the Documents object 
        Dim vPurchaseOrder As SAPbobsCOM.Documents
        vPurchaseOrder = objMain.objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)
        'Set values to the fields 
        'vPurchaseOrder.Series = 0
        vPurchaseOrder.Series = 0
        vPurchaseOrder.CardCode = "BP234"
        vPurchaseOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
        vPurchaseOrder.PaymentGroupCode = "-1"
        vPurchaseOrder.DocDate = DateTime.Today
        vPurchaseOrder.DocTotal = 264.6
        'Invoice Lines - Set values to the first line 
        vPurchaseOrder.Lines.ItemCode = "A00023"
        vPurchaseOrder.Lines.ItemDescription = "Banana"
        vPurchaseOrder.Lines.PriceAfterVAT = 2.36
        vPurchaseOrder.Lines.Quantity = 50
        vPurchaseOrder.Lines.Currency = "Eur"
        vPurchaseOrder.Lines.DiscountPercent = 10
        'Invoice Lines - Set values to the second line 
        vPurchaseOrder.Lines.Add()
        vPurchaseOrder.Lines.ItemCode = " A00033"
        vPurchaseOrder.Lines.ItemDescription = "Orange"
        vPurchaseOrder.Lines.PriceAfterVAT = 118
        vPurchaseOrder.Lines.Quantity = 1
        vPurchaseOrder.Lines.Currency = "Eur"
        vPurchaseOrder.Lines.DiscountPercent = 10
        vPurchaseOrder.Lines.Add()
        vPurchaseOrder.Lines.ItemCode = " A00034"
        vPurchaseOrder.Lines.ItemDescription = "mangoOrange"
        vPurchaseOrder.Lines.PriceAfterVAT = 118
        vPurchaseOrder.Lines.Quantity = 1
        vPurchaseOrder.Lines.Currency = "Eur"
        vPurchaseOrder.Lines.DiscountPercent = 10
 
 
        'Add the Invoice 
        RetVal = vPurchaseOrder.Add
        'Check the result 
        If RetVal  0 Then
            'objMain.objCompany.GetLastError(ErrCode, ErrMsg)
            MsgBox(ErrCode & " " & ErrMsg)
        End If

This code shows error

Datasource no data fond...!!!

Here directly im assigning values . How we can assign datssource to this code

by

Firos

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

please find my comments in your code


Dim RetVal As Long
        Dim ErrCode As Long
        Dim ErrMsg As String
        'Create the Documents object 
        Dim vPurchaseOrder As SAPbobsCOM.Documents
        vPurchaseOrder = objMain.objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)
        'Set values to the fields 
'J: Not need or you sould read a correct value from ONNM and NNM1 tables.
' vPurchaseOrder.Series = 0 
        vPurchaseOrder.CardCode = "BP234"
        vPurchaseOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
' Automatic, populated by BP master data vPurchaseOrder.PaymentGroupCode = "-1"
        vPurchaseOrder.DocDate = DateTime.Today
' Filled by DI API, not needed vPurchaseOrder.DocTotal = 264.6
        'Invoice Lines - Set values to the first line 
        vPurchaseOrder.Lines.ItemCode = "A00023"
' Filled by DI API, not needed , but if you give a different name necessary  vPurchaseOrder.Lines.ItemDescription = "Banana"
' Filled by DI API, not needed vPurchaseOrder.Lines.PriceAfterVAT = 2.36
'Use UnitPrice or Price up to the Customizing. Pure 2007 version apply UnitPrice upgarded from prevoius versions check document settings
vPurchaseOrder.Lines.UnitPrice =  2.36
        vPurchaseOrder.Lines.Quantity = 50
' Filled by DI API, not needed  should be defined in header level   vPurchaseOrder.Lines.Currency = "Eur"
        vPurchaseOrder.Lines.DiscountPercent = 10
        'Invoice Lines - Set values to the second line 
        vPurchaseOrder.Lines.Add()
'missing
vPurchaseOrder.SetCurrentLine(1)
        vPurchaseOrder.Lines.ItemCode = " A00033"
        vPurchaseOrder.Lines.ItemDescription = "Orange"
        'Filled by DI API, not needed vPurchaseOrder.Lines.PriceAfterVAT = 118
        vPurchaseOrder.Lines.Quantity = 1
        vPurchaseOrder.Lines.Currency = "Eur"
'Use UnitPrice or Price up to the Customizing. Pure 2007 version apply UnitPrice upgarded from prevoius versions check document settings vPurchaseOrder.Lines.UnitPrice = 118
        vPurchaseOrder.Lines.DiscountPercent = 10
        'Add the Invoice 
        RetVal = vPurchaseOrder.Add
        'Check the result 
        If RetVal  0 Then
            'objMain.objCompany.GetLastError(ErrCode, ErrMsg)
            MsgBox(ErrCode & " " & ErrMsg)
        End If

Regards

János

Former Member
0 Kudos

Hello, i will try...ur code

by Firos

Former Member
0 Kudos

Hi,I tried ur code it is not working. No error but not creating any purchase order.

By

Firos

Former Member
0 Kudos

If there is no error, the PO should be created.

Check you system

regards,

János

Former Member
0 Kudos

Hi, nagy

I tried . code is executing properly retuning - datasource not found.

By

Firos

Former Member
0 Kudos

Hi,Nagy

getting error on Setcurrent line

error is "Public member 'SetCurrentLine' on type 'IDocuments' not found"

By

Firos

Former Member
0 Kudos

Hello

Mistake inside, sorry. The Correct Is: Document.Lines.SetCurrentLine()


Dim RetVal As Long
        Dim ErrCode As Long
        Dim ErrMsg As String
        Dim vPurchaseOrder As SAPbobsCOM.Documents
        vPurchaseOrder = objMain.objCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)
        vPurchaseOrder.CardCode = "BP234"
        vPurchaseOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
        vPurchaseOrder.DocDate = DateTime.Today
        vPurchaseOrder.Lines.ItemCode = "A00023"
        vPurchaseOrder.Lines.UnitPrice =  2.36
        vPurchaseOrder.Lines.Quantity = 50
        vPurchaseOrder.Lines.DiscountPercent = 10
        vPurchaseOrder.Lines.Add()
        vPurchaseOrder.Lines.SetCurrentLine(1)
        vPurchaseOrder.Lines.ItemCode = " A00033"
        vPurchaseOrder.Lines.ItemDescription = "Orange"
        vPurchaseOrder.Lines.Quantity = 1
        vPurchaseOrder.Lines.UnitPrice = 118
        vPurchaseOrder.Lines.DiscountPercent = 10
        'Add the Invoice 
        RetVal = vPurchaseOrder.Add
        'Check the result 
        If RetVal  0 Then
            'objMain.objCompany.GetLastError(ErrCode, ErrMsg)
            MsgBox(ErrCode & " " & ErrMsg)
        End If

Regards,

J.

Former Member
0 Kudos

Thx 4 ur reply...

vPurchaseOrder.Lines.SetCurrentLine(1) want replace with Document.Lines.SetCurrentLine()

I got confuse...

Document is not available in code library how we can acess document ?

By

Firos

Former Member
0 Kudos

I ment document object Lines.SetCurrentLine.

If you see the code,. inside it is ok.

Former Member
0 Kudos

hi,

Now it is showing error "Datasource not found(-2028 this error code)"

By

Firos

Edited by: firos.Cherukad on Nov 25, 2009 5:46 PM

Former Member
0 Kudos

Check Business Partner and Item codes are really exists?

Regards

J.

Former Member
0 Kudos

Thanks nagy

No. That business partner doesnt exist in database. I will try with existing code and reply

By

Firos.C

Former Member
0 Kudos

Thanks nagy...

U suggested me exact reason.

I solved problem.Take ur 10 points...

By

Firos.C

Answers (1)

Answers (1)

Former Member
0 Kudos

The value of series is 0.Chek if this value is correct.

Former Member
0 Kudos

Hi,Dilip

Series means DocEntry or not ..?

By

Firos