cancel
Showing results for 
Search instead for 
Did you mean: 

Want to create a multiple Purchase Order using one file source

Former Member
0 Kudos

I'm want to create a multiple purchase order using one source file. I want to read the file source create LINES in a purchase order and when the Vendor code changes I want to Add the purchase order and then create a new purchase order and Add LINES and so on.

Right now I get Item.no is missing [POR1.ItemCode][Line 2]

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks for your help, that did the trick, everything seem to be working great now.

Former Member
0 Kudos

Here is a code sample

Private Sub testcode()

Dim strOrdplanFile As String

Dim oLineRec As SAPbobsCOM.Recordset

Dim strLine As String = ""

Dim ItemName As String

Dim Quantity As String

Dim RequiredDate As String

Dim SupplierType As String

Dim ShipTo As String

Dim Vendor As String

Dim oPurchaseOrder As SAPbobsCOM.Documents

Dim bAddPOrder As Boolean = True

Dim bPurchase As Boolean = False

Dim sSQL As String

Dim iReads As Integer = 1

Dim iCurrentPurchaseNumber As Integer = 0

Dim bErrors As Boolean = False

Dim retCode As Double

oPurchaseOrder = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)

strOrdplanFile = strFolderLocation & "ORDPLAN.TXT"

If File.Exists(strOrdplanFile) And FileLen(strOrdplanFile) > 0 Then

Dim sr As New StreamReader(strOrdplanFile)

strLine = sr.ReadLine()

txtPurRec.String = "0"

oFormStatus.Update()

Try

Do

Vendor = strLine.Substring(0, 8).Trim()

ShipTo = strLine.Substring(12, 8).Trim()

SupplierType = strLine.Substring(26, 1)

ItemName = strLine.Substring(27, 20).Trim()

Quantity = strLine.Substring(94, 😎

RequiredDate = strLine.Substring(206, 9)

oLineRec = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

sSQL = "SELECT PrcrmntMtd, CardCode FROM OITM WHERE ItemCode = '" & ItemName & "'"

oLineRec.DoQuery(sSQL)

If oLineRec.RecordCount() > 0 Then ' if it exists add the record

If oLineRec.Fields.Item(0).Value.ToString = "B" Then

If (bAddPOrder) Then

oPurchaseOrder.CardCode = Vendor

oPurchaseOrder.DocDueDate = RequiredDate

'Add first item to the purchase order

oPurchaseOrder.Lines.ItemCode = ItemName

oPurchaseOrder.Lines.WarehouseCode = ShipTo

oPurchaseOrder.Lines.Quantity = CDbl(Quantity)

oPurchaseOrder.Lines.Add()

bAddPOrder = False

bPurchase = True

iCurrentPurchaseNumber = iCurrentPurchaseNumber + 1

txtPurRec.String = "R: " & iReads & " W: " & iCurrentPurchaseNumber.ToString

oFormStatus.Update()

Else

'compare CardCode to make sure Vendor hasn't change

If (oPurchaseOrder.CardCode.CompareTo(Vendor) = 0) Then

'Add item to the purchase order

oPurchaseOrder.Lines.ItemCode = ItemName

oPurchaseOrder.Lines.WarehouseCode = ShipTo

oPurchaseOrder.Lines.Quantity = CDbl(Quantity)

oPurchaseOrder.Lines.Add()

Else

'vender code changed

retCode = oPurchaseOrder.Add()

If (retCode <> 0) Then

SBO_Application.MessageBox(oCompany.GetLastErrorDescription(), 1, "OK", "", "")

End If

oPurchaseOrder.CardCode = Vendor

oPurchaseOrder.DocDueDate = RequiredDate

'Add first item to the purchase order

oPurchaseOrder.Lines.ItemCode = ItemName

oPurchaseOrder.Lines.WarehouseCode = ShipTo

oPurchaseOrder.Lines.Quantity = CDbl(Quantity)

oPurchaseOrder.Lines.Add()

bAddPOrder = False

bPurchase = True

iCurrentPurchaseNumber = iCurrentPurchaseNumber + 1

txtPurRec.String = "R: " & iReads & " W: " & iCurrentPurchaseNumber.ToString

oFormStatus.Update()

End If

iReads = iReads + 1

End If 'new

strLine = sr.ReadLine()

End If

End If

Loop Until sr.EndOfStream

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Information)

End Try

If (bPurchase) Then

lRetCode = oPurchaseOrder.Add()

End If

sr.Close()

swLogFile.WriteLine("Purchase orders stored : " & iCurrentPurchaseNumber)

oPurchaseOrder = Nothing

End If

End Sub

former_member201110
Active Contributor
0 Kudos

Hi Tom,

The reason you are getting the Item Missing error is that the first line of any marketing document is automatically generated for you so you don't need to call the Lines.Add() method until you are adding the second line. Also, the Line.Add() method is called before you populate the properties of the new line. So something like:

Dim iLineNum as Integer = 0

If iLineNum > 0 then
	oPurchaseOrder.Lines.Add()
	oPurchaseOrder.SetCurrentLine(iLineNum)
End if
iLineNum++
oPurchaseOrder.Lines.ItemCode = ItemName
oPurchaseOrder.Lines.WarehouseCode = ShipTo
oPurchaseOrder.Lines.Quantity = CDbl(Quantity)

You'll then need to reset iLineNum to 0 when the vendor code changes and you want to create a new PO.

Kind Regards,

Owen

former_member201110
Active Contributor
0 Kudos

Hi Tom,

What is your source file? The various XML schemas for SBO will allow you to load multiple POs from the same XML file. The Company object in the DI API has two methods called GetBusinessObjectFromXML and GetXMLelementCount. These can be used to loop through the data in the XML file, loading each PO in to a separate Documents object and adding it to SBO. Of course, your source file must comply with one of the SBO schemas for POs.

If XML is not the way you want to go, perhaps you could post a code sample so others can try and spot the problem.

Kind Regards,

Owen