Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IBM i - CL Array

Posted on 2016-08-25
5
Medium Priority
?
200 Views
Last Modified: 2016-08-25
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!
0
Comment
Question by:Matthew Roessner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 35

Accepted Solution

by:
Gary Patterson earned 2000 total points
ID: 41770991
Short answer - still no native arrays support in CL.  You can "roll your own" using pointers, but that's a lot of work and error-prone.

Why not just use SQL to sort your output?

CREATE TABLE QTEMP/myoutput as (select lib, object, date_changed from mylib/dspobjd order by lib,date_changed, object) with data

Then use CPYTOIMPF to generate a CSV from the QTEMP/myoutput table.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 41770997
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.
0
 
LVL 35

Assisted Solution

by:Gary Patterson
Gary Patterson earned 2000 total points
ID: 41771012
Forgot to mention:  

Depending on the TR level you're on, look at the QSYS2.OBJECT_STATISTICS view.  It contains much of the info found in DSPOBJD, and that means that you could do all of this with a single SQL statement and a CPYTOIMPF command.

https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/IBM+i+Technology+Updates/page/QSYS2.Object_Statistics+table+function+ease+of+use
0
 
LVL 18

Expert Comment

by:Dave Ford
ID: 41771013
PGM
RUNSQL     SQL('create table MyLib.TheTarget as ( +
                select * +
                  from MyLib.TheSource +
                 order by someColumn +
                ) with data')
ENDPGM

Open in new window

0
 
LVL 1

Author Closing Comment

by:Matthew Roessner
ID: 41771023
Thanks Gary
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What we learned in Webroot's webinar on multi-vector protection.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question