Sunteți pe pagina 1din 7

An Array of Arrays | IBM i | IBM Systems Magazine

1 of 7

http://www.ibmsystemsmag.com/ibmi/developer/7216p3.aspx

Administrator
Backup and Recovery
DB2
High Availability
LPAR
Networks
Performance
Security
Systems Management
Tivoli
Trends
AIX
Linux
Open Source
What's New
Tips & Techniques
Application Development
Systems Management
Miscellaneous
Case Studies
Automotive
Healthcare
Manufacturing
Miscellaneous
Non-profit
Retail
Storage
Disk
Servers
Software
Tape
Product News
Buyer's Guide
Administrator
Backup and Recovery
DB2
Domino
High Availability
LPAR
Networks
Performance
Printing
Security
Systems Management
WebSphere
Windows Integration
Developer
General
Java
Modernization
RPG
WebSphere
Trends
IBM Announcements
Linux
Open Source
SOA
What's New
Tips & Techniques
Application Development

9/27/2010 10:51 AM

An Array of Arrays | IBM i | IBM Systems Magazine

2 of 7

http://www.ibmsystemsmag.com/ibmi/developer/7216p3.aspx

Systems Management
Case Studies
Automotive
Banking/Finance
Healthcare
Insurance
Manufacturing
Miscellaneous
Non-profit
Retail
Storage
Disk
Optical
Servers
Tape
Product News
Product Reviews
ENDPGM Main Page
Administrator
Backup and Recovery
CICS
DB2
High Availability
IMS
LPAR
Migration
Networks
Performance
Security
Systems Management
Tivoli
Trends
Linux
Open Source
Security
SOA
What's New
z/OS
z/VM
Tips & Techniques
Application Development
Systems Management
Case Studies
Automotive
Banking/Finance
Healthcare
Insurance
Manufacturing
Miscellaneous
Retail
Storage
Disk
Servers
Software
Tape
Product News
Stop Run
Buyer's Guide Main Page

9/27/2010 10:51 AM

An Array of Arrays | IBM i | IBM Systems Magazine

3 of 7

http://www.ibmsystemsmag.com/ibmi/developer/7216p3.aspx

Business Strategy
Competitive Advantage
Consolidation
Executive Perspective
Green IT
Migration
Open Source
ROI
Infrastructure
Blades
Storage
Systems Management
Case Studies
Distribution
Healthcare
Manufacturing
Services
Web 2.0
Cloud
Social Media
Trends
Collaboration
IBM Announcements
IBM Research
Open Source
Social Media
What's New
Product News

AIX
MAINFRAME
POWER
Newsletters
About Us

Subscribe
Current Issue
Archive

IBM i
ALL EDITIONS
ADMINISTRATOR
DEVELOPER
TRENDS
TIPS & TECHNIQUES
CASE STUDIES

9/27/2010 10:51 AM

An Array of Arrays | IBM i | IBM Systems Magazine

4 of 7

http://www.ibmsystemsmag.com/ibmi/developer/7216p3.aspx

STORAGE
PRODUCT NEWS
ENDPGM
BUYER'S GUIDE

Administrator > Security

An Array of Arrays
July 2006 | by Jon Paris and Susan Gantner

Print

Email

An Array of Arrays
As we read each customer record, we simply add the customer number to the starting address of our storage allocation. We then set the indicator at
the resulting position to *On. The first indicator in our "array" corresponds to customer number 00000, the second to customer 00001 and so on.
/Free
// Allocate space for customer indicators (up to 100,000) and
// set intial value of all entries to *Off
pcustomerArray = %alloc(100000);
memset( pcustomerArray: *Off: 100000 );
read custMast;
Dow not %Eof( custmast );
// Increment pointer with customer number to position in array
// Then set the indicator
pvalidCustomer = pcustomerArray + custNo;
validCustomer = *On;
customerCount += 1;
read custMast;
EndDo;
return customerCount;
/end-free
Once the loading of the array is complete, we enter the test loop as we previously did. As you'll see when you study the complete program, the
process of looking up the customer number is basically the same as the approach used to load the array (i.e., we increment the starting pointer by the
customer number).
One Last Thought
You may be wondering how the original technique of using an array of customer numbers could be extended beyond RPG's array limits. The answer,
as you may have already surmised, is to adapt the technique that we've just applied to the indicator array. There are two things that we need to
consider. First, the memory allocation will need to be "n" times the maximum number of entries (where "n" is the size in bytes of a single entry - five
in our case). Second, we need to change the search method. The original program used the %LOOKUP BIF, which can only be applied to
conventional RPG arrays, so we must use the C function bsearch instead. If you're not familiar with using bsearch, you might want to check out "
'Sorting' it All Out." We aim to make an example of this approach available on our Web site in the future for those interested in the technique.
When reviewing the performance figures for these various methods, it's important to remember that many RPG applications, particularly batch, are

9/27/2010 10:51 AM

An Array of Arrays | IBM i | IBM Systems Magazine

5 of 7

http://www.ibmsystemsmag.com/ibmi/developer/7216p3.aspx

I/O bound. Reducing the I/O traffic, even if no physical I/O is involved, can make a far bigger difference to the overall application performance than
these simple timings might indicate.
Table 1 compares the measured performance of the three methods. The figures shown are relative to a base test that used CHAIN against the
customer file. (It may interest you to note that in our tests, CHAIN consistently outperformed SETLL but only by a small margin). As is to be
expected, in a small test of 1,000 lookups, all of our programs took longer than CHAIN due to the overhead of reading the whole file to load the array.
However, as the sample size increased, the advantage quickly swung the other way. Even at a sample size of 10,000 the slowest of the programs was
twice as fast as CHAIN. At a larger sample size the difference is even greater, as you can see.
We hope we've given you something to think about the next time you add a lookup routine to a program. And of course, we hope it goes without
saying that such routines should be packaged in service programs!
In support of these sample programs, we developed a number of small helper subprocedures, the most important of which generates the random
numbers used to fill the test file and generate customer numbers to simulate the transactions. The subprocedure uses the Qc3GenPRNs random
number generator API and although we don't have room to describe it here, we've documented the source code to explain the approach used. You'll
find the routine in the source member BASICTOOLS, which you can download, along with the rest of the programs referenced in the article, from our
Web site (www.Partner400.com/ExtraDownloads.htm).
Page 1 2 3
Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.
More Articles From Jon Paris
Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.
More Articles From Susan Gantner

Advertisement

WEBINAR
Thursday, September 30 2pm (ET) from LANSA
IBM i Enterprise Web Development ---- Fact or Fiction?

Browse products and services for Administrator.

Advertisement

9/27/2010 10:51 AM

An Array of Arrays | IBM i | IBM Systems Magazine

6 of 7

http://www.ibmsystemsmag.com/ibmi/developer/7216p3.aspx

Maximize your IT investment with monthly information from THE source...IBM Systems Magazine EXTRA & Marketplace eNewsletters.
SUBSCRIBE NOW.
View past IBM i EXTRAs here

Related Articles
An Array of Arrays
E-Newsletter Exclusive
iSeries EXTRA: Look Before You %Lookup
E-Newsletter Exclusive
What Is New (and Enhanced) With RPG in V5R3
Developer
Paging RPG IV
The State of Modernization

9/27/2010 10:51 AM

An Array of Arrays | IBM i | IBM Systems Magazine

7 of 7

http://www.ibmsystemsmag.com/ibmi/developer/7216p3.aspx

Cover Story | Bruce Vining talks modernization with Jon Paris and Susan Gantner
IBM i
AIX
MAINFRAME
POWER
Homepage
About Us
Contact Us
Subscriptions
Editorial Calendar
Advertise With Us
Reprints
Privacy Policy
Terms of Service
Sitemap
IBM Systems Magazine is a trademark of International Business Machines Corporation. The editorial content of IBM Systems Magazine is placed on
this website by MSP TechMedia under license from International Business Machines Corporation.
2010 MSP Communications, Inc. All rights reserved

9/27/2010 10:51 AM

S-ar putea să vă placă și