• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • 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

    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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Maxava

    Migrate IBM i with Confidence

    Tired of costly and risky migrations? Maxava Migrate Live minimizes disruption with seamless transitions. Upgrading to Power10 or cloud hosted system, Maxava has you covered!

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    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

    Mainsoft Supports Visual Studio 2005, Mono 1.2 with Updated Grasshopper IBM Upgrades System i5 Disk Controllers, Adds Enclosures

    Leave a Reply Cancel reply

Volume 7, Number 4 -- January 31, 2007
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

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle