Skip to Content
0
Former Member
Jul 31, 2006 at 10:04 AM

How to Add serial No in GRPO Programmatically

46 Views

Hi friends

I am faceing some problem when i'm tried to add GRPO through Programmaitically. Here is my code

oInv = CType(objSBOAPI.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes), SAPbobsCOM.Documents)

oInv.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes

oInv.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items

oInv.DocumentSubType = SAPbobsCOM.BoDocumentSubType.bod_None

oInv.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO

oInv.JournalMemo = "GRPO - " & oSNDataset.Fields.Item("U_BPCODE").Value

oInv.CardCode = Convert.ToString(oSNDataset.Fields.Item("U_BPCODE").Value)

oInv.CardName = Convert.ToString(oSNDataset.Fields.Item("U_BPNAME").Value)

oInv.DocDate = CType(oSNDataset.Fields.Item("U_DATE").Value, DateTime)

otemprecordset = CType(objSBOAPI.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset), SAPbobsCOM.Recordset)

Dim oBP As SAPbobsCOM.BusinessPartners

oBP = CType(objSBOAPI.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners), SAPbobsCOM.BusinessPartners)

If oBP.GetByKey(Convert.ToString(oSNDataset.Fields.Item("U_BPCODE").Value)) Then

If oBP.Currency = "##" Then

Else

oInv.DocCurrency = oBP.Currency

End If

End If

oInv.DiscountPercent = 0

Dim iCnt1 As Integer = 1

While iCnt1 <= oDataset.RecordCount

If iCnt1 > 1 Then

oInv.Lines.Add()

End If

Dim oItem As SAPbobsCOM.Items

Dim oTax As SAPbobsCOM.SalesTaxCodes

Dim oCrdCode As SAPbobsCOM.BusinessPartners

oCrdCode = CType(objSBOAPI.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners), SAPbobsCOM.BusinessPartners)

oTax = CType(objSBOAPI.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSalesTaxCodes), SAPbobsCOM.SalesTaxCodes)

oItem = CType(objSBOAPI.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems), SAPbobsCOM.Items)

oInv.Lines.ItemCode = Convert.ToString(oDataset.Fields.Item("U_Item").Value)

oInv.Lines.WarehouseCode = oDataset.Fields.Item("U_Whse").Value

' oInv.Lines.SetCurrentLine(iCnt1 - 1)

If Not (Convert.ToDouble(oDataset.Fields.Item("U_Qty").Value) = 0) Then

oInv.Lines.Quantity = oDataset.Fields.Item("U_Qty").Value

Else

oInv.Lines.Quantity = 1

End If

Dim strSNO As String

strSNO = Convert.ToString(oDataset.Fields.Item("U_Sno").Value)

strTemp = strSNO.Split(":"c)

Dim inty As Integer = 0

oInv.Lines.Price = Convert.ToDouble(oDataset.Fields.Item("U_Price").Value)

TaxTot = TaxTot + (Convert.ToDouble(oDataset.Fields.Item("U_Price").Value) * Convert.ToDouble(oDataset.Fields.Item("U_Qty").Value) * Convert.ToDouble(objSBOAPI.GetTaxRate(Convert.ToString(oDataset.Fields.Item("U_tax").Value))) / 100)

nTotal = nTotal + Convert.ToDouble((oDataset.Fields.Item("U_Price").Value))

oInv.DocTotal = nTotal + TaxTot

oInv.DiscountPercent = 0

Try

While inty < strTemp.Length

oInv.Lines.SerialNumbers.InternalSerialNumber = strTemp(inty)

oInv.Lines.SerialNumbers.Add()

System.Math.Min(System.Threading.Interlocked.Increment(inty), inty - 1)

End While

Catch ex As Exception

MsgBox(ex.Message)

End Try

oInv.Lines.BaseLine = iCnt1

oDataset.MoveNext()

System.Math.Min(System.Threading.Interlocked.Increment(iCnt1), iCnt1 - 1)

End While

Err = oInv.Add

If Not (Err = 0) Then

objUtility.ShowErrorMessage(objSBOAPI.oCompany.GetLastErrorDescription)

strSql = "delete from [@PP_CustrecRow] where DocEntry=(select DocEntry from [@PP_Custrec] where U_Docnum=" & aDocnum & ")"

otemprecordset.DoQuery(strSql)

strSql = "Delete from [@PP_CustRec] where U_docnum=" & aDocnum

otemprecordset.DoQuery(strSql)

Return False

Else

objUtility.ShowSuccessMessage("Successfully Completed")

nTotal = 0

TaxTot = 0

Return True

End If

Return True

Catch ex As Exception

objUtility.ShowErrorMessage(ex.Message)

strSql = "delete from [@PP_CustrecRow] where DocEntry=(select DocEntry from [@PP_Custrec] where U_Docnum=" & aDocnum & ")"

otemprecordset.DoQuery(strSql)

strSql = "Delete from [@PP_CustRec] where U_docnum=" & aDocnum

otemprecordset.DoQuery(strSql)

Return False

End Try

When i am try to add GPRO Item with Serial No the System Give " The selected Serial/Batch No quantity is greater than Open Quantity"

can any one having idea. please let me know

rgar

senthilkumar