<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: AS/400:- How to select records to be displayed in subfile</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/as400-how-to-select-records-to-be-displayed-in-subfile/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/as400-how-to-select-records-to-be-displayed-in-subfile/</link>
	<description></description>
	<lastBuildDate>Thu, 20 Jun 2013 01:19:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: sloopy</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/as400-how-to-select-records-to-be-displayed-in-subfile/#comment-53750</link>
		<dc:creator>sloopy</dc:creator>
		<pubDate>Thu, 05 Jun 2008 15:38:56 +0000</pubDate>
		<guid isPermaLink="false">#comment-53750</guid>
		<description><![CDATA[The sort of selection you want is certainly more suited to SQL than to native database processing. And in the screen programs I have done, I have found either no great speed difference between &#039;ordinary&#039; RPG selection and embedded SQL selection, or else the SQL selection was much faster.

However, there are some ways to speed things up.

In SLQRPG, NEVER select from logical files. SQL does not like logical files. See this article to find out why:

http://www.itjungle.com/fhg/fhg040908-story01.html

See THIS article to see how to make sure that your iSeries SQL will not use logical files :

http://www.itjungle.com/fhg/fhg041608-story01.html

In addition, coding multiple conditioned SQL SELECT statements in your program can also speed things up, because you can then use the SELECT statement that best fits the selections the user has made from your screen. So, for the cases where the user only fills in a single range, there is a SELECT just for that single range. But there must always be a SELECT for the worst-case, where multiple ranges and single values have been selected.

Now to &#039;ordinary&#039; RPG processing. I am assuming here that all your ranges are on data held in the same physical file.

First, look at the logical files you have to play with. You can specify all those that allow you to select the ranges of data required in your F-specs, and of course they must have different record format names in the code.

(Create a D-spec externally-described data structure for the file. It will be filled in by any of the record formats when you do a read from any of the logicals, because they all have the same field names. You don&#039;t really need it, but if your screen fields are based on a similar extrenally-described structure with a renamed prefix, then just one EVAL will move the data from the file into the structure for the screen, so saving some time.)

Have a subroutine which examines the user selections, and which will decide which logical file to use. So, if the user selects the range FAX REFERENCE NUMBER, your routine will decide to use the logical keyed on fax reference number . The object is to reduce the number of database reads. However, there may be issues regarding the order the user expects the data to be shown in the subfile.

Your subroutine will have set a multi-valued flag that will control a Select group to SETLL the selected logical using the FROM range value, and then in a read loop to control a Select group to Read the logical.

You READ the range for the key. Test the key value , and when it is greater than the TO range value leave the loop. If the user entered just one value (meaning &#039;just this value&#039;), then set the TO value = the FROM value.

Inside the loop, perform sub-selection, where the user has entered additional selection values not covered by the logical you used.

So, if the user entered a range of Fax Reference Numbers and a single Order Date, and you don&#039;t have a logical based on order date, you will read the logical based on Fax Ref No for the range, and within the loop have:

Select
When ScreenOrderDateFrom = *Zero
When ScreenOrderDateTo = *Zero and
     FileOrderDate &lt;&gt; ScreenOrderDateFrom
Iter
When FileOrderDate &lt; ScreenOrderDateFrom or
     FileOrderDate &gt; ScreenOrderDateTo
Iter
EndSl

The Iter is the fastest way to loop round for the next record.

Of course, you&#039;ll also have a Select group that covers the range your logical is keyed on, just because the read loop could be reading from any of the logicals; but this Select group will never make an Iter.

Another thing to look at is, how many records do you expect to find? If it&#039;s a lot, then think about loading the subfile a page at a time, so the user gets one page as soon as it is filled, and the program only looks for the next page of data when the user pressed Roll Up (Page Down). Otherwise you may spend a lot of time loading a lot of records, and the user will get bored and make a cup of tea, spill it on his keyboard, and you will get the blame.

Regards,

Sloopy]]></description>
		<content:encoded><![CDATA[<p>The sort of selection you want is certainly more suited to SQL than to native database processing. And in the screen programs I have done, I have found either no great speed difference between &#8216;ordinary&#8217; RPG selection and embedded SQL selection, or else the SQL selection was much faster.</p>
<p>However, there are some ways to speed things up.</p>
<p>In SLQRPG, NEVER select from logical files. SQL does not like logical files. See this article to find out why:</p>
<p><a href="http://www.itjungle.com/fhg/fhg040908-story01.html" rel="nofollow">http://www.itjungle.com/fhg/fhg040908-story01.html</a></p>
<p>See THIS article to see how to make sure that your iSeries SQL will not use logical files :</p>
<p><a href="http://www.itjungle.com/fhg/fhg041608-story01.html" rel="nofollow">http://www.itjungle.com/fhg/fhg041608-story01.html</a></p>
<p>In addition, coding multiple conditioned SQL SELECT statements in your program can also speed things up, because you can then use the SELECT statement that best fits the selections the user has made from your screen. So, for the cases where the user only fills in a single range, there is a SELECT just for that single range. But there must always be a SELECT for the worst-case, where multiple ranges and single values have been selected.</p>
<p>Now to &#8216;ordinary&#8217; RPG processing. I am assuming here that all your ranges are on data held in the same physical file.</p>
<p>First, look at the logical files you have to play with. You can specify all those that allow you to select the ranges of data required in your F-specs, and of course they must have different record format names in the code.</p>
<p>(Create a D-spec externally-described data structure for the file. It will be filled in by any of the record formats when you do a read from any of the logicals, because they all have the same field names. You don&#8217;t really need it, but if your screen fields are based on a similar extrenally-described structure with a renamed prefix, then just one EVAL will move the data from the file into the structure for the screen, so saving some time.)</p>
<p>Have a subroutine which examines the user selections, and which will decide which logical file to use. So, if the user selects the range FAX REFERENCE NUMBER, your routine will decide to use the logical keyed on fax reference number . The object is to reduce the number of database reads. However, there may be issues regarding the order the user expects the data to be shown in the subfile.</p>
<p>Your subroutine will have set a multi-valued flag that will control a Select group to SETLL the selected logical using the FROM range value, and then in a read loop to control a Select group to Read the logical.</p>
<p>You READ the range for the key. Test the key value , and when it is greater than the TO range value leave the loop. If the user entered just one value (meaning &#8216;just this value&#8217;), then set the TO value = the FROM value.</p>
<p>Inside the loop, perform sub-selection, where the user has entered additional selection values not covered by the logical you used.</p>
<p>So, if the user entered a range of Fax Reference Numbers and a single Order Date, and you don&#8217;t have a logical based on order date, you will read the logical based on Fax Ref No for the range, and within the loop have:</p>
<p>Select<br />
When ScreenOrderDateFrom = *Zero<br />
When ScreenOrderDateTo = *Zero and<br />
     FileOrderDate &lt;&gt; ScreenOrderDateFrom<br />
Iter<br />
When FileOrderDate &lt; ScreenOrderDateFrom or<br />
     FileOrderDate &gt; ScreenOrderDateTo<br />
Iter<br />
EndSl</p>
<p>The Iter is the fastest way to loop round for the next record.</p>
<p>Of course, you&#8217;ll also have a Select group that covers the range your logical is keyed on, just because the read loop could be reading from any of the logicals; but this Select group will never make an Iter.</p>
<p>Another thing to look at is, how many records do you expect to find? If it&#8217;s a lot, then think about loading the subfile a page at a time, so the user gets one page as soon as it is filled, and the program only looks for the next page of data when the user pressed Roll Up (Page Down). Otherwise you may spend a lot of time loading a lot of records, and the user will get bored and make a cup of tea, spill it on his keyboard, and you will get the blame.</p>
<p>Regards,</p>
<p>Sloopy</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/9 queries in 0.012 seconds using memcached
Object Caching 268/271 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-06-20 01:25:53 -->