on 10-05-2006 5:36 PM
Hey I am becoming desprate, I have asked about this before with no response which means that it must be something with my code, so here is my code in hopes that someone can find my error.
Thanks for the help...
Ok, Here is the situation:
I pull a sales order into a DataGridView.
This allows for the assigning of Serial Numbers from a UDT I created to manage serial numbers until they are ready for release.
I assign the serial numbers.
When the Delivery is to be created I flip through the rows of the DGV and pull the assosiated row from the SO to apply it and the assosiated serial number with in the Delivery.
<b>The following code works great for 1-1 copies.</b>
The problem comes when a Row has been deleted from within SAP from the SO or When the user removes a row from the DGV that they don't want copied into the Delivery.
When this is tryed I get an error stating:
"-10 :: [DLN1.WhsC ode][line: 0]. 'Item'ACC-USB-LCD-MX233 ' with system serial 2 is not in stock"
The weird thing is I don't have that item anywhere in my sales order or in the XML export from the Delivery object.
It is not even the first Item in our item table.
What I do is grab the rows from the Sales Order based on LineNum.
If a row is not needed I ignore that row in the Sales Order by its LineNum.
I was wondering if this is a SAP BUG but I have not seen anyone else with this problem and can't seem to get SAP to respond to my Support Notes.
Here's my code:
<if more info is needed please let me know, thanks>
Dim soDoc As SAPbobsCOM.Documents
Dim dnDoc As SAPbobsCOM.Documents
soDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
dnDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)
Try
Dim rsData As SAPbobsCOM.Recordset
Dim iTemp As Integer
iTemp = Integer.Parse(txtSalesOrder.Text)
rsData = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
rsData.DoQuery("Select DocEntry From ORDR where DocNum='" + iTemp.ToString + "'")
soDoc.GetByKey(Integer.Parse(rsData.Fields.Item("DocEntry").Value))
dnDoc.CardCode = soDoc.CardCode
dnDoc.Comments = "Based On Sales Order " & soDoc.DocNum & ". For Notes see Sales Order."
dnDoc.DocDate = Today
dnDoc.ContactPersonCode = soDoc.ContactPersonCode
dnDoc.DocCurrency = soDoc.DocCurrency
dnDoc.DocDueDate = Today
dnDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oDeliveryNotes
dnDoc.SalesPersonCode = soDoc.SalesPersonCode
If soDoc.DocumentsOwner > 0 Then
dnDoc.DocumentsOwner = soDoc.DocumentsOwner
End If
' For each item
' -> Check to see if Item is in stock
' -> -> If not then make sure it is ok to continue without the item
' -> Check to see if Item is Serialised
'-> -> If Item is serialised make sure there is a Serial number assisgned to it.
' -> -> If there is no serial number assigned Tell the user and stop creation
Dim count As Short
Dim items As SAPbobsCOM.Items
items = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
count = 0
While count <> dgvMat.Rows.Count
Dim lCount
lCount = 0
Do Until soDoc.Lines.LineNum = Integer.Parse(dgvMat.Rows(count).Cells("LineNum").Value.ToString)
soDoc.Lines.SetCurrentLine(lCount)
lCount += 1
Loop
' MessageBox.Show(soDoc.Lines.LineNum.ToString + " :: " + soDoc.Lines.ItemCode.ToString + " :: " + dgvMat.Rows.Count.ToString + " :: " + count.ToString)
' MessageBox.Show(dgvMat.Rows(count).Cells("ItemCode").Value.ToString)
items.GetByKey(dgvMat.Rows(count).Cells("ItemCode").Value.ToString)
If (items.InventoryItem = SAPbobsCOM.BoYesNoEnum.tNO) Or ((items.QuantityOnStock - Double.Parse(dgvMat.Rows(count).Cells("Quantity").Value.ToString)) > 0) Then
' MessageBox.Show("Got here, Starting Base line :: " + count.ToString)
dnDoc.Lines.BaseEntry = soDoc.DocEntry
dnDoc.Lines.BaseLine = soDoc.Lines.LineNum
dnDoc.Lines.Quantity = (Double.Parse(dgvMat.Rows(count).Cells("Quantity").Value.ToString))
dnDoc.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders
dnDoc.Lines.LineTotal = (soDoc.Lines.Price * (Double.Parse(dgvMat.Rows(count).Cells("Quantity").Value.ToString))) ' * (dnDoc.Lines.Quantity / soDoc.Lines.Quantity)
' dnDoc.Lines.AccountCode = soDoc.Lines.AccountCode
dnDoc.Lines.Address = soDoc.Lines.Address
dnDoc.Lines.Currency = soDoc.Lines.Currency
dnDoc.Lines.ItemCode = soDoc.Lines.ItemCode
dnDoc.Lines.ItemDescription = soDoc.Lines.ItemDescription
dnDoc.Lines.WarehouseCode = soDoc.Lines.WarehouseCode
dnDoc.Lines.TaxCode = soDoc.Lines.TaxCode
Dim qCount As Short
'Check if the item is managed by a serial number
If (items.ManageSerialNumbers = SAPbobsCOM.BoYesNoEnum.tYES) Then
qCount = 0
'Check to see if its the last item in the list
If count + 1 < dgvMat.RowCount Then
'Check to see if the following Row is the same as the current row
If dgvMat.Rows(count + 1).Cells("LineNum").Value = dgvMat.Rows(count).Cells("LineNum").Value Then
'Flip through the like rows
While dgvMat.Rows(count + 1).Cells("LineNum").Value = dgvMat.Rows(count).Cells("LineNum").Value
'For each simular Row, flip through the quantity
While qCount < dgvMat.Rows(count).Cells("Quantity").Value
'Serial Number
Try
' Adds serial Numbers
rsData.DoQuery("SELECT SysSerial FROM OSRI WHERE IntrSerial = '" + dgvMat.Rows(count).Cells("SerialNumber").Value.ToString + "'")
dnDoc.Lines.SerialNumbers.InternalSerialNumber = dgvMat.Rows(count).Cells("SerialNumber").Value.ToString
dnDoc.Lines.SerialNumbers.SystemSerialNumber = rsData.Fields.Item("SysSerial").Value.ToString
dnDoc.Lines.SerialNumbers.BaseLineNumber = soDoc.Lines.BaseLine
MessageBox.Show(soDoc.Lines.ItemCode.ToString + "::" + dgvMat.Rows(count).Cells("SerialNumber").Value.ToString + "::" + rsData.Fields.Item("SysSerial").Value.ToString)
Catch
MessageBox.Show("Error with Serial Number for Item: " + dgvMat.Rows(count).Cells("ItemCode").Value.ToString)
Exit Sub
End Try
' If dgvMat.Rows.Count - 1 <> count Then
'dnDoc.Lines.SerialNumbers.Add()
' End If
'For each Quantity greater then 1, add the extra rows of serial numbers
If qCount + 1 < dgvMat.Rows(count).Cells("Quantity").Value Then
dnDoc.Lines.SerialNumbers.Add()
End If
'Increment the row count
count += 1
'Increment the Quantity Count
qCount += 1
End While
'if out of rows then leave the while loop
If count + 1 >= dgvMat.RowCount Then
Exit While
End If
End While
End If
End If
'if Quantity has not been counted then process the serial numbers
If Not qCount > 0 Then
' For each Quantity, add a serial number
While qCount < dgvMat.Rows(count).Cells("Quantity").Value.ToString
'Serial Number
Try
' Add the serial Numbers
rsData.DoQuery("SELECT SysSerial FROM OSRI WHERE IntrSerial = '" + dgvMat.Rows(count).Cells("SerialNumber").Value.ToString + "'")
dnDoc.Lines.SerialNumbers.InternalSerialNumber = dgvMat.Rows(count).Cells("SerialNumber").Value.ToString
dnDoc.Lines.SerialNumbers.SystemSerialNumber = rsData.Fields.Item("SysSerial").Value.ToString
dnDoc.Lines.SerialNumbers.BaseLineNumber = soDoc.Lines.BaseLine
MessageBox.Show(soDoc.Lines.ItemCode.ToString + "::" + dgvMat.Rows(count).Cells("SerialNumber").Value.ToString + "::" + rsData.Fields.Item("SysSerial").Value.ToString)
Catch ex As Exception
MessageBox.Show("Error with Serial Number for Item: " + dgvMat.Rows(count).Cells("ItemCode").Value.ToString + " :: " + ex.Message)
Exit Sub
End Try
'For each Quantity greater then 1, add the extra rows of serial numbers
If qCount + 1 < dgvMat.Rows(count).Cells("Quantity").Value Then
dnDoc.Lines.SerialNumbers.Add()
End If
' For each quantity advance the row count
If qCount + 1 < dgvMat.Rows(count).Cells("Quantity").Value Then
count += 1
End If
'increment the quantity count
qCount += 1
End While
End If
Else
qCount = 0
If count + 1 < dgvMat.RowCount Then
If dgvMat.Rows(count + 1).Cells("LineNum").Value = dgvMat.Rows(count).Cells("LineNum").Value Then
While dgvMat.Rows(count + 1).Cells("LineNum").Value = dgvMat.Rows(count).Cells("LineNum").Value
While qCount < dgvMat.Rows(count).Cells("Quantity").Value
If (qCount + 1) < dgvMat.Rows(count).Cells("Quantity").Value Then
count += 1
End If
qCount += 1
End While
End While
End If
End If
If Not qCount > 0 Then
While qCount < dgvMat.Rows(count).Cells("Quantity").Value
If (qCount + 1) < dgvMat.Rows(count).Cells("Quantity").Value Then
count += 1
End If
qCount += 1
End While
End If
End If
Else
MessageBox.Show("There are not enough of item '" + dgvMat.Rows(count).Cells("ItemCode").Value.ToString + "' to fill this order.")
Exit Sub
End If
If count <> dgvMat.RowCount - 1 Then
dnDoc.Lines.Add()
End If
count += 1
End While
Dim lretvel, errcode As Long
Dim errmsg As String
Dim oDoc As SAPbobsCOM.Documents
'oDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)
' wrtiefile(dnDoc.GetAsXML)
dnDoc.SaveXML("C:Jer's FilesMusicDelivery.txt")
'MessageBox.Show("Stop Here")
' oDoc = oCompany.GetBusinessObjectFromXML("C:Jer's FilesMusicDelivery.txt", 0)
'dnDoc = oDoc
lretvel = dnDoc.Add()
If lretvel <> 0 Then
oCompany.GetLastError(errcode, errmsg)
MessageBox.Show(errcode.ToString + " :: " + errmsg)
Else
MessageBox.Show("Success")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Also is there a way to ADD serial Numbers at time of Delivery Creation with the SDK? I need to be able to do this for items that have Serial Numbers Managed on Release.
Thanks again,
Jeremy Adam
Message was edited by: Frank Moebius
...refortmatted the text for easier understanding (I suggest that you use line breaks a bit more often...) unfortunately I don't have enough time to check the issue myself right now. Sorry, Frank
The solution to this problem incase anyone else runs into it is. Within the Serial Number Object under the Delivery there is a baselineNumber field which needs to be set to the Delivery not the sales order.
dnDoc.Lines.SerialNumbers.BaseLineNumber = dnDoc.LineNum
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
7 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.