an array of arrays _ ibm i ...3

Upload: nairarung

Post on 01-Jun-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 An Array of Arrays _ IBM i ...3

    1/7

  • 8/9/2019 An Array of Arrays _ IBM i ...3

    2/7

  • 8/9/2019 An Array of Arrays _ IBM i ...3

    3/7

    Business Strategy

    Competitive Advantage

    Consolidation

    Executive Perspective

    Green IT

    Migration

    Open Source

    ROI

    Infrastructure

    Blades

    StorageSystems Management

    Case Studies

    Distribution

    Healthcare

    Manufacturing

    Services

    Web 2.0

    Cloud

    Social Media

    Trends

    Collaboration

    IBM AnnouncementsIBM 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

    rray of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/721

    9/27/2010 1

  • 8/9/2019 An Array of Arrays _ IBM i ...3

    4/7

    STORAGE

    PRODUCT NEWS

    ENDPGM

    BUYER'S GUIDE

    Administrator> Security

    An Array of ArraysJuly 2006 | by Jon Parisand 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 ThoughtYou 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

    rray of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/721

    9/27/2010 1

  • 8/9/2019 An Array of Arrays _ IBM i ...3

    5/7

    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 123

    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

    rray of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/721

    9/27/2010 1

  • 8/9/2019 An Array of Arrays _ IBM i ...3

    6/7

    Maximize your IT investment with monthly information from THE source...IBM Systems MagazineEXTRA & 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

    rray of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/721

    9/27/2010 1

  • 8/9/2019 An Array of Arrays _ IBM i ...3

    7/7

    Cover Story | Bruce Vining talks modernization with Jon Paris and Susan Gantner

    IBM i

    AIX

    MAINFRAME

    POWER

    Homepage

    About Us

    Contact Us

    Subscriptions

    Editorial CalendarAdvertise 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

    rray of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/721