We have all had the situation where we needed to print or display IBM i data from CA 2E (Synon) in some odd way. Usually this meant creating a work file, loading it and building a report or display over the work file. Eventually you might end up with several one-off tables, sometimes with very little difference between them.
There is another solution: arrays. Now I know you are saying, “But you can’t build a screen/report over an array.” True, but you can build a single work file that can be used by any number of processes, and here’s how.
You start by creating a table. Let’s call it the Array Display File. It’s going to have one field, a 5.0 NBR field (since arrays are still limited to 9999 elements).
You will need to load the table with numbers from 1 to 9999. You can use your preferred method (SQL, YWRKF, intern, program). I use a program only because it’s an easy way to ensure someone else can come along after you and recreate the data.
Let’s say you need to display a list of spool files for a user sorted by date descending. I would start by creating two arrays, the first my needed fields and keyed/sorted in the order I want (create date (d)(k), create time (d)(k), file name, user date, job details, output queue). I would create the second to be the same as the first, except I would add the Array Display Key field and make it my key. Load the first array with the spool file data. Once that is done, you can read the ordered data and load the second array for display (most recent spool file is assigned sequence number 1 in the second array and so on down the line.
Create a display file over the Array Display File and in the initialize subfile record user point, read the corresponding record from the second array you created.
If you want to print, create a print file/print object of the Array Display File, in the user point Print Details read the corresponding record from the array.
By Eamonn Foley