Showing results for 
Search instead for 
Did you mean: 

How to update oOrder and oInvoice Items' COGM?

Former Member
0 Kudos

I am attempting to update the COGM and Profit Margin values for Non-Stock items when an associated Purchase Invoice for these non-stock items is received. This is being done to have more accurate booked order and invoiced order reports. The code I have written is shown below. As yet, I am unable to find a way to reach the RDR1.GrossBuyPr column (labled as COGM in the UI) and INV1.GrossBuyPr column (also, COGM in the UI) from the DI API. Is there another way to update these values. Also, how would I update the Profit Margin for the respective lines?

Any help would be greatly appreciated!

    Private Sub oApplication_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles oApplication.ItemEvent

        If pVal.FormType = 141 And pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK And _
           pVal.Before_Action = False And pVal.FormUID = 1 And pVal.Action_Success = True Then

            oForm = oApplication.Forms.GetForm(pVal.ForType, pVal.FormTypeCount)

        End If

    End Sub

    Private Sub updateNonStockCOGM()

        Dim oItems As SAPbouiCOM.Items
        Dim oItem As SAPbouiCOM.Item
        Dim oEditText As SAPbouiCOM.EditText
        Dim sPI_DocNum As String
        Dim row, row2 As Integer
        Dim oPI As SAPbobsCOM.Documents
        Dim oPI_Lines As SAPbobsCOM.Document_Lines
        Dim uiPI_Item As SAPbobsCOM.Items
        Dim oPO As SAPbobsCOM.Documents
        Dim oPO_Lines As SAPbobsCOM.Document_Lines
        Dim uiPO_Item As SAPbobsCOM.Items
        Dim oSO As SAPbobsCOM.Documents
        Dim oSO_Lines As SAPbobsCOM.Document_Lines
        Dim uiSO_Item As SAPbobsCOM.Items
        Dim oSI As SAPbobsCOM.Documents
        Dim oSI_Lines As SAPbobsCOM.Document_Lines
        Dim uiSI_Item As SAPbobsCOM.Items

        ' Obtain OPCH.DocNum ... contained in Item # 8  
        oItems = oForm.Items
        oItem = oItems.Item("8")
        oEditText = oItem.Specific
        sPI_DocNum = oEditText.Value

        oPI = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices)

        If oPI.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items Then

            oPI_Lines = oPI.Lines

            For row = 0 To oPI_Lines.Count

                If uiPI_Item.InventoryItem = SAPbobsCOM.BoYesNoEnum.tNO And oPI_Lines.BaseEntry() > 0 Then
                    ' Update PO Price
                    oPO = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)
                    oPO_Lines = oPO.Lines
                    oPO_Lines.Price = oPI_Lines.Price()
                    If oPO_Lines.BaseEntry() > 0 Then
                        ' Update SO Price
                        oSO = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
                        oSO_Lines = oSO.Lines
                        oSO_Lines.Price = oPI_Lines.Price()    '<== INCORRECT!!!  NOT SURE HOW TO SET THE COST OF THE ITEM...
                        ' How do I recompute the COGM value?
                    End If
                    Dim oRecordSet As SAPbobsCOM.Recordset
                    oSI = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
                    oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                    oRecordSet.DoQuery("Select DocNum from OINV where BaseDocNum = '" & oSO.DocNum & "'")
                    If oRecordSet.RecordCount > 0 Then
                        oSI.Browser.Recordset = oRecordSet
                        oSI_Lines = oSI.Lines
                        For row2 = 0 To oSI_Lines.Count
                            If oSI_Lines.BaseLine.Equals(oSO_Lines.LineNum) = True Then
                                oSI_Lines.cost()    '<== INCORRECT!!!!  NOT SURE HOW TO SET THE COST OF THE ITEM....
                                ' How do I recompute the COGM value?
                            End If
                    End If
                End If
        End If
    End Sub

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hey Scott. There is no COGM property. You have to update the table directly.


Answers (0)