<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Nav developer's blog : C/AL</title><link>http://blogs.msdn.com/nav_developer/archive/tags/C_2F00_AL/default.aspx</link><description>Tags: C/AL</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Problems in transformation forms to pages using TransformationTools</title><link>http://blogs.msdn.com/nav_developer/archive/2009/09/14/problems-in-transformation-forms-to-pages-using-transformationtools.aspx</link><pubDate>Mon, 14 Sep 2009 15:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9894944</guid><dc:creator>gediminb</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/nav_developer/comments/9894944.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nav_developer/commentrss.aspx?PostID=9894944</wfw:commentRss><description>&lt;P&gt;After Microsoft Dynamics NAV 2009 SP1 release more and more developers start using it and trying to&amp;nbsp;adopt existing solutions&amp;nbsp;for new 3tier environment.&lt;BR&gt;Most workload comes from trying to adopt current forms to new object - pages.&lt;BR&gt;Particularly transformation could be done by using TransformationTools (&lt;A href="http://msdn.microsoft.com/en-us/library/dd338789.aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd338789.aspx"&gt;http://msdn.microsoft.com/en-us/library/dd338789.aspx&lt;/A&gt;), however it is not "best ever" and partners reporting&amp;nbsp;problems and require to fix it...&lt;/P&gt;
&lt;P&gt;But it isn't so easy...&lt;/P&gt;
&lt;P&gt;This tool is delivered to us from dev team and it&amp;nbsp;helps us to make transformation faster, but it is supplementary tool - we can use NAV without this tool and we can "convert " our solutions without it - do it manually.&lt;BR&gt;So "big thanks" to dev team for this tool, however we can't expect that dev team will fix all problems in tool with the same priority&amp;nbsp;as base products (Microsoft Dynamics NAV).&lt;/P&gt;
&lt;P&gt;And we can't expect fixes for problems related&amp;nbsp;to incorrect transformed statements - after transformation pages can't be compiled...&lt;BR&gt;Problem is in tool simplicity: it searches for text and convert it to another text. Converting rules are described in file CodeRules.txt (&lt;A href="http://msdn.microsoft.com/en-us/library/dd338843.aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd338843.aspx"&gt;http://msdn.microsoft.com/en-us/library/dd338843.aspx&lt;/A&gt;).&lt;BR&gt;But simplicity is as strength as weakness of this tool - only text described in CodeRules.txt file will be converted, if there are any differences in text - transformation will be incorrect.&lt;BR&gt;For example:&lt;BR&gt;In form code we have statement:&lt;BR&gt;&lt;FONT face="Courier New"&gt;CurrForm.Number.UPDATEFONTBOLD(Number);&lt;BR&gt;&lt;FONT face=Arial&gt;Then after transformation on page will be created&amp;nbsp;new variable &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;NumberEmphasize&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face=Arial&gt;And statement will be converted to:&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;NumberEmphasize := Number;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face=Arial&gt;It is because&amp;nbsp;UPDATEFONTBOLD is not used in pages and must be removed.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;So far so good.&lt;BR&gt;Tranformation will be done correct for statements:&lt;BR&gt;&lt;FONT face="Courier New"&gt;CurrForm.Number.UPDATEFONTBOLD(Number1=Number);&lt;BR&gt;CurrForm.Number.UPDATEFONTBOLD(Number1&amp;gt;Number);&lt;BR&gt;&lt;/FONT&gt;and etc. because transformation rules are described in CodeRules.txt&lt;/P&gt;
&lt;P&gt;But transformation tool is looking for direct text fit to rules and will not transform text which is not described in Coderules.txt.&amp;nbsp;&lt;BR&gt;If code becomes little more complicated (not described the same&amp;nbsp;syntax as CodeRules)&amp;nbsp;- transformation tool capitulates.&lt;BR&gt;For example next code will not be transformed:&lt;BR&gt;&lt;FONT face="Courier New"&gt;CurrForm.Number.UPDATEFONTBOLD(Number1&amp;lt;Number);&lt;BR&gt;CurrForm.Number.UPDATEFONTBOLD(Number1=xRec.Number);&lt;BR&gt;CurrForm.Number.UPDATEFONTBOLD(xRec.Number1=Number);&lt;/FONT&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;CurrForm.Number.UPDATEFONTBOLD(Number1=Number2=Number3);&lt;BR&gt;CurrForm.Number.UPDATEFONTBOLD(Number1=(Number+100));&lt;/FONT&gt;&lt;BR&gt;...&lt;BR&gt;&lt;BR&gt;Yes... We can make rules for these statements too&amp;nbsp;(dev team delivered rules file), but we will never describe everything what could be written by happy-creative developpers around the world...&lt;BR&gt;Maybe some rules could be&amp;nbsp;never used? Who&amp;nbsp;knows..?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;I can collect all requirements for CodeRules.txt and periodically release new one (fixed). Do you want to&amp;nbsp;order me do&amp;nbsp;it, let me know in comment to current post :) ...&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;EM&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin" lang=EN&gt;&lt;FONT size=3&gt;These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal&gt;&lt;EM&gt;&lt;SPAN style="FONT-STYLE: normal; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-style: italic; mso-bidi-font-weight: bold" lang=EN&gt;&lt;FONT size=3&gt;Gedas Busniauskas&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 10pt" class=MsoNormal&gt;&lt;EM&gt;&lt;SPAN style="FONT-STYLE: normal; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-style: italic; mso-bidi-font-weight: bold" lang=EN&gt;&lt;FONT size=3&gt;Microsoft Lithuania&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-style: italic; mso-bidi-font-weight: bold" lang=EN&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; mso-ansi-language: EN" lang=EN&gt;&lt;FONT size=3&gt;Microsoft Customer Service and Support (CSS) EMEA&lt;/FONT&gt;&lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9894944" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nav_developer/archive/tags/C_2F00_AL/default.aspx">C/AL</category><category domain="http://blogs.msdn.com/nav_developer/archive/tags/Upgrade/default.aspx">Upgrade</category><category domain="http://blogs.msdn.com/nav_developer/archive/tags/NAV+2009/default.aspx">NAV 2009</category><category domain="http://blogs.msdn.com/nav_developer/archive/tags/Transformation/default.aspx">Transformation</category></item><item><title>What exactly does COUNT count?</title><link>http://blogs.msdn.com/nav_developer/archive/2008/05/08/what-exactly-does-count-count.aspx</link><pubDate>Thu, 08 May 2008 12:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8470443</guid><dc:creator>Lohndorf</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/nav_developer/comments/8470443.aspx</comments><wfw:commentRss>http://blogs.msdn.com/nav_developer/commentrss.aspx?PostID=8470443</wfw:commentRss><description>&lt;P&gt;The command COUNT is pretty simple. But on the SQL option there are a number of different ways to count records, and each can give a different result. This is how the different ways of counting works in NAV on SQL:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two commands you can use: COUNT or COUNTAPPROX. As the name suggests, COUNTAPPROX is only designed to give an approximate count. But this does not necessarily mean that COUN is exact (I will come back to this later).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;COUNTAPPROX:&lt;/STRONG&gt;&lt;BR&gt;This command doesn't actually count anything. It only asks SQL Server to make a query plan for a SELECT statement. Then it reads the estimated number of records from the query plan. This is how COUNTAPPROX looks in a profiler trace:&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SET&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;SHOWPLAN_ALL&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ON&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SELECT&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;*&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;FROM&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT size=2&gt;"CRONUS International Ltd_$Standard Text" &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;WITH&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;READUNCOMMITTED&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SET&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;SHOWPLAN_ALL&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;OFF&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;It is the same as if you click on Query -&amp;gt; "Display Estimated Execution Plan (Ctrl+L)" in SQL Server Management Studio, instead of running a query normally (Ctrl+E / F5). This tells SQL Server to only compile a query plan, but not actually run the query. The query plan will contain "estimated number of rows", which in turn is based on SQL Server statistics. This is the number that COUNTAPPROX returns.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;&lt;STRONG&gt;COUNT:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;COUNT works differently, depending on whether there is a filter on the table or not. Without a filter it can just go to Table-Information, and get the number of records from there. This is quicker than going to the actual table and count every record. On the SQL Side, it means counting the number of rows from the sysindexes table, like this:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SELECT&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;SUM&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;rows&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;),&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;SUM&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;reserved&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;FROM&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT size=2&gt;[dbo]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;[sysindexes]&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;But sysindexes is not always up to date! Only just after having updated statistics, can you rely on the numbers in this table. So COUNT, without a filter, will not always give you the correct number.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;If you have a filter, for example:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;Cust.SETRANGE("Currency Code",'EUR');&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;i := Cust.COUNT;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#000000&gt;Then the method of just looking up table-information doesn't work. So NAV has to count the records the hard way. In this case we finally get an actual COUNT SQL command:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SELECT&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;COUNT&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(*)&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;FROM&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;"CRONUS International Ltd_$Customer"&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;But even this method of counting is still not necessarily accurate, because it reads uncommitted data. If you run the following code from another client, and leave the CONFIRM-dialog:&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;OnRun()&lt;BR&gt;Cust.INSERT(TRUE);&lt;BR&gt;Cust."Currency Code" := 'EUR';&lt;BR&gt;Cust.MODIFY;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;IF NOT CONFIRM('Continue?') THEN;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;ERROR('Transaction rollback.');&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;Then, the COUNT above will include a record which never existed / was never committed.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;The only way to get an exact count, is by applying a lock. For example:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;Cust.LOCKTABLE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;i := Cust.COUNT;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;This will give you an exact count, whether you have a filter or not. On the&amp;nbsp;SQL side it will look like this:&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;SELECT&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;COUNT&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(*)&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;FROM&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;"CRONUS International Ltd_$Customer" &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;WITH&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;UPDLOCK&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;Because of the &lt;FONT color=#0000ff&gt;UPDLOCK&lt;/FONT&gt;&amp;nbsp;it only counts committed records. And because of the lock, NAV knows not to just look up the number of records from table information, but to run a &lt;FONT color=#0000ff&gt;SELECT&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;COUNT &lt;/FONT&gt;on SQL Server.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;FONT color=#000000&gt;
&lt;P&gt;&lt;FONT size=2&gt;Lars Lohndorf-Larsen&lt;/P&gt;
&lt;P&gt;Microsoft Dynamics UK&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Microsoft Customer Service and Support (CSS) EMEA&lt;/P&gt;
&lt;P&gt;These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8470443" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/nav_developer/archive/tags/C_2F00_AL/default.aspx">C/AL</category><category domain="http://blogs.msdn.com/nav_developer/archive/tags/SQL/default.aspx">SQL</category></item></channel></rss>