cancel
Showing results for 
Search instead for 
Did you mean: 

Manual Distribution Rule

Former Member
0 Kudos

Hi!

I need to create a MANUAL distribution rule from the SDK to associate then with a line of an Invoice.

I've already used the object SAPbobsCOM.DistributionRule but when I add is displayed in the master data of the distribution rules, in this way:

Dim oCmpSrv As SAPbobsCOM.CompanyService = oCompany.GetCompanyService()
        Dim oDLservice As SAPbobsCOM.DistributionRulesService = oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.DistributionRulesService)
        Dim oDL As SAPbobsCOM.DistributionRule
  
  

            ' Add distribution rule
        oDL = oDLservice.GetDataInterface(SAPbobsCOM.DistributionRulesServiceDataInterfaces.drsDistributionRule)
        oDL.FactorCode = _Code
        oDL.FactorDescription = _Code
        oDL.InWhichDimension = 1
        Dim TotalFactor As Double = 0

        For i As Integer = 0 To (ProfitCenters.Length \ 2) - 1
            oDL.DistributionRuleLines.Add()
            oDL.DistributionRuleLines.Item(i).CenterCode = ProfitCenters(i, 0)
            oDL.DistributionRuleLines.Item(i).TotalInCenter = ProfitCenters(i, 1)
            oDL.DistributionRuleLines.Item(i).Effectivefrom = Date.Now
            TotalFactor += ProfitCenters(i, 1)
        Next
        
        oDL.TotalFactor = TotalFactor


        Try
            oDLservice.AddDistributionRule(oDL)
        Catch ex As Exception
            oLog.Errore(ex.Message, ex)
            _return = ""
        End Try

I would use a manual distribution rule.

How can I do?

Thanks!

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi. Did you find any solution to post the data to manual distribution rule using DIAPI.?

Former Member
0 Kudos

Yes, I have succeeded.

I attach a example code :

oSapInvoice.Lines.CostingCode = AddDistributionRule(ProfitCenters, LineTotal, Me.DocDestDataDoc)



where:


Public Function AddDistributionRule(ByVal ProfitCenters(,) As String, ByVal LineTotal As Double, ByVal DocDate As Date) As String

        Dim _return As String = ""

        Dim oCmpSrv As SAPbobsCOM.CompanyService = oCompany.GetCompanyService()

        Dim oDLservice As SAPbobsCOM.DistributionRulesService = oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.DistributionRulesService)

        Dim oDL As SAPbobsCOM.DistributionRule

        Dim recordSet As SAPbobsCOM.Recordset = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

        Dim sSQL As String

        recordSet.DoQuery("SELECT ISNULL(MAX(CAST(SUBSTRING(OcrCode,2,8) AS INTEGER)),0) FROM OOCR WHERE OcrCode LIKE 'H%'")

        Dim maxIndex As Integer

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

            maxIndex = 1

        Else

            maxIndex = Integer.Parse(recordSet.Fields.Item(0).Value.ToString)

            maxIndex += 1

        End If

        Dim sCode As String = maxIndex.ToString("0000000")

        _return = "H" & sCode

        ' Add distribution rule

        oDL = oDLservice.GetDataInterface(SAPbobsCOM.DistributionRulesServiceDataInterfaces.drsDistributionRule)

        oDL.FactorCode = _return

        oDL.FactorDescription = _return

        oDL.InWhichDimension = 1

        Dim TotalFactor As Double = 0

        Dim TotaleKM As Double = 0

        For i As Integer = 0 To (ProfitCenters.Length \ 2) - 1

            TotaleKM += ProfitCenters(i, 1)

        Next

        Dim j As Integer = 0

        For i As Integer = 0 To (ProfitCenters.Length \ 2) - 1

            If CDbl(ProfitCenters(i, 1)) > 0 Then

                Dim KM As Double = ProfitCenters(i, 1)

                Dim Ricavo As Double = (KM * LineTotal) / TotaleKM

                oDL.DistributionRuleLines.Add()

                oDL.DistributionRuleLines.Item(j).CenterCode = ProfitCenters(i, 0)

                oDL.DistributionRuleLines.Item(j).TotalInCenter = Ricavo

                oDL.DistributionRuleLines.Item(j).Effectivefrom = DocDate

                j += 1

                TotalFactor += Ricavo

            End If

        Next

        oDL.TotalFactor = TotalFactor

        Try

            oDLservice.AddDistributionRule(oDL)

        Catch ex As Exception

            oLog.Errore(ex.Message, ex)

            _return = ""

        End Try

        Return _return

    End Function

Former Member
0 Kudos

Hi Gianluca

I have tried it but am facing the below issue

540000077 - You cannot continue; distribution rule is not fully within linked cost center's effective period

at   oDLservice.AddDistributionRule(oDL).

cost centers are effective from 01-01-2014 to 31-12-2014

and am passing the DocDate as today's date.

Former Member
0 Kudos

Hi Gianluca

Above issue is resolved. The Distributions are added in OOCR and are not getting assigned to the Dimension 1 Cost center.

I have tried the same that you have suggested.

Do you have any other idea?

Former Member
0 Kudos

Hi Gianluca

Thank you. There was an error in my code.. your solution works. But the distribution rule is added to OOCR.

Is there no other way to add the disribution rule to OMDR.

Former Member
0 Kudos

Hi,

What is the reason you select: (ProfitCenters.Length \ 2) - 1 as the ending point?

Thanks,

Gordon

Former Member
0 Kudos

Because ProfitCenters is a two-dimensional array...

Former Member
0 Kudos

In that case, you need to use two loops separately instead of one.

Former Member
0 Kudos

Maybe I have not explained well ... My problem is not in the lines of distribution rule, but I want to create a MANUAL distribution rule...

Former Member
0 Kudos

You have already set: oDL.InWhichDimension = 1. How you can access the 2nd dimension?

Former Member
0 Kudos

If you go on a line of an invoice, in the column "Distr. Rule", you can create a Manual Distribution rule by a button on the form "List of Distribution Rules": I would do the same by the SDK.

Former Member
0 Kudos

Then, use UI API to do the same.

Former Member
0 Kudos

i can't because i need to create from SDK also the Invoice, in this way:

oSapInvoice.Lines.CostingCode = ManualDistributionRule

I need to use a object for the table OMDR and MDR1 (Manual distribution rule)...

Edited by: Gianluca D'Alessandro on Jan 31, 2012 4:38 PM