fhg
Volume 7, Number 4 -- January 31, 2007

Sorting Arrays and Subfiles with a User Index

Published: January 31, 2007

Hey, Ted:

I'd like to suggest another method Jennifer can use for sorting arrays. Why not use a user index? I use user indexes so the user may sort subfiles umpteen different ways. Using a user index eliminates the need to be concerned with size (unless you have more than 4 GB of data). Maybe size would not be an issue in Jennifer's daily run shipping application.

--Drew at BIC Graphic USA


Note: the code from this article is available for download


Drew sent me some illustrative code and a short write-up about the three API's he uses--Create a User Index (QUSCRTUI), Add User Index Entries (QUSADDUI), and Retrieve User Index Entries (QUSRTVUI). I fleshed out the code, adding the calculations to read file QCUSTCDT (an example file you will find in library QIWS) and print out the sorted data. You can download the code here. It should compile and run, sorting the data on customer number. Here's the output I got.

192837    Lee      F L Hector 
389572    Stevens  K L Denver 
392859    Vine     S S Broton 
397267    Tyron    W E Hector 
475938    Doe      J W Sutter 
583990    Abraham  M T Isle   
593029    Williams E D Dallas 
693829    Thomas   A N Casper 
839283    Jones    B D Clay   
846283    Alison   J S Isle   
938472    Henning  G K Dallas 
938485    Johnson  J A Helen

It's worth taking a minute to look at the parameter lists for the APIs, so I've included Drew's tables below. Once you've set them up in one program, they should be easy to adapt to other programs. Also, I recommend you check out Bruce Guetzkow's article on user indexes. The link to that story is below in the Related Stories section.

--Ted


QUSCRTUI--Create User Index


Parameter

Description

IndexName

Name of index - user name plus QTEMP library

ExtendAtr

Blanks for the extended attribute

EntLenAtr

‘F’ for fixed length – can also be ‘V’ for variable length

EntLength

Length of the index data

KeyInsert

‘1’ for insertion by key – can also be ‘0’ for no insertion by key

KeyLength

Length of key

ImmdUpdat

‘1’ for immediate update – can also be ‘0’ for no immediate update

Optimize 

‘1’ for optimize for sequential references – can also be ‘0’ for optimize for random references

PubAuthor

‘*ALL’ for allowing user to perform all operations on the index

TextDesc 

Text description of the index

Replace  

‘*YES’ for replace index of the same name and library

APIError

Error data structure


QUSADDUI--Add User Index Entries


Parameter

Description

ReturnLib 

Name of library of index which entries were added

NumbAdded 

Number of entries successfully added

IndexName 

Name of index – user name plus QTEMP library

ActionType

Type of insert to be performed – 3 for insert without replacement – can also be 1 for insert for non-key or 2 for insert with replacement

IndexData 

Actual entry or entries – name of data structure that holds the data

IndexLen  

Length of entry of entries

LenOffSet 

Used for variable length indexes

NumbEntry 

Number of entries to be added

APIError  

Error data structure


QUSRTVUI--Retrieve User Index Entries


Parameter

Description

RcvVar    

The variable that is to receive the data – name of the data structure

RcvVarLen 

Length of the receiver variable

RcvLenOff 

Entry offset used to parse through the receiver variable

RcvVarOffL

Length of entry offset

NumbReturn

Number of entries returned

ReturnLib 

Name of library of index which entries were retrieved

IndexName 

Name of index – user name plus QTEMP library

FmtName   

Format of index information – IDXE0100

MaxNbrEnt 

Maximum number of entries to be returned

SearchType

Type of search to be performed – 2 for greater than – can also be 1 for equal, 3 for less than, 4 for greater than or equal, 5 for less than or equal, 6 for first, 7 for last, and 8 for between

SearchKey 

Search criteria – the key

SearchLen 

Length of the search criteria

SearchOff 

Search criteria offset – *Zero – ignored unless search type is 8

APIError  

Error data structure


Note: When index records are returned, ignore the first eight bytes of data (contain some type of hex index information).


RELATED STORIES

Dynamically Sized Arrays

Easy-to-Use User Indexes



                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
IBS

Simplify the business of doing business

IBS INTEGRATOR opens up a world of
business possibilities. It's an IT solution that
can connect your company with
information from anywhere, in any format,
from legacy systems to new
business partners across the globe.

                                         · More than 250 powerful functions and features.
                                         · Supply chain integration with flexibility.
                                         · Powerful integration for all businesses.

Visit www.ibsus.com to learn more!


Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

COMMON:  Join us at the 2007 conference, April 29 – May 3, in Anaheim, California
New Generation Software:  Leading provider of iSeries BI and financial management software
Twin Data:  System console control for AS/400s and LPARs from a LAN, WAN, VPN, or via Internet


Books on Sale at the IT Jungle Store: 30 Percent Off for 30 Days

The System i Pocket RPG & RPG IV Guide: List Price, $69.95; Sale Price, $49.00
The iSeries Pocket Database Guide: List Price, $59.00; Sale Price, $41.00
The iSeries Pocket Developers' Guide: List Price, $59.00; Sale Price, $41.00
The iSeries Pocket SQL Guide: List Price, $59.00; Sale Price, $41.00
The iSeries Pocket Query Guide: List Price, $49.00; Sale Price, $34.00
The iSeries Pocket WebFacing Primer: List Price, $39.00; Sale Price, $27.00
Migrating to WebSphere Express for iSeries: List Price, $49.00; Sale Price, $34.00
iSeries Express Web Implementer's Guide: List Price, $59.00; Sale Price, $41.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95; Sale Price, $56.00
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00; Sale Price, $62.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00; Sale Price, $34.00
WebFacing Application Design and Development Guide: List Price, $55.00; Sale Price, $38.00
Can the AS/400 Survive IBM?: List Price, $49.00; Sale Price, $34.00
The All-Everything Machine: List Price, $29.95; Sale Price, $21.00
Chip Wars: List Price, $29.95; Sale Price, $21.00

 

The Four Hundred
The Vanishing IT Woman--System i Women Respond

IBM Sells Printing Division to Ricoh for $725 Million

IT Salaries Rise by 5.2 in 2006, Dice Survey Says

As I See It: Measuring What Counts

The Linux Beacon
Novell Says SLED Is Better Than Windows Vista

AMD: Native Quad Core Opteron Will Best Intel Quasi Quads

IT Salaries Rise by 5.2 in 2006, Dice Survey Says

Ask TPM: The Economics of Open Source Software

Four Hundred Stuff
Idiom Translates Globalization Software into Strong Growth

PowerTech Looks to OpenService for Cross-Platform Security

Notes-Domino 8 Beta On Deck, Mid-Year GA Still on Schedule

mrc Hits the Throttle with Development Tools

Big Iron
IBM Buys Softek to Bolster Data Migration Offerings

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
January 27, 2007: Volume 9, Number 4

January 20, 2007: Volume 9, Number 3

January 13, 2007: Volume 9, Number 2

January 6, 2007: Volume 9, Number 1

December 30, 2006: Volume 8, Number 50

December 23, 2006: Volume 8, Number 49

The Windows Observer
Microsoft Keeps the Pressure on IBM's Notes, Domino

IBM Lotus Adds Handles to Information Overload

Symantec Expands Performance Management Software

Salesforce.com Reports AppExchange Milestone

The Unix Guardian
Sun Profits in Fiscal Q2, Gets $700 Million Equity Injection from KKR

Sun, Intel Form Alliance for Xeon Servers and Workstations

IBM Closes Out 2006 With a Strong Fourth Quarter

The X Factor: Solaris Versus Linux Support Pricing

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

Profound Logic Software
IBS
WorksRight Software



TABLE OF CONTENTS
Finding the Last Transaction for a Customer

Sorting Arrays and Subfiles with a User Index

When Fix Central Won't Let You Download PTFs

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Populate fields with file

Alert emails from iSeries

READC SUBFILE

CL Question on Overrides

Self referencing trigger





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement