Sorting Arrays and Subfiles with a User Index
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
QUSADDUI–Add User Index Entries
QUSRTVUI–Retrieve User Index Entries
Note: When index records are returned, ignore the first eight bytes of data (contain some type of hex index information). RELATED STORIES
|