deploy: 9e06f72056
This commit is contained in:
parent
de09820554
commit
e4f08bf9a7
187 changed files with 6620 additions and 6342 deletions
|
|
@ -6,16 +6,16 @@
|
|||
<link rel=alternate type=application/rss+xml href=/navpatterns/1-patterns/queries/index.xml title="AL Guidelines">
|
||||
<meta name=description content>
|
||||
<title>Queries :: AL Guidelines</title>
|
||||
<link href=/css/nucleus.css?1644506471 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1644506471 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1644506471 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1644506471 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1644506471 rel=stylesheet>
|
||||
<link href=/css/theme.css?1644506471 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1644506471 rel=stylesheet>
|
||||
<link href=/css/variant.css?1644506471 rel=stylesheet>
|
||||
<link href=/css/print.css?1644506471 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1644506471></script>
|
||||
<link href=/css/nucleus.css?1644600601 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1644600601 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1644600601 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1644600601 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1644600601 rel=stylesheet>
|
||||
<link href=/css/theme.css?1644600601 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1644600601 rel=stylesheet>
|
||||
<link href=/css/variant.css?1644600601 rel=stylesheet>
|
||||
<link href=/css/print.css?1644600601 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1644600601></script>
|
||||
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
|
||||
</head>
|
||||
<body data-url=/navpatterns/1-patterns/queries/>
|
||||
|
|
@ -33,9 +33,9 @@ ALGuidelines.Dev
|
|||
<input data-search-input id=search-by type=search placeholder=Search...>
|
||||
<span data-search-clear><i class="fas fa-times"></i></span>
|
||||
</div>
|
||||
<script src=/js/lunr.min.js?1644506471></script>
|
||||
<script src=/js/auto-complete.js?1644506471></script>
|
||||
<script src=/js/search.js?1644506471></script>
|
||||
<script src=/js/lunr.min.js?1644600601></script>
|
||||
<script src=/js/auto-complete.js?1644600601></script>
|
||||
<script src=/js/search.js?1644600601></script>
|
||||
</div>
|
||||
<div class=highlightable>
|
||||
<ul class=topics>
|
||||
|
|
@ -268,12 +268,12 @@ ALGuidelines.Dev
|
|||
<div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px>
|
||||
<div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div>
|
||||
</div>
|
||||
<script src=/js/clipboard.min.js?1644506471></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1644506471></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1644506471></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1644506471></script>
|
||||
<script src=/js/featherlight.min.js?1644506471></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1644506471></script>
|
||||
<script src=/js/relearn.js?1644506471></script>
|
||||
<script src=/js/clipboard.min.js?1644600601></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1644600601></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1644600601></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1644600601></script>
|
||||
<script src=/js/featherlight.min.js?1644600601></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1644600601></script>
|
||||
<script src=/js/relearn.js?1644600601></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
Abstract This pattern explains how to perform SELECT DISTINCT by using queries in Dynamics NAV.
|
||||
Description
|
||||
When working with tables, sometimes a developer needs to perform a SELECT DISTINCT (also known as SELECT UNIQUE) from a table. As NAV does not provide this out of the box, we present below a way to select unique records by using queries.
|
||||
Problem statement</description></item><item><title>Use Queries to Detect Duplicate Records</title><link>https://alguidelines.dev/navpatterns/1-patterns/queries/use-queries-to-detect-duplicate-records/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/navpatterns/1-patterns/queries/use-queries-to-detect-duplicate-records/</guid><description>Originally by Abshishek Ghosh and Bogdan Sturzoiu at Microsoft Development Center Copenhagen
|
||||
Problem statement
|
||||
Let&rsquo;s consider the VAT Entry table as below:</description></item><item><title>Use Queries to Detect Duplicate Records</title><link>https://alguidelines.dev/navpatterns/1-patterns/queries/use-queries-to-detect-duplicate-records/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/navpatterns/1-patterns/queries/use-queries-to-detect-duplicate-records/</guid><description>Originally by Abshishek Ghosh and Bogdan Sturzoiu at Microsoft Development Center Copenhagen
|
||||
Abstract This pattern uses queries to create an efficient way to detect duplicate entries in a table. This is, for example, useful when trying to find out which customers or contacts have the same names, so we can merge them later.
|
||||
Description Duplicate detection has several requirements in Microsoft Dynamics NAV. One method to eliminate duplication is by defining the relevant field as the primary key.</description></item><item><title>Use Queries to Replace Nested Loops</title><link>https://alguidelines.dev/navpatterns/1-patterns/queries/use-queries-to-replace-nested-loops/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/navpatterns/1-patterns/queries/use-queries-to-replace-nested-loops/</guid><description>Originally by Bogdan Sturzoiu, Microsoft Development Center Copenhagen
|
||||
Abstract This pattern shows how the new query object type introduced in NAV 2013 allows you to replace costly loops when inspecting data from two or more tables.
|
||||
|
|
|
|||
|
|
@ -5,16 +5,16 @@
|
|||
<meta name=generator content="Hugo 0.92.1">
|
||||
<meta name=description content>
|
||||
<title>SELECT DISTINCT with Queries :: AL Guidelines</title>
|
||||
<link href=/css/nucleus.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/theme.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/variant.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/print.css?1644506469 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1644506469></script>
|
||||
<link href=/css/nucleus.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/theme.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/variant.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/print.css?1644600599 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1644600599></script>
|
||||
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
|
||||
</head>
|
||||
<body data-url=/navpatterns/1-patterns/queries/select-distinct-with-queries/>
|
||||
|
|
@ -32,9 +32,9 @@ ALGuidelines.Dev
|
|||
<input data-search-input id=search-by type=search placeholder=Search...>
|
||||
<span data-search-clear><i class="fas fa-times"></i></span>
|
||||
</div>
|
||||
<script src=/js/lunr.min.js?1644506469></script>
|
||||
<script src=/js/auto-complete.js?1644506469></script>
|
||||
<script src=/js/search.js?1644506469></script>
|
||||
<script src=/js/lunr.min.js?1644600599></script>
|
||||
<script src=/js/auto-complete.js?1644600599></script>
|
||||
<script src=/js/search.js?1644600599></script>
|
||||
</div>
|
||||
<div class=highlightable>
|
||||
<ul class=topics>
|
||||
|
|
@ -251,8 +251,8 @@ ALGuidelines.Dev
|
|||
<ul>
|
||||
<li>
|
||||
<ul>
|
||||
<li><a href=#abstract><strong>Abstract</strong></a></li>
|
||||
<li><a href=#example><strong>Example</strong></a></li>
|
||||
<li><a href=#abstract>Abstract</a></li>
|
||||
<li><a href=#example>Example</a></li>
|
||||
<li><a href=#nav-usages><strong>NAV Usages</strong></a></li>
|
||||
<li><a href=#related-topics><strong>Related Topics</strong></a></li>
|
||||
</ul>
|
||||
|
|
@ -267,18 +267,15 @@ ALGuidelines.Dev
|
|||
<main id=body-inner>
|
||||
<h1>SELECT DISTINCT with Queries</h1>
|
||||
<p><em>By Bogdana Botez, at Microsoft Development Center Copenhagen</em></p>
|
||||
<h3 id=abstract><strong>Abstract</strong></h3>
|
||||
<h3 id=abstract>Abstract</h3>
|
||||
<p>This pattern explains how to perform SELECT DISTINCT by using queries in Dynamics NAV.</p>
|
||||
<hr>
|
||||
<p><strong>Description</strong></p>
|
||||
<p>When working with tables, sometimes a developer needs to perform a SELECT DISTINCT (also known as SELECT UNIQUE) from a table. As NAV does not provide this out of the box, we present below a way to select unique records by using queries.</p>
|
||||
<hr>
|
||||
<p><strong>Problem statement</strong></p>
|
||||
<p>Let’s consider the <strong>VAT Entry</strong> table as below: <a href=https://microsoft.sharepoint.com/teams/DynamicsNAV/Wiki/Nav%20Wiki%20Documents/NAV%20App%20Patterns/NAV%20App%20Patterns%20for%20Review/Table%20Select%20Distinct.docx#_msocom_1><br>
|
||||
</a></p>
|
||||
<p>Let’s consider the <strong>VAT Entry</strong> table as below: <a href=https://microsoft.sharepoint.com/teams/DynamicsNAV/Wiki/Nav%20Wiki%20Documents/NAV%20App%20Patterns/NAV%20App%20Patterns%20for%20Review/Table%20Select%20Distinct.docx#_msocom_1> </a></p>
|
||||
<p><a href=6521.clip_5F00_image001.png><img src=6521.clip_5F00_image001.png alt=" "></a></p>
|
||||
<p>The goal is to select one line for each separate document that produced VAT Entries. In other words, we want records grouped by <strong>Type, Document Type</strong> and <strong>Document No.</strong>. However, if there are multiple lines with the same value of the triad <strong>Type, Document Type</strong> and <strong>Document No.</strong> in the <strong>VAT Entry</strong> table, we only want to see one of them.</p>
|
||||
<h4 id=solution><strong>Solution</strong></h4>
|
||||
<h4 id=solution>Solution</h4>
|
||||
<p>Create a new query object <strong>VAT Entry Distinct Document No.</strong>, with a single DataItem sourced from <strong>VAT Entry</strong> table. Add the three desired group-by fields <strong>Type, Document Type</strong> and <strong>Document No.</strong> as columns.</p>
|
||||
<p><a href=clip_5F00_image002.png><img src=clip_5F00_image002.png alt=" "></a></p>
|
||||
<p>To enable grouping, add one more column, with <strong>Method Type</strong> = <strong>Totals</strong>. This will automatically set the <strong>Group By</strong> checkbox to TRUE on the three precedent fields.</p>
|
||||
|
|
@ -286,7 +283,7 @@ ALGuidelines.Dev
|
|||
<p><a href=clip_5F00_image003.png><img src=clip_5F00_image003.png alt=" "></a></p>
|
||||
<p>Running the query yields a single record per document. You can notice in the second line below for example, how the sales invoice number 103001 had 2 VAT Entries, but it shows up only once in the query:</p>
|
||||
<p><a href=clip_5F00_image004.png><img src=clip_5F00_image004.png alt=" "></a></p>
|
||||
<h3 id=example><strong>Example</strong></h3>
|
||||
<h3 id=example>Example</h3>
|
||||
<p>One thing is to be noted: there is a limitation to how much information you can take out from the records. For example, if we need to extract more information than just the one we already have in the columns, then the following apply: adding one more column of <strong>Method Type</strong> = <strong>None</strong> will indeed show more information, but it <em>might</em> affect the grouping. More details below.</p>
|
||||
<p><strong>The grouping is affected</strong> for example when the additional column is the <strong>VAT Entry No</strong>. In this case, this column brings up additional grouping criteria and one group for each entry number will end up being created.</p>
|
||||
<p><a href=clip_5F00_image005.png><img src=clip_5F00_image005.png alt=" "></a></p>
|
||||
|
|
@ -315,12 +312,12 @@ ALGuidelines.Dev
|
|||
<div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px>
|
||||
<div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div>
|
||||
</div>
|
||||
<script src=/js/clipboard.min.js?1644506469></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1644506469></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1644506469></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1644506469></script>
|
||||
<script src=/js/featherlight.min.js?1644506469></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1644506469></script>
|
||||
<script src=/js/relearn.js?1644506469></script>
|
||||
<script src=/js/clipboard.min.js?1644600599></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1644600599></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1644600599></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1644600599></script>
|
||||
<script src=/js/featherlight.min.js?1644600599></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1644600599></script>
|
||||
<script src=/js/relearn.js?1644600599></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -5,16 +5,16 @@
|
|||
<meta name=generator content="Hugo 0.92.1">
|
||||
<meta name=description content>
|
||||
<title>Use Queries to Detect Duplicate Records :: AL Guidelines</title>
|
||||
<link href=/css/nucleus.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/theme.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/variant.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/print.css?1644506469 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1644506469></script>
|
||||
<link href=/css/nucleus.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/theme.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/variant.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/print.css?1644600599 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1644600599></script>
|
||||
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
|
||||
</head>
|
||||
<body data-url=/navpatterns/1-patterns/queries/use-queries-to-detect-duplicate-records/>
|
||||
|
|
@ -32,9 +32,9 @@ ALGuidelines.Dev
|
|||
<input data-search-input id=search-by type=search placeholder=Search...>
|
||||
<span data-search-clear><i class="fas fa-times"></i></span>
|
||||
</div>
|
||||
<script src=/js/lunr.min.js?1644506469></script>
|
||||
<script src=/js/auto-complete.js?1644506469></script>
|
||||
<script src=/js/search.js?1644506469></script>
|
||||
<script src=/js/lunr.min.js?1644600599></script>
|
||||
<script src=/js/auto-complete.js?1644600599></script>
|
||||
<script src=/js/search.js?1644600599></script>
|
||||
</div>
|
||||
<div class=highlightable>
|
||||
<ul class=topics>
|
||||
|
|
@ -249,13 +249,9 @@ ALGuidelines.Dev
|
|||
<div class=wrapper>
|
||||
<nav id=TableOfContents>
|
||||
<ul>
|
||||
<li><a href=#abstract><strong>Abstract</strong></a></li>
|
||||
<li><a href=#description><strong>Description</strong></a>
|
||||
<ul>
|
||||
<li></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href=#usage><strong>Usage</strong></a>
|
||||
<li><a href=#abstract>Abstract</a></li>
|
||||
<li><a href=#description>Description</a></li>
|
||||
<li><a href=#usage>Usage</a>
|
||||
<ul>
|
||||
<li></li>
|
||||
</ul>
|
||||
|
|
@ -271,29 +267,27 @@ ALGuidelines.Dev
|
|||
<main id=body-inner>
|
||||
<h1>Use Queries to Detect Duplicate Records</h1>
|
||||
<p><em>Originally by Abshishek Ghosh and Bogdan Sturzoiu at Microsoft Development Center Copenhagen</em></p>
|
||||
<h2 id=abstract><strong>Abstract</strong></h2>
|
||||
<h2 id=abstract>Abstract</h2>
|
||||
<p>This pattern uses queries to create an efficient way to detect duplicate entries in a table. This is, for example, useful when trying to find out which customers or contacts have the same names, so we can merge them later.</p>
|
||||
<h2 id=description><strong>Description</strong></h2>
|
||||
<h2 id=description>Description</h2>
|
||||
<p>Duplicate detection has several requirements in Microsoft Dynamics NAV. One method to eliminate duplication is by defining the relevant field as the primary key. However, this method is not always practical either due to the size of the field or due to business requirements that dictate how duplicates are detected but not necessarily how they are eliminated. An example of this method is to detect contacts with the same name and take action to merge them if they are.</p>
|
||||
<p>Before Dynamics NAV 2013, the only possibility was to iterate through the table in a loop and then create a sub-loop where another instance of the same table is filtered to check for duplicates. For example, to check for duplicate names in the Customer table, the code would look like this:</p>
|
||||
<pre><code>PROCEDURE HasDuplicateCustomers@26() : Boolean;
|
||||
VAR
|
||||
Customer@1000 : Record 18;
|
||||
Customer2@1001 : Record 18;
|
||||
BEGIN
|
||||
IF Customer.FINDSET THEN
|
||||
REPEAT
|
||||
Customer2.SETRANGE(Name,Customer.Name);
|
||||
IF Customer2.COUNT \> 1 THEN
|
||||
EXIT(TRUE);
|
||||
UNTIL Customer.NEXT = 0;
|
||||
EXIT(FALSE);
|
||||
END;
|
||||
</code></pre>
|
||||
<h4 id=heading></h4>
|
||||
<p>This code would involve setting filters on the <strong>Customer</strong> table as many times as there are records in the table. This is an expensive operation.</p>
|
||||
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al><span style=color:#66d9ef>PROCEDURE</span> HasDuplicateCustomers@<span style=color:#ae81ff>26</span><span style=color:#f92672>() </span>: <span style=color:#66d9ef>Boolean</span>;
|
||||
<span style=color:#66d9ef>VAR</span>
|
||||
Customer@<span style=color:#ae81ff>1000</span> : <span style=color:#66d9ef>Record</span> <span style=color:#ae81ff>18</span>;
|
||||
Customer2@<span style=color:#ae81ff>1001</span> : <span style=color:#66d9ef>Record</span> <span style=color:#ae81ff>18</span>;
|
||||
<span style=color:#66d9ef>BEGIN</span>
|
||||
<span style=color:#66d9ef>IF</span> Customer<span style=color:#f92672>.</span>FINDSET <span style=color:#66d9ef>THEN</span>
|
||||
<span style=color:#66d9ef>REPEAT</span>
|
||||
Customer2<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span>Name,Customer<span style=color:#f92672>.</span>Name<span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>IF</span> Customer2<span style=color:#f92672>.</span><span style=color:#66d9ef>COUNT</span> \> <span style=color:#ae81ff>1</span> <span style=color:#66d9ef>THEN</span>
|
||||
<span style=color:#66d9ef>EXIT</span><span style=color:#f92672>(</span>TRUE<span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>UNTIL</span> Customer<span style=color:#f92672>.</span>NEXT = <span style=color:#ae81ff>0</span>;
|
||||
<span style=color:#66d9ef>EXIT</span><span style=color:#f92672>(</span>FALSE<span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>END</span>;
|
||||
</code></pre></div><p>This code would involve setting filters on the <strong>Customer</strong> table as many times as there are records in the table. This is an expensive operation.</p>
|
||||
<p>Starting with Dynamics NAV 2013, we can use queries to create a more efficient implementation of the same logic.</p>
|
||||
<h2 id=usage><strong>Usage</strong></h2>
|
||||
<h2 id=usage>Usage</h2>
|
||||
<p>The solution involves that you create a query to return duplicates, and then invoke it from a method that would test the value of the query to identify if duplicates were found.</p>
|
||||
<p><strong>Step 1</strong> – <strong>Creating the Query</strong></p>
|
||||
<ul>
|
||||
|
|
@ -303,7 +297,7 @@ END;
|
|||
</ul>
|
||||
<p>Continuing with our Customer Name example, here is how the query would look:</p>
|
||||
<p><a href=clip_5F00_image002.jpg><img src=clip_5F00_image002.jpg alt=" "></a></p>
|
||||
<h4 id=heading-1></h4>
|
||||
<h4 id=heading></h4>
|
||||
<pre><code>ELEMENTS
|
||||
{
|
||||
{ 1 ; ;DataItem; ;
|
||||
|
|
@ -311,26 +305,22 @@ DataItemTable=Table18 }
|
|||
{ 2 ;1 ;Column ; ;
|
||||
DataSource=Name }
|
||||
{ 3 ;1 ;Column ; ;
|
||||
ColumnFilter=Count\_=FILTER(\>1);
|
||||
ColumnFilter=Count_=FILTER(\>1);
|
||||
MethodType=Totals;
|
||||
Method=Count }
|
||||
}
|
||||
</code></pre>
|
||||
<p>**<br>
|
||||
**</p>
|
||||
<p><strong>Step 2 – Invoking the Query to Check for Duplicates</strong></p>
|
||||
<p>Now that the query is created, all we need to do is to invoke the query and check if any records are returned, which would mean that there are duplicates.</p>
|
||||
<p>Here is an alternate implementation of the <strong>HasDuplicateCustomers</strong> method using the query that we created:</p>
|
||||
<pre><code>PROCEDURE HasDuplicateCustomersWithQuery@27() : Boolean;
|
||||
VAR
|
||||
CustomerDuplicate@1000 : Query 70000;
|
||||
BEGIN
|
||||
CustomerDuplicate.OPEN;
|
||||
EXIT(CustomerDuplicate.READ);
|
||||
END;
|
||||
</code></pre>
|
||||
<h4 id=heading-2></h4>
|
||||
<p><strong>Examples</strong></p>
|
||||
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al><span style=color:#66d9ef>PROCEDURE</span> HasDuplicateCustomersWithQuery@<span style=color:#ae81ff>27</span><span style=color:#f92672>() </span>: <span style=color:#66d9ef>Boolean</span>;
|
||||
<span style=color:#66d9ef>VAR</span>
|
||||
CustomerDuplicate@<span style=color:#ae81ff>1000</span> : <span style=color:#66d9ef>Query</span> <span style=color:#ae81ff>70000</span>;
|
||||
<span style=color:#66d9ef>BEGIN</span>
|
||||
CustomerDuplicate<span style=color:#f92672>.</span>OPEN;
|
||||
<span style=color:#66d9ef>EXIT</span><span style=color:#f92672>(</span>CustomerDuplicate<span style=color:#f92672>.</span>READ<span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>END</span>;
|
||||
</code></pre></div><p><strong>Examples</strong></p>
|
||||
<ul>
|
||||
<li><strong>Acc. Sched. Chart Management</strong> codeunit (762),<br>
|
||||
methods CheckDuplicateAccScheduleLineDescription and CheckDuplicateColumnLayoutColumnHeader</li>
|
||||
|
|
@ -351,12 +341,12 @@ methods CheckDuplicateAnalysisLineDescription and CheckDuplicateAnalysisColumnHe
|
|||
<div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px>
|
||||
<div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div>
|
||||
</div>
|
||||
<script src=/js/clipboard.min.js?1644506469></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1644506469></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1644506469></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1644506469></script>
|
||||
<script src=/js/featherlight.min.js?1644506469></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1644506469></script>
|
||||
<script src=/js/relearn.js?1644506469></script>
|
||||
<script src=/js/clipboard.min.js?1644600599></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1644600599></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1644600599></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1644600599></script>
|
||||
<script src=/js/featherlight.min.js?1644600599></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1644600599></script>
|
||||
<script src=/js/relearn.js?1644600599></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -5,16 +5,16 @@
|
|||
<meta name=generator content="Hugo 0.92.1">
|
||||
<meta name=description content>
|
||||
<title>Use Queries to Replace Nested Loops :: AL Guidelines</title>
|
||||
<link href=/css/nucleus.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/theme.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/variant.css?1644506469 rel=stylesheet>
|
||||
<link href=/css/print.css?1644506469 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1644506469></script>
|
||||
<link href=/css/nucleus.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/theme.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/variant.css?1644600599 rel=stylesheet>
|
||||
<link href=/css/print.css?1644600599 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1644600599></script>
|
||||
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
|
||||
</head>
|
||||
<body data-url=/navpatterns/1-patterns/queries/use-queries-to-replace-nested-loops/>
|
||||
|
|
@ -32,9 +32,9 @@ ALGuidelines.Dev
|
|||
<input data-search-input id=search-by type=search placeholder=Search...>
|
||||
<span data-search-clear><i class="fas fa-times"></i></span>
|
||||
</div>
|
||||
<script src=/js/lunr.min.js?1644506469></script>
|
||||
<script src=/js/auto-complete.js?1644506469></script>
|
||||
<script src=/js/search.js?1644506469></script>
|
||||
<script src=/js/lunr.min.js?1644600599></script>
|
||||
<script src=/js/auto-complete.js?1644600599></script>
|
||||
<script src=/js/search.js?1644600599></script>
|
||||
</div>
|
||||
<div class=highlightable>
|
||||
<ul class=topics>
|
||||
|
|
@ -249,12 +249,12 @@ ALGuidelines.Dev
|
|||
<div class=wrapper>
|
||||
<nav id=TableOfContents>
|
||||
<ul>
|
||||
<li><a href=#abstract><strong>Abstract</strong></a>
|
||||
<li><a href=#abstract>Abstract</a>
|
||||
<ul>
|
||||
<li><a href=#description><strong>Description</strong></a></li>
|
||||
<li><a href=#usage><strong>Usage</strong></a></li>
|
||||
<li><a href=#nav-specific-examples><strong>NAV Specific Examples</strong></a></li>
|
||||
<li><a href=#ideas-for-improvement><strong>Ideas for Improvement</strong></a></li>
|
||||
<li><a href=#description>Description</a></li>
|
||||
<li><a href=#usage>Usage</a></li>
|
||||
<li><a href=#nav-specific-examples>NAV Specific Examples</a></li>
|
||||
<li><a href=#ideas-for-improvement>Ideas for Improvement</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -267,18 +267,18 @@ ALGuidelines.Dev
|
|||
<main id=body-inner>
|
||||
<h1>Use Queries to Replace Nested Loops</h1>
|
||||
<p><em>Originally by Bogdan Sturzoiu, Microsoft Development Center Copenhagen</em></p>
|
||||
<h2 id=abstract><strong>Abstract</strong></h2>
|
||||
<h2 id=abstract>Abstract</h2>
|
||||
<p>This pattern shows how the new query object type introduced in NAV 2013 allows you to replace costly loops when inspecting data from two or more tables.</p>
|
||||
<h3 id=description><strong>Description</strong></h3>
|
||||
<h3 id=description>Description</h3>
|
||||
<p>One of the core operations in a relational database is joining two or more tables. For example, you might need to extract all sales lines in the database together with information regarding the related sales header. This requires joining the Sales Header and Sales Line tables using Sales Header No. as the connecting field.;</p>
|
||||
<p>The join operation has traditionally been done in C/AL by record looping. When NAV 2013 introduced the query object, it allowed us to produce a data set that is the result of a join operation between two or more tables. This simplifies the problem of finding related records in two tables linked through a foreign key.</p>
|
||||
<h4 id=pattern-elements><strong>Pattern Elements</strong></h4>
|
||||
<h4 id=pattern-elements>Pattern Elements</h4>
|
||||
<ol>
|
||||
<li>Two or more tables that contain records linked through a foreign key: Table 1, Table 2, Table n.</li>
|
||||
<li>A query object Query X, that joins Table 1, Table 2, etc. based on the connecting key.</li>
|
||||
<li>A processing codeunit that loops through the query records (or any other code-bearing object).</li>
|
||||
</ol>
|
||||
<h4 id=pattern-steps><strong>Pattern Steps</strong></h4>
|
||||
<h4 id=pattern-steps>Pattern Steps</h4>
|
||||
<ol>
|
||||
<li>Run the query on the connected tables.</li>
|
||||
<li>Loop through the records returned by the query.</li>
|
||||
|
|
@ -286,141 +286,128 @@ ALGuidelines.Dev
|
|||
</ol>
|
||||
<p><a href=5040.clip_5F00_image002.png><img src=5040.clip_5F00_image002.png alt=" "></a></p>
|
||||
<p><em>Figure 1. The pattern elements</em></p>
|
||||
<h3 id=usage><strong>Usage</strong></h3>
|
||||
<h4 id=sample-problem><strong>Sample Problem</strong></h4>
|
||||
<h3 id=usage>Usage</h3>
|
||||
<h4 id=sample-problem>Sample Problem</h4>
|
||||
<p>The Bank Acc. Reconciliation Line table (274) and the Bank Account Ledger Entry table (271) are connected through the Bank Account No. field. Identify the matching pairs of records based on having the same remaining amount and transaction date.</p>
|
||||
<h4 id=solution-using-nested-loops><strong>Solution Using Nested Loops</strong></h4>
|
||||
<h4 id=solution-using-nested-loops>Solution Using Nested Loops</h4>
|
||||
<p>The classic C/AL approach is to:</p>
|
||||
<ol>
|
||||
<li>
|
||||
<p>Set the necessary filters on the left table, i.e. table 274.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Loop through the filtered records.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>For each record in the filter, find the related records in the right table (table 271) and set the required filters on it.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>For each pair of records from the left and right table, decide if they are a solution and if so, apply them to each other.</p>
|
||||
<p>PROCEDURE MatchSingle@5(BankAccReconciliation@1003 : Record 273);
|
||||
VAR
|
||||
BankAccRecLine@1005 : Record 274;
|
||||
BankAccLedgerEntry@1006 : Record 271;
|
||||
BankAccEntrySetReconNo@1007 : Codeunit 375;
|
||||
BEGIN
|
||||
BankAccRecLine.SETRANGE(“Bank Account No.",BankAccReconciliation.“Bank Account No.");
|
||||
BankAccRecLine.SETRANGE(“Statement No.",BankAccReconciliation.“Statement No.");
|
||||
BankAccRecLine.SETFILTER(Difference,'<>%1',0);
|
||||
BankAccRecLine.SETRANGE(Type,BankAccRecLine.Type::“Bank Account Ledger Entry”);
|
||||
IF BankAccRecLine.FINDSET THEN
|
||||
REPEAT
|
||||
BankAccLedgerEntry.SETRANGE(“Bank Account No.",BankAccRecLine.“Bank Account No.");
|
||||
BankAccLedgerEntry.SETRANGE(Open,TRUE);
|
||||
BankAccLedgerEntry.SETRANGE(“Statement Status”,BankAccLedgerEntry.“Statement Status”::Open);
|
||||
BankAccLedgerEntry.SETFILTER(“Remaining Amount”,'<>%1',0);
|
||||
IF BankAccLedgerEntry.FINDSET THEN
|
||||
REPEAT
|
||||
IF (BankAccRecLine.Difference = BankAccLedgerEntry.“Remaining Amount”) AND
|
||||
(BankAccRecLine.“Transaction Date” = BankAccLedgerEntry.“Posting Date”) THEN
|
||||
BankAccEntrySetReconNo.ApplyEntries(
|
||||
BankAccRecLine,BankAccLedgerEntry, Relation::“One-to-One”);
|
||||
UNTIL BankAccLedgerEntry.NEXT = 0;
|
||||
UNTIL BankAccRecLine.NEXT = 0;
|
||||
END;</p>
|
||||
</li>
|
||||
<li>Set the necessary filters on the left table, i.e. table 274.</li>
|
||||
<li>Loop through the filtered records.</li>
|
||||
<li>For each record in the filter, find the related records in the right table (table 271) and set the required filters on it.</li>
|
||||
<li>For each pair of records from the left and right table, decide if they are a solution and if so, apply them to each other.</li>
|
||||
</ol>
|
||||
<p><strong>Solution Using Query</strong></p>
|
||||
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al><span style=color:#66d9ef>PROCEDURE</span> MatchSingle@<span style=color:#ae81ff>5</span><span style=color:#f92672>(</span>BankAccReconciliation@<span style=color:#ae81ff>1003</span> : <span style=color:#66d9ef>Record</span> <span style=color:#ae81ff>273</span><span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>VAR</span>
|
||||
BankAccRecLine@<span style=color:#ae81ff>1005</span> : <span style=color:#66d9ef>Record</span> <span style=color:#ae81ff>274</span>;
|
||||
BankAccLedgerEntry@<span style=color:#ae81ff>1006</span> : <span style=color:#66d9ef>Record</span> <span style=color:#ae81ff>271</span>;
|
||||
BankAccEntrySetReconNo@<span style=color:#ae81ff>1007</span> : <span style=color:#66d9ef>Codeunit</span> <span style=color:#ae81ff>375</span>;
|
||||
<span style=color:#66d9ef>BEGIN</span>
|
||||
BankAccRecLine<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span>"Bank Account No.",BankAccReconciliation<span style=color:#f92672>.</span>"Bank Account No."<span style=color:#f92672>)</span>;
|
||||
BankAccRecLine<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span>"Statement No.",BankAccReconciliation<span style=color:#f92672>.</span>"Statement No."<span style=color:#f92672>)</span>;
|
||||
BankAccRecLine<span style=color:#f92672>.</span>SETFILTER<span style=color:#f92672>(</span>Difference,<span style=color:#e6db74>'<>%1'</span>,<span style=color:#ae81ff>0</span><span style=color:#f92672>)</span>;
|
||||
BankAccRecLine<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span><span style=color:#66d9ef>Type</span>,BankAccRecLine<span style=color:#f92672>.</span><span style=color:#66d9ef>Type</span>::"Bank Account Ledger Entry"<span style=color:#f92672>)</span>;
|
||||
|
||||
<span style=color:#66d9ef>IF</span> BankAccRecLine<span style=color:#f92672>.</span>FINDSET <span style=color:#66d9ef>THEN</span>
|
||||
<span style=color:#66d9ef>REPEAT</span>
|
||||
BankAccLedgerEntry<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span>"Bank Account No.",BankAccRecLine<span style=color:#f92672>.</span>"Bank Account No."<span style=color:#f92672>)</span>;
|
||||
BankAccLedgerEntry<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span>Open,TRUE<span style=color:#f92672>)</span>;
|
||||
BankAccLedgerEntry<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span>"Statement Status",BankAccLedgerEntry<span style=color:#f92672>.</span>"Statement Status"::Open<span style=color:#f92672>)</span>;
|
||||
BankAccLedgerEntry<span style=color:#f92672>.</span>SETFILTER<span style=color:#f92672>(</span>"Remaining Amount",<span style=color:#e6db74>'<>%1'</span>,<span style=color:#ae81ff>0</span><span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>IF</span> BankAccLedgerEntry<span style=color:#f92672>.</span>FINDSET <span style=color:#66d9ef>THEN</span>
|
||||
<span style=color:#66d9ef>REPEAT</span>
|
||||
<span style=color:#66d9ef>IF</span> <span style=color:#f92672>(</span>BankAccRecLine<span style=color:#f92672>.</span>Difference = BankAccLedgerEntry<span style=color:#f92672>.</span>"Remaining Amount"<span style=color:#f92672>) </span><span style=color:#f92672>AND</span>
|
||||
<span style=color:#f92672>(</span>BankAccRecLine<span style=color:#f92672>.</span>"Transaction Date" = BankAccLedgerEntry<span style=color:#f92672>.</span>"Posting Date"<span style=color:#f92672>) </span><span style=color:#66d9ef>THEN</span>
|
||||
BankAccEntrySetReconNo<span style=color:#f92672>.</span>ApplyEntries<span style=color:#f92672>(
|
||||
</span><span style=color:#f92672> </span>BankAccRecLine,BankAccLedgerEntry, Relation::"One-to-One"<span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>UNTIL</span> BankAccLedgerEntry<span style=color:#f92672>.</span>NEXT = <span style=color:#ae81ff>0</span>;
|
||||
<span style=color:#66d9ef>UNTIL</span> BankAccRecLine<span style=color:#f92672>.</span>NEXT = <span style=color:#ae81ff>0</span>;
|
||||
<span style=color:#66d9ef>END</span>;
|
||||
</code></pre></div><p><strong>Solution Using Query</strong></p>
|
||||
<p>The new query-based approach involves:</p>
|
||||
<ol>
|
||||
<li>
|
||||
<p>Define a query that returns the full filtered join of tables 271 and 274.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Loop through the records returned by the query.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>For each query record, decide if it represents a solution and then connect the two table records that formed it through an application.</p>
|
||||
<p>PROCEDURE MatchSingle@5(BankAccReconciliation@1003 : Record 273);
|
||||
VAR
|
||||
BankRecMatchCandidates@1001 : Query 1252;
|
||||
BankAccEntrySetReconNo@1007 : Codeunit 375;
|
||||
BEGIN
|
||||
BankRecMatchCandidates.SETRANGE(Rec_Line_Bank_Account_No,
|
||||
BankAccReconciliation.“Bank Account No.");
|
||||
BankRecMatchCandidates.SETRANGE(Rec_Line_Statement_No,
|
||||
BankAccReconciliation.“Statement No.");
|
||||
IF NOT BankRecMatchCandidates.OPEN THEN
|
||||
EXIT;
|
||||
WHILE BankRecMatchCandidates.READ DO BEGIN
|
||||
BankAccLedgerEntry.GET(BankRecMatchCandidates.Entry_No);
|
||||
BankAccRecLine.GET(BankAccRecLine.“Statement Type”::“Bank Reconciliation”,
|
||||
BankRecMatchCandidates.Rec_Line_Bank_Account_No,
|
||||
BankRecMatchCandidates.Rec_Line_Statement_No,
|
||||
BankRecMatchCandidates.Rec_Line_Statement_Line_No);
|
||||
BankAccEntrySetReconNo.ApplyEntries(BankAccRecLine,BankAccLedgerEntry,
|
||||
Relation::“One-to-One”);
|
||||
END;
|
||||
END;</p>
|
||||
</li>
|
||||
<li>Define a query that returns the full filtered join of tables 271 and 274.</li>
|
||||
<li>Loop through the records returned by the query.</li>
|
||||
<li>For each query record, decide if it represents a solution and then connect the two table records that formed it through an application.</li>
|
||||
</ol>
|
||||
<p>where the query 1252 is defined as:</p>
|
||||
<pre><code>OBJECT Query 1252 Bank Rec. Match Candidates
|
||||
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al><span style=color:#66d9ef>PROCEDURE</span> MatchSingle@<span style=color:#ae81ff>5</span><span style=color:#f92672>(</span>BankAccReconciliation@<span style=color:#ae81ff>1003</span> : <span style=color:#66d9ef>Record</span> <span style=color:#ae81ff>273</span><span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>VAR</span>
|
||||
BankRecMatchCandidates@<span style=color:#ae81ff>1001</span> : <span style=color:#66d9ef>Query</span> <span style=color:#ae81ff>1252</span>;
|
||||
BankAccEntrySetReconNo@<span style=color:#ae81ff>1007</span> : <span style=color:#66d9ef>Codeunit</span> <span style=color:#ae81ff>375</span>;
|
||||
<span style=color:#66d9ef>BEGIN</span>
|
||||
BankRecMatchCandidates<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span>Rec_Line_Bank_Account_No,
|
||||
BankAccReconciliation<span style=color:#f92672>.</span>"Bank Account No."<span style=color:#f92672>)</span>;
|
||||
BankRecMatchCandidates<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span>Rec_Line_Statement_No,
|
||||
BankAccReconciliation<span style=color:#f92672>.</span>"Statement No."<span style=color:#f92672>)</span>;
|
||||
|
||||
<span style=color:#66d9ef>IF</span> <span style=color:#f92672>NOT</span> BankRecMatchCandidates<span style=color:#f92672>.</span>OPEN <span style=color:#66d9ef>THEN</span>
|
||||
<span style=color:#66d9ef>EXIT</span>;
|
||||
|
||||
<span style=color:#66d9ef>WHILE</span> BankRecMatchCandidates<span style=color:#f92672>.</span>READ <span style=color:#66d9ef>DO</span> <span style=color:#66d9ef>BEGIN</span>
|
||||
BankAccLedgerEntry<span style=color:#f92672>.</span>GET<span style=color:#f92672>(</span>BankRecMatchCandidates<span style=color:#f92672>.</span>Entry_No<span style=color:#f92672>)</span>;
|
||||
BankAccRecLine<span style=color:#f92672>.</span>GET<span style=color:#f92672>(</span>BankAccRecLine<span style=color:#f92672>.</span>"Statement Type"::"Bank Reconciliation",
|
||||
BankRecMatchCandidates<span style=color:#f92672>.</span>Rec_Line_Bank_Account_No,
|
||||
BankRecMatchCandidates<span style=color:#f92672>.</span>Rec_Line_Statement_No,
|
||||
BankRecMatchCandidates<span style=color:#f92672>.</span>Rec_Line_Statement_Line_No<span style=color:#f92672>)</span>;
|
||||
BankAccEntrySetReconNo<span style=color:#f92672>.</span>ApplyEntries<span style=color:#f92672>(</span>BankAccRecLine,BankAccLedgerEntry,
|
||||
Relation::"One-to-One"<span style=color:#f92672>)</span>;
|
||||
<span style=color:#66d9ef>END</span>;
|
||||
<span style=color:#66d9ef>END</span>;
|
||||
</code></pre></div><p>where the query 1252 is defined as:</p>
|
||||
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al>OBJECT <span style=color:#66d9ef>Query</span> <span style=color:#ae81ff>1252</span> Bank Rec<span style=color:#f92672>. </span>Match Candidates
|
||||
{
|
||||
OBJECT-PROPERTIES
|
||||
{
|
||||
Date=;
|
||||
Time=;
|
||||
Version List=;
|
||||
}
|
||||
PROPERTIES
|
||||
{
|
||||
}
|
||||
ELEMENTS
|
||||
{
|
||||
{ 1 ; ;DataItem; ;
|
||||
DataItemTable=Table274;
|
||||
DataItemTableFilter=Difference=FILTER(<\>0),
|
||||
Type=FILTER(=Bank Account Ledger Entry) }
|
||||
{ 2 ;1 ;Column ;Rec\_Line\_Bank\_Account\_No;
|
||||
DataSource=Bank Account No. }
|
||||
{ 3 ;1 ;Column ;Rec\_Line\_Statement\_No;
|
||||
DataSource=Statement No. }
|
||||
{ 4 ;1 ;Column ;Rec\_Line\_Statement\_Line\_No;
|
||||
DataSource=Statement Line No. }
|
||||
{ 5 ;1 ;Column ;Rec\_Line\_Transaction\_Date;
|
||||
DataSource=Transaction Date }
|
||||
{ 6 ;1 ;Column ;Rec\_Line\_Difference ;
|
||||
DataSource=Difference }
|
||||
{ 7 ;1 ;DataItem; ;
|
||||
DataItemTable=Table271;
|
||||
DataItemTableFilter=Remaining Amount=FILTER(<\>0),
|
||||
Open=CONST(Yes),
|
||||
Statement Status=FILTER(Open);
|
||||
DataItemLink=Bank Account No.=Bank\_Acc\_Reconciliation\_Line."Bank Account o.",
|
||||
Remaining Amount=Bank\_Acc\_Reconciliation\_Line.Difference,
|
||||
Posting Date=Bank\_Acc\_Reconciliation\_Line."Transaction Date" }
|
||||
{ 8 ;2 ;Column ; ;
|
||||
DataSource=Entry No. }
|
||||
{ 9 ;2 ;Column ;Bank\_Account\_No ;
|
||||
DataSource=Bank Account No. }
|
||||
{ 10 ;2 ;Column ; ;
|
||||
DataSource=Posting Date }
|
||||
{ 11 ;2 ;Column ; ;
|
||||
DataSource=Remaining Amount }
|
||||
{ 12 ;2 ;Column ;Bank\_Ledger\_Entry\_Open;
|
||||
DataSource=Open }
|
||||
{ 13 ;2 ;Column ; ;
|
||||
DataSource=Statement Status }
|
||||
}
|
||||
CODE
|
||||
{
|
||||
BEGIN
|
||||
END.
|
||||
}
|
||||
</code></pre>
|
||||
<h4 id=heading></h4>
|
||||
<p>When comparing the two implementations, we notice the following advantages of using a query instead of two loops:Comparison</p>
|
||||
OBJECT<span style=color:#f92672>-</span>PROPERTIES
|
||||
{
|
||||
<span style=color:#66d9ef>Date</span>=;
|
||||
<span style=color:#66d9ef>Time</span>=;
|
||||
<span style=color:#66d9ef>Version</span> <span style=color:#66d9ef>List</span>=;
|
||||
}
|
||||
PROPERTIES
|
||||
{
|
||||
}
|
||||
<span style=color:#66d9ef>ELEMENTS</span>
|
||||
{
|
||||
{ <span style=color:#ae81ff>1</span> ; ;<span style=color:#66d9ef>DataItem</span>; ;
|
||||
DataItemTable=Table274;
|
||||
DataItemTableFilter=Difference=<span style=color:#66d9ef>FILTER</span><span style=color:#f92672>(</span><><span style=color:#ae81ff>0</span><span style=color:#f92672>)</span>,
|
||||
<span style=color:#66d9ef>Type</span>=<span style=color:#66d9ef>FILTER</span><span style=color:#f92672>(</span>=Bank Account Ledger Entry<span style=color:#f92672>) </span>}
|
||||
{ <span style=color:#ae81ff>2</span> ;<span style=color:#ae81ff>1</span> ;<span style=color:#66d9ef>Column</span> ;Rec_Line_Bank_Account_No;
|
||||
DataSource=Bank Account No<span style=color:#f92672>. </span>}
|
||||
{ <span style=color:#ae81ff>3</span> ;<span style=color:#ae81ff>1</span> ;<span style=color:#66d9ef>Column</span> ;Rec_Line_Statement_No;
|
||||
DataSource=Statement No<span style=color:#f92672>. </span>}
|
||||
{ <span style=color:#ae81ff>4</span> ;<span style=color:#ae81ff>1</span> ;<span style=color:#66d9ef>Column</span> ;Rec_Line_Statement_Line_No;
|
||||
DataSource=Statement Line No<span style=color:#f92672>. </span>}
|
||||
{ <span style=color:#ae81ff>5</span> ;<span style=color:#ae81ff>1</span> ;<span style=color:#66d9ef>Column</span> ;Rec_Line_Transaction_Date;
|
||||
DataSource=Transaction <span style=color:#66d9ef>Date</span> }
|
||||
{ <span style=color:#ae81ff>6</span> ;<span style=color:#ae81ff>1</span> ;<span style=color:#66d9ef>Column</span> ;Rec_Line_Difference ;
|
||||
DataSource=Difference }
|
||||
{ <span style=color:#ae81ff>7</span> ;<span style=color:#ae81ff>1</span> ;<span style=color:#66d9ef>DataItem</span>; ;
|
||||
DataItemTable=Table271;
|
||||
DataItemTableFilter=Remaining Amount=<span style=color:#66d9ef>FILTER</span><span style=color:#f92672>(</span><><span style=color:#ae81ff>0</span><span style=color:#f92672>)</span>,
|
||||
Open=<span style=color:#66d9ef>CONST</span><span style=color:#f92672>(</span>Yes<span style=color:#f92672>)</span>,
|
||||
Statement Status=<span style=color:#66d9ef>FILTER</span><span style=color:#f92672>(</span>Open<span style=color:#f92672>)</span>;
|
||||
DataItemLink=Bank Account No<span style=color:#f92672>.</span>=Bank_Acc_Reconciliation_Line<span style=color:#f92672>.</span>"Bank Account o.",
|
||||
Remaining Amount=Bank_Acc_Reconciliation_Line<span style=color:#f92672>.</span>Difference,
|
||||
Posting <span style=color:#66d9ef>Date</span>=Bank_Acc_Reconciliation_Line<span style=color:#f92672>.</span>"Transaction Date" }
|
||||
{ <span style=color:#ae81ff>8</span> ;<span style=color:#ae81ff>2</span> ;<span style=color:#66d9ef>Column</span> ; ;
|
||||
DataSource=Entry No<span style=color:#f92672>. </span>}
|
||||
{ <span style=color:#ae81ff>9</span> ;<span style=color:#ae81ff>2</span> ;<span style=color:#66d9ef>Column</span> ;Bank_Account_No ;
|
||||
DataSource=Bank Account No<span style=color:#f92672>. </span>}
|
||||
{ <span style=color:#ae81ff>10</span> ;<span style=color:#ae81ff>2</span> ;<span style=color:#66d9ef>Column</span> ; ;
|
||||
DataSource=Posting <span style=color:#66d9ef>Date</span> }
|
||||
{ <span style=color:#ae81ff>11</span> ;<span style=color:#ae81ff>2</span> ;<span style=color:#66d9ef>Column</span> ; ;
|
||||
DataSource=Remaining Amount }
|
||||
{ <span style=color:#ae81ff>12</span> ;<span style=color:#ae81ff>2</span> ;<span style=color:#66d9ef>Column</span> ;Bank_Ledger_Entry_Open;
|
||||
DataSource=Open }
|
||||
{ <span style=color:#ae81ff>13</span> ;<span style=color:#ae81ff>2</span> ;<span style=color:#66d9ef>Column</span> ; ;
|
||||
DataSource=Statement Status }
|
||||
}
|
||||
<span style=color:#66d9ef>CODE</span>
|
||||
{
|
||||
<span style=color:#66d9ef>BEGIN</span>
|
||||
<span style=color:#66d9ef>END</span><span style=color:#f92672>.
|
||||
</span><span style=color:#f92672> </span>}
|
||||
</code></pre></div><p>When comparing the two implementations, we notice the following advantages of using a query instead of two loops:Comparison</p>
|
||||
<ol>
|
||||
<li>A query produces the Cartesian product of tables 1 and 2 faster than by looping through both of them. The advantage grows as there are more tables linked.</li>
|
||||
</ol>
|
||||
|
|
@ -430,9 +417,9 @@ END.
|
|||
<li>Using a query only requires one loop, whereas joining two or more tables requires multiple code loops that quickly become difficult to read and follow.</li>
|
||||
<li>Queries are easy to create and maintain and generally provide a cleaner design.</li>
|
||||
</ol>
|
||||
<h3 id=nav-specific-examples><strong>NAV Specific Examples</strong></h3>
|
||||
<h3 id=nav-specific-examples>NAV Specific Examples</h3>
|
||||
<p>In Microsoft Dynamics NAV 2013 R2, we can see the query object used in the bank account reconciliation matching algorithm. The object is query Bank Rec. Match Candidates query (1252), and it is called by the matching engine in the Match Bank Rec. Lines codeunit (1252).</p>
|
||||
<h3 id=ideas-for-improvement><strong>Ideas for Improvement</strong></h3>
|
||||
<h3 id=ideas-for-improvement>Ideas for Improvement</h3>
|
||||
<p>The query object type could be improved to allow the passing of parameters at runtime, or, in general, being built dynamically at runtime. This will remove the need for multiple static definitions of the same base query used in slightly different contexts.</p>
|
||||
<footer class=footline>
|
||||
</footer>
|
||||
|
|
@ -446,12 +433,12 @@ END.
|
|||
<div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px>
|
||||
<div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div>
|
||||
</div>
|
||||
<script src=/js/clipboard.min.js?1644506469></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1644506469></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1644506469></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1644506469></script>
|
||||
<script src=/js/featherlight.min.js?1644506469></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1644506469></script>
|
||||
<script src=/js/relearn.js?1644506469></script>
|
||||
<script src=/js/clipboard.min.js?1644600599></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1644600599></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1644600599></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1644600599></script>
|
||||
<script src=/js/featherlight.min.js?1644600599></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1644600599></script>
|
||||
<script src=/js/relearn.js?1644600599></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue