Link to home
Start Free TrialLog in
Avatar of Matthew Roessner
Matthew Roessner

asked on

IBM i - CL Array

Does anyone know if it is possible to create, sort, and read from arrays within CL on the IBM i?  I am currently running V7R1.

Basically I am creating a program that will write out all *PGM objects within a given library and display the last change date for that object.  (this is for our SOX auditors).

I have the program created easily enough and I wrote everything to a .CSV file in the IFS.  However, our auditors are ultimately looking for the most recently changed object in a given library. So for them to get that from my spreadsheet, they would have to open it up, and highlight everything - and then do a SORT on the CHANGE DATE "column".

I was wondering if - before I wrote the data to the outfile - I could write all the data to an array and then after everything was written to the array, sort the array based on the Change Date, and then read back through the array so that I can then write the output to my .csv file in the IFS.

Anyone have any idea if that is possible using CL? I know you can do that sort of thing with COBOL and RPG - but was hoping to accomplish this with just CL.

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Gary Patterson, CISSP
Gary Patterson, CISSP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_276102
Member_2_276102

I can think of various ways to sort data with CL.

For example. various types of sort algorithms can be fairly directly implemented with ILE CL coding.

I've also used the QLGSORT API, which can sort files or input buffers such as an array in memory. The biggest problem with it is that it's so flexible that it has a large set of control parameters. It gets complicated. It's not especially fast, but it doesn't matter with a small data set.

Or maybe you could simply insert your array entries into a keyed user index. Define the key according to your sort key. Then just retrieve the entries back out in key sequence.

One thing I haven't tried but should be doable would be use Qshell sort. It could be tricky getting your array into and out of the "file" format that sort wants, but it's possible to access a user space in Qshell as a "file". If the array is based on a pointer to the space, it could probably be made to work.

Other than those thoughts, it might depend on your array data definitions. Can you post enough code for us to know what is needed? Also, what's the maximum number of entries are you looking at? At least one other thought might depend on info you can add.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PGM
RUNSQL     SQL('create table MyLib.TheTarget as ( +
                select * +
                  from MyLib.TheSource +
                 order by someColumn +
                ) with data')
ENDPGM

Open in new window

Avatar of Matthew Roessner

ASKER

Thanks Gary