<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Thanks Enda.<div>Yes, I read carefully the docs and understand that eval expected a boolena expression.</div><div>I succesfully change the rule to :</div><div><br></div><div><div>rule "Sumatoria de lineas detalle vs Header"</div><div>&nbsp;&nbsp;salience 10</div><div>&nbsp;&nbsp;when</div><div>&nbsp;&nbsp; &nbsp; &nbsp; Number( $total : doubleValue) from accumulate(</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map(this["_TYPE_"] == "D",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $monto : this["MONTO"]),</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum(toDouble($monto)))</div><div>&nbsp;&nbsp; &nbsp; &nbsp; $map : Map(this["_TYPE_"] == "H",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$totEnc : this["MT_TOTAL"]) &amp;&amp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eval(toDouble($totEnc) != $total)</div><div><br></div><div>&nbsp;&nbsp;then</div><div>&nbsp;&nbsp; &nbsp;System.out.println("Encabezado:" + toDouble($totEnc) + ", Detalle=" + $total);</div><div>&nbsp;&nbsp; &nbsp;listBitacora.add(new BitacoraDTO($map.get("_NUMLINE_"),</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Error en el Detalle: El número del lineas de detalle (" + &nbsp;$total +</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") no empareja con lo del encabezado (" + $map.get("NU_REGISTROS") + ")"));</div><div>&nbsp;end</div><div><br></div><div><br></div><div>Where "toDouble" is a function :</div><div><br></div><div><div><div>function double toDouble(Object oMonto) {</div><div>&nbsp;&nbsp; String strMonto = oMonto.toString();</div><div>&nbsp;&nbsp; int len = strMonto.length();</div><div>&nbsp;&nbsp; int pos = len - 2;</div><div><br></div><div>&nbsp;&nbsp; strMonto = StringUtils.left(strMonto, pos) + "." + StringUtils.right(strMonto,2);</div><div><br></div><div>&nbsp;&nbsp; //return Double.valueOf(strMonto) &nbsp;;</div><div>&nbsp;&nbsp; &nbsp;double d = Double.parseDouble(strMonto);</div><div><br></div><div>&nbsp;&nbsp; return d;</div><div>}</div><div><br></div><div><br></div><div>Thanks to Enda and Thomas for help me to solve this...</div><div><br></div></div></div><hr id="stopSpelling">Date: Thu, 11 Mar 2010 15:02:33 +0000<br>From: ejdiggins@gmail.com<br>To: rules-users@lists.jboss.org<br>Subject: Re: [rules-users] Problems count and sumarizing data in facts<br><br>Hi Yamil,<br><br>'eval()' expects a primitive boolean value as a result of the expression. You may need to look into creating a custom accumulate function that can accept a string and do the conversion in java. Have a look at section 6.5.2.10.1 Accumulate Function in the Drools documentation:<br>
<br><a href="http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html_single/index.html">http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html_single/index.html</a><br><br>Alternatively, you could change the type of your map to something like Map&lt;String, Double&gt;<br>
<br>Hope it helps,<br><br>Enda<br><br><div class="ecxgmail_quote">2010/3/11 Yamil Bracho <span dir="ltr">&lt;<a href="mailto:yamilbracho@hotmail.com">yamilbracho@hotmail.com</a>&gt;</span><br><blockquote class="ecxgmail_quote" style="padding-left:1ex">




<div>
I rewrote as :<div><br></div><div><div class="ecxim"><div>rule "Sumatoria de lineas detalle vs Header"</div><div>&nbsp;&nbsp;salience 10</div><div>&nbsp;&nbsp;when</div><div>&nbsp;&nbsp; &nbsp; &nbsp; Number( $total : doubleValue) from accumulate(</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map(this["_TYPE_"] == "D",</div></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $monto : this["MONTO"]),</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum(eval(toDouble($monto))))</div><div class="ecxim"><div>&nbsp;&nbsp; &nbsp; &nbsp; $map : Map(this["_TYPE_"] == "H",</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this["MT_TOTAL"] != $total)</div><div>&nbsp;&nbsp;then</div><div>&nbsp;&nbsp; &nbsp;System.out.println("TOTAL=" + $total);</div><div>&nbsp;&nbsp; &nbsp;listBitacora.add(new BitacoraDTO($map.get("_NUMLINE_"),</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Error en el Detalle: El número del lineas de detalle (" + &nbsp;$total +</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") no empareja con lo del encabezado (" + $map.get("NU_REGISTROS") + ")"));</div>
<div>&nbsp;end</div><div>&nbsp;</div></div><div>Where "toDouble" is :</div><div><br></div><div><div>function Double toDouble(Object oMonto) {</div><div>&nbsp;&nbsp; String strMonto = oMonto.toString();</div><div>&nbsp;&nbsp; int len = strMonto.length();</div>
<div>&nbsp;&nbsp; int pos = len - 3;</div><div><br></div><div>&nbsp;&nbsp; strMonto = StringUtils.left(strMonto, pos) + "." + StringUtils.right(strMonto,2);</div><div><br></div><div>&nbsp;&nbsp; return Double.valueOf(strMonto) &nbsp;;</div><div><br>
</div><div>}</div><div><br></div><div>And I got</div><div><br></div><div><div class="ecxim"><div>Rule Compilation error : [Rule name='Sumatoria de lineas detalle vs Header']</div></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;rule/Rule_Sumatoria_de_lineas_detalle_vs_Header_0.java (9:1350) : The method eval(Double) is undefined for the type Rule_Sumatoria_de_lineas_detalle_vs_Header_0</div>
<div><br></div><div>Thanks again, Thomas..!</div></div></div><div class="ecxim"><br><hr>From: <a href="mailto:TSwindells@nds.com">TSwindells@nds.com</a><br>To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
</div>Date: Thu, 11 Mar 2010 09:25:31 +0000<div><div></div><div class="h5"><br>Subject: Re: [rules-users] Problems count and sumarizing data in facts<br><br>










<div>
<span style="font-size:11pt;color:rgb(31, 73, 125)">Have you tried assigning the string to $monto and then performing the evel within the sum?</span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">&nbsp;</span><BR>
<div style="border-width:medium medium medium 1.5pt;border-style:none none none solid;border-color:-moz-use-text-color -moz-use-text-color -moz-use-text-color blue;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color;padding:3pt 0cm 0cm">
<b><span style="font-size:10pt" lang="EN-US">From:</span></b><span style="font-size:10pt" lang="EN-US"> <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>]
<b>On Behalf Of </b>Yamil Bracho<br>
<b>Sent:</b> 10 March 2010 19:38<br>
<b>To:</b> Drools UserList<br>
<b>Subject:</b> Re: [rules-users] Problems count and sumarizing data in facts</span><BR>
</div>
</div>
&nbsp;<BR>
<span style="font-size:10pt">Thanks Thomas.</span><BR>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
<div>
<span style="font-size:10pt">I rewrote the rule as:</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">rule "Sumatoria de lineas detalle vs Header"</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;salience 10</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;when</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; Number( $total : doubleValue) from accumulate(</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map(this["_TYPE_"] == "D",</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $monto : eval(Double.parseDouble(this.get("MONTO")))),</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum($monto))</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; $map : Map(this["_TYPE_"] == "H",</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this["MT_TOTAL"] != $total)</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;then</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;System.out.println("TOTAL=" + $total);</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;listBitacora.add(new BitacoraDTO($map.get("_NUMLINE_"),</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Error en el Detalle: El número del lineas de detalle (" + &nbsp;$total +</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") no empareja con lo del encabezado (" + $map.get("NU_REGISTROS") + ")"));</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;end</span><BR>
</div>
<div>
<p style="margin-bottom:12pt"><span style="font-size:10pt">&nbsp;</span></p>
</div>
<div>
<span style="font-size:10pt">but I am getting errors in the parseDouble:</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">[828,29]: [ERR 101] Line 828:29 no viable alternative at input 'Double' in rule "Sumatoria de lineas detalle vs Header" in pattern Map[828,67]: [ERR 102] Line 828:67 mismatched
 input ')' expecting 'then' in rule "Sumatoria de lineas detalle vs Header"</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">Any hint...</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
<div style="text-align:center" align="center"><span style="font-size:10pt">
<hr align="center" width="100%" size="2">
</span></div>
<p style="margin-bottom:12pt"><span style="font-size:10pt">From: <a href="mailto:TSwindells@nds.com">TSwindells@nds.com</a><br>
To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
Date: Wed, 10 Mar 2010 15:13:49 +0000<br>
Subject: Re: [rules-users] Problems count and sumarizing data in facts</span></p>
<div>
<span style="font-size:11pt;color:rgb(31, 73, 125)">To convert from string to double you have to full back to java:</span><span style="font-size:10pt"></span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">Something along the lines &nbsp;of</span><span style="font-size:10pt"></span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">$monto : eval(Double.parseDouble(this.get(“MONTO”)))</span><span style="font-size:10pt"></span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">&nbsp;</span><span style="font-size:10pt"></span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">However even with doing this your rules are unlikely to work consistently as you expect.&nbsp; Using equality tests on doubles is fundamentally unsafe as doubles
 aren’t represented exactly and may not exactly match the value you think you have.&nbsp; Force instance 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1 != 1.0 (dependent on floating point chipset etc).&nbsp; If you are dealing with currency then it is far simpler and safer
 to just operate with integers and divide by 100 when you want to display the value.&nbsp; The other alternative is to use BigDecimal which will store an exact representation but will probably require more work with getting your accumulate function correct.&nbsp; Your
 last option is to use Math.abs(left-right) &lt; 0.1 to see if they are approximately equal.&nbsp; More details can be found here
<a href="http://firstclassthoughts.co.uk/java/traps/java_double_traps.html">http://firstclassthoughts.co.uk/java/traps/java_double_traps.html</a></span><span style="font-size:10pt"></span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">&nbsp;</span><span style="font-size:10pt"></span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">Thomas</span><span style="font-size:10pt"></span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">&nbsp;</span><span style="font-size:10pt"></span><BR>
<span style="font-size:11pt;color:rgb(31, 73, 125)">&nbsp;</span><span style="font-size:10pt"></span><BR>
<div style="border-width:medium medium medium 1.5pt;border-style:none none none solid;border-color:-moz-use-text-color -moz-use-text-color -moz-use-text-color blue;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color;padding:3pt 0cm 0cm">
<b><span style="font-size:10pt" lang="EN-US">From:</span></b><span style="font-size:10pt" lang="EN-US"> <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>]
<b>On Behalf Of </b>Yamil Bracho<br>
<b>Sent:</b> 10 March 2010 14:27<br>
<b>To:</b> Drools UserList<br>
<b>Subject:</b> Re: [rules-users] Problems count and sumarizing data in facts</span><span style="font-size:10pt"></span><BR>
</div>
</div>
<span style="font-size:10pt">&nbsp;</span><BR>
<span style="font-size:10pt">I solved the counting of detail lines this way:</span><BR>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<div>
<span style="font-size:10pt">rule "Contador de lineas detalle vs Header"</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;salience 10</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;when</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; Number($count : intValue) from accumulate(</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$mp : Map(this["_TYPE_"] == "D"), count($mp))</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; $map : Map(this["_TYPE_"] == "H",</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this["NU_REGISTROS"] != $count)</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;then</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;System.out.println("NumRecs=" + $count);</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;listBitacora.add(new BitacoraDTO($map.get("_NUMLINE_"),</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"El número del lineas de detalle (" + $count +</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") no empareja con lo del encabezado (" + $map.get("NU_REGISTROS") + ")"));</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;end</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">However, I still got problem with summarize the amounts. I wrote</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<div>
<span style="font-size:10pt">rule "Sumatoria de lineas detalle vs Header"</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;salience 10</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;when</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; Number( $total : doubleValue) from accumulate(</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map(this["_TYPE_"] == "D",</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $monto : ((Number) this["MONTO"]),</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum($monto)))</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; $map : Map(this["_TYPE_"] == "H",</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this["MT_TOTAL"] != $total)</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;then</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;System.out.println("TOTAL=" + $total);</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;listBitacora.add(new BitacoraDTO($map.get("_NUMLINE_"),</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Error en el Detalle: El número del lineas de detalle (" + &nbsp;$total +</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") no empareja con lo del encabezado (" + $map.get("NU_REGISTROS") + ")"));</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;end</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">And i am getting&nbsp;&nbsp;mismatched input" so my question is how to convert a string to double in this line "$monto : ((Number) this["MONTO"])," ?</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">TIA</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">Yamil</span><BR>
</div>
</div>
<span style="font-size:10pt">&nbsp;</span><BR>
<div style="text-align:center" align="center"><span style="font-size:10pt">
<hr align="center" width="100%" size="2">
</span></div>
<span style="font-size:10pt">From: <a href="mailto:yamilbracho@hotmail.com">yamilbracho@hotmail.com</a><br>
To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
Date: Tue, 9 Mar 2010 17:41:43 +0000<br>
Subject: [rules-users] Problems count and sumarizing data in facts<br>
<br>
Hi,&nbsp;I have two kind of facts in a map.</span><BR>
<div>
<div>
<span style="font-size:10pt">There is a field called _TYPE_ (H)eader, D)etail)</span><BR>
</div>
<div>
<span style="font-size:10pt">In the Header line I have two String fields, one for the number of details lines ("NU_REGISTROS") and another for the sum of the detail line ("MT_TOTAL")</span><BR>
</div>
<div>
<span style="font-size:10pt">In the detail lines I only have a String field called "MONTO"&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">I would like to build two rules. One to check the count of detail lines versus the field in the header line so I wrote :</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">rule "Contador de lineas detalle vs Header"</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;salience 10</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;when</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; $numRecs : Number()</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from accumulate(Map(this["_TYPE_"] == "D", $d : this["_NUMLINE_"]), count($d))</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; $map : Map(this["_TYPE_"] == "H",</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this["NU_REGISTROS"] != $numRecs)</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;then</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;System.out.println("NumRecs=" + $numRecs);</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;listBitacora.add(new BitacoraDTO($map.get("_NUMLINE_"),</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Error en el Detalle: El número del lineas de detalle (" + &nbsp;$total +</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") no empareja con lo del encabezado (" + $map.get("NU_REGISTROS") + ")"));</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;end</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;However I always got "NumRecs=1" when i print out the value of $numRecs but I am absolute sure there is two details lines...</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;Second when i try to sumarize the total field in the details line i got (MONTO in the detail line is a string):</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;rule "Sumatoria de lineas detalle vs Header"</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;salience 10</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;when</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; $total : Number()</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from accumulate(Map(this["_TYPE_"] == "D",</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$monto : this["MONTO"]),</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sum(eval(Double.valueOf((String) $monto ))))</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; $map : Map(this["_TYPE_"] == "H",</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this["MT_TOTAL"] != $total)</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp;then</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;System.out.println("TOTAL=" + $total);</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp;listBitacora.add(new BitacoraDTO($map.get("_NUMLINE_"),</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Error en el Detalle: El número del lineas de detalle (" + &nbsp;$total +</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") no empareja con lo del encabezado (" + $map.get("NU_REGISTROS") + ")"));</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;end</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;but I got</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;Rule Compilation error : [Rule name='Sumatoria de lineas detalle vs Header']</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;rule/Rule_Sumatoria_de_lineas_detalle_vs_Header_0.java (9:1313) : The method eval(Double) is undefined for the type Rule_Sumatoria_de_lineas_detalle_vs_Header_0</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;Any help in those tow problems</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;TIA</span><BR>
</div>
<div>
<span style="font-size:10pt">&nbsp;</span><BR>
</div>
<div>
<span style="font-size:10pt">Yamil</span><BR>
</div>
</div>
<span style="font-size:10pt">&nbsp;</span><BR>
<div style="text-align:center" align="center"><span style="font-size:10pt">
<hr align="center" width="100%" size="2">
</span></div>
<span style="font-size:10pt">Actualízate gratis al nuevo Internet Explorer 8 y
<a href="http://www.microsoft.com/spain/windows/internet-explorer/default.aspx">navega más seguro</a></span><BR>
</div>
<span style="font-size:10pt">&nbsp;</span><BR>
<div style="text-align:center" align="center"><span style="font-size:10pt">
<hr align="center" width="100%" size="2">
</span></div>
<span style="font-size:10pt">Compartir tus mejores FOTOS es fácil en Messenger
<a href="http://events.es.msn.com/windows-live/redes-sociales/default.aspx">¡DESCUBRE cómo!</a></span><BR>
</div>
</div>
<span style="font-size:10pt">&nbsp;</span><BR>
<div style="text-align:center" align="center"><span style="font-size:10pt">
<hr align="center" width="100%" size="2">
</span></div>
<p style="margin-bottom:12pt"><span style="font-size:7.5pt;color:gray"><br>
**************************************************************************************<br>
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the <a href="mailto:postmaster@nds.com">postmaster@nds.com</a> and delete it from your system as well as any copies. The content of e-mails as well as traffic data
 may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.<br>
<br>
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00<br>
**************************************************************************************</span><span style="font-size:10pt"></span></p>
<div style="text-align:center" align="center"><span style="font-size:10pt">
<hr align="center" width="100%" size="2">
</span></div>
<span style="font-size:7.5pt;color:gray">This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the <a href="mailto:postmaster@nds.com">postmaster@nds.com</a> and
 delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.<br>
To protect the environment please do not print this e-mail unless necessary.<br>
<br>
An NDS Group Limited company. <a href="http://www.nds.com">www.nds.com</a></span><span style="font-size:10pt"></span><BR>
</div>
</div>
<span style="font-size:10pt">&nbsp;</span><BR>
<div style="text-align:center" align="center"><span style="font-size:10pt">
<hr align="center" width="100%" size="2">
</span></div>
<span style="font-size:10pt">¿Sabes que la Videollamada de Messenger es GRATIS
<a href="http://events.es.msn.com/windows-live/redes-sociales/default.aspx">
¡Descúbrela!</a></span><BR>
</div>
</div>
<br>
<hr>
<font color="Gray" face="Arial" size="1"><br>
**************************************************************************************<br>
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the <a href="mailto:postmaster@nds.com">postmaster@nds.com</a> and delete it from your system as well as any copies. The content of e-mails as well as traffic data
 may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.<br>
<br>
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00<br>
**************************************************************************************<br>
</font><br>
<hr>
<font color="Gray" face="Arial" size="1">This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the <a href="mailto:postmaster@nds.com">postmaster@nds.com</a> and delete it from your system as well as any copies. The
 content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.<br>
To protect the environment please do not print this e-mail unless necessary.<br>
<br>
An NDS Group Limited company. <a href="http://www.nds.com">www.nds.com</a><br>
</font></div></div></div>                                               <br><hr>¿Quieres saber qué móvil eres? <a href="http://www.quemovileres.com/">¡Descúbrelo aquí!</a></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Enda J Diggins<br></div>                                               <br /><hr />Actualízate gratis al nuevo Internet Explorer 8 y <a href='http://www.microsoft.com/spain/windows/internet-explorer/default.aspx' target='_new'>navega más seguro</a></body>
</html>