an array of arrays _ ibm i ...1

7
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 An Array of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/7216p1.aspx?ht= 1 of 7 9/27/2010 10:50 AM

Upload: nairarung

Post on 17-Jul-2016

219 views

Category:

Documents


2 download

DESCRIPTION

as400

TRANSCRIPT

Page 1: An Array of Arrays _ IBM i ...1

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

An Array of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/7216p1.aspx?ht=

1 of 7 9/27/2010 10:50 AM

Page 2: An Array of Arrays _ IBM i ...1

Systems Management

Case Studies

Automotive

Banking/Finance

Healthcare

Insurance

Manufacturing

Miscellaneous

Non-profit

Retail

Storage

Disk

Optical

Servers

Tape

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

An Array of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/7216p1.aspx?ht=

2 of 7 9/27/2010 10:50 AM

Page 3: An Array of Arrays _ IBM i ...1

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

An Array of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/7216p1.aspx?ht=

3 of 7 9/27/2010 10:50 AM

Page 4: An Array of Arrays _ IBM i ...1

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

One of the most under-utilized features of RPG IV has to be arrays. We frequently see programs that use a database lookup when an array could've

served the purpose and would almost certainly have been far more efficient. For example, many of you probably have a database on your system

containing the U.S. state codes and names. This, in spite of the fact that the last record to be added to the file was Hawaii in August of 1959. Not

exactly a dynamic file is it?! We suspect that part of the reason for this lies in the fact that prior to V5R1, RPG didn't have a high-speed array search

capability. The performance of the old LOOKUP op-code was so poor that it was often faster to use a database lookup. The advent of the %LOOKUP

BIF removed this shortcoming, but old habits die hard. If you want to know more about the details behind how %LOOKUP operates read the article,

"Look before you %LOOKUP."

For this article, we decided to explore the idea of using arrays for the validation of codes such as account and part numbers, GL codes, etc. Our

examples demonstrate two basic approaches to the problem. The first method searches a conventional RPG array, which is loaded with all of the

customer numbers present in the customer master file. The second takes a rather different approach. It takes advantage of the fact that customer

numbers are indeed numbers and uses the number as the index into an array of indicators. The programs have been set up to time their operation

through a number of iterations so we can compare the relative speeds of the different approaches. It may have occurred to you since both of these

approaches utilize arrays, that they're constrained by RPG's limit of 32,767 elements. We'll address that issue in our third example.

Now that you know where we're headed, let's jump into our first program.

H Option(*SrcStmt:*NoDebugIO) DftActGrp(*No)

H BndDir('PARIS/EXTRATOOLS')

FcustMast IF E K DISK

/Copy BASETOOLPR

D LoadCustomerNumbers...

D pr 10i 0

(A) D validCustomer s Like(custNo)

D Dim(32767) Ascend

D customerCount s 10i 0

D searchCust s Like(custNo)

D x s 10i 0

D result s 10i 0

D loopMax s 10i 0

D hits s 10i 0

An Array of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/7216p1.aspx?ht=

4 of 7 9/27/2010 10:50 AM

Page 5: An Array of Arrays _ IBM i ...1

D misses s 10i 0

D splitTimestamp ds

D timestamp z

D timePortion 12a Overlay(timestamp: 12)

/Free

(B) dsply 'Number of test loops to run?' '' loopMax;

StartTimer();

customerCount = LoadCustomerNumbers();

For x = 1 to loopMax;

searchCust = GetRandom( 1: 32000 );

i = %Lookup(searchCust: validCustomer: 1: customerCount);

if i > 0;

hits += 1;

else;

misses += 1;

endIf;

endFor;

(C) timestamp = StopTimer();

dsply ('Total time ' + timePortion );

dsply ('Hits = ' + %Char(hits) + ' - Misses = ' + Char(misses) );

*inlr = *On;

/end-free

(D) P LoadCustomerNumbers...

P b

D pi 10i 0

/Free

read custMast;

Dow not %Eof( custmast );

customerCount += 1;

validCustomer( customerCount ) = custNo;

read custMast;

EndDo;

return customerCount;

/end-free

P LoadCustomerNumbers...

P e

Next page: >>

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

An Array of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/7216p1.aspx?ht=

5 of 7 9/27/2010 10:50 AM

Page 6: An Array of Arrays _ IBM i ...1

How Frontline Homeowners Insurance SOA - Enables their IBM i Policy and Claims Applications

Wednesday, October 13, 2010 - 2pm EST

Browse products and services for Administrator.

Advertisement

Maximize your IT investment with monthly information from THE source...IBM Systems Magazine EXTRA & Marketplace eNewsletters.

An Array of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/7216p1.aspx?ht=

6 of 7 9/27/2010 10:50 AM

Page 7: An Array of Arrays _ IBM i ...1

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

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

An Array of Arrays | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/developer/7216p1.aspx?ht=

7 of 7 9/27/2010 10:50 AM