8 Replies Latest reply: Apr 26, 2012 11:35 AM by Rob Bradford-Oracle RSS

    InstanceCount throwing compile error

    930442
      Hi

      We are tryiing to use a simple example of 'InstanceCount' and 'InstanceCountIf' in OPM.

      We have a entity called 'the citizen' under 'global', and a child entity 'the child' under 'the citizen' entity.
      We have named the relationship between 'the citizen' and 'the child' as 'the children'

      We have written the following rules :

      1.the number of children for the citizen = InstanceCount (the children)

      2.the number of included children for the citizen = InstanceCountIf (the children, the child is included in plan)

      There is a separate rule which derives the value of the Boolean variable 'the child is included in plan', and that rule has compiled successfully.

      On compiling the rules 1 or 2, we get the following compile error :
      Expected: Unable to find a relationship belonging to the entity 'the citizen'

      Please advise how to overcome above compile error.

      Thanks
      Swati
        • 1. Re: InstanceCount throwing compile error
          Rob Bradford-Oracle
          Hi Swati,

          If you're sure you've set up the relationship correctly using relationship text 'the children', the only other thing it is likely to be is that you haven't declared 'the number of children for the citizen' and 'the number of included children for the citizen' as number variables. The text equivalent of InstanceCount(<relationship>) is the number of (<relationship>), so if you haven't declared your variables first then this is how OPM will try and interpret your rule (as the wording matches).
          • 2. Re: InstanceCount throwing compile error
            Matt Sevin-Oracle
            I haven't confirmed that this suggestion resolves your specific issue but in terms of best practice ...

            The relationship from citizen to children should be "the citizen's children". Substitution, parsing and clarity of rules are all improved with this approach. For example, "Joe Citizen's children", no ambiguity on whose children you are counting in the InstanceCount rule etc.. For example, your current rule appears as if you are counting all children to compute the number of children of each specific citizen (at least when reading the rule literally without knowledge of the model).
            • 3. Re: InstanceCount throwing compile error
              930442
              Hi Matt

              Changed the relationship text to 'the citizen's children' and the rule to read :

              the number of included children for the citizen = InstanceCountIf (the citizen's children, the child is included in plan)

              Still getting the same compile error :

              Error after 'the number of '. Found: 'included children for the citizen = InstanceCountIf (the citizen's children, the child is included in plan)'.
              Expected :Unable to find a relationship belonging to the entity 'the citizen'.
              • 4. Re: InstanceCount throwing compile error
                930442
                Hi Rob

                Tried by declaring 'the number of included children for the citizen' as a number variable and then recompiling the rule.

                Getting a new error :

                Error after 'the number of included children for the citizen = '. Found: 'InstanceCountIf (the citizen's children, the child is included in plan)'.
                Expected: expression, variable, constant
                • 5. Re: InstanceCount throwing compile error
                  Davin Fifield-Oracle
                  Try removing the space between InstanceCountIf and the parenthesis.
                  • 6. Re: InstanceCount throwing compile error
                    930442
                    Hi Davin

                    Thanks !
                    My issue was solved by removing the space and declaring the result 'the number of included children for the citizen' as a variable/ attribute beforehand.

                    the number of included children for the citizen = InstanceCountIf(the citizen's children, the child is included in plan)

                    Thanks
                    Swati
                    • 7. Re: InstanceCount throwing compile error
                      773387
                      Hi,

                      I have a similar problem and would be very glad if anyone could help me.

                      My design is as follows, using OPM 10.3.1:

                      global (level 1)
                      has 0...many Households (level 2)
                      have 0...many Residents (level 3)

                      What I would like to do is to get the sum of all Salaries of female residents.

                      If I try to use all_male_salary = InstanceSumIf(Household's Residents, resident_salary, resident_gender="Female") the following error occurs while compiling: "unable to find a relationship belonging to the entity 'global'".
                      The same applies to InstanceCountIf.

                      How would it be possible to get level 3 data on level 1 and store the sum/count in a lvl 1 attribute? (with lvl 2 all works fine).


                      Many thanks!
                      • 8. Re: InstanceCount throwing compile error
                        Rob Bradford-Oracle
                        Not sure how you have named the entities, but assuming you have:

                        Global -> the household -> the household's resident

                        You should do this in two separate calcs, the first to work out the combined female salary of the household (at the household entity level), and the second to sum the figures from each household (global). E.g:

                        the household's total female salaries = InstanceSumIf(the household's residents, the household's resident's salary, the household's resident's gender = "female")

                        the combined salary of all females = InstanceSum(the households, the household's total female salaries)