Lightly Seared On The Reality Grill

Random expat geekery from The Low Countries

Browsing Posts tagged CL

The IBM i CL command Reorganize Physical File Mbr (RGZPFM) removes deleted records from a specified member of a physical file and, optionally, reorganizes that member. It’s a handy command to know about but reorganising physical files member by member can become a very painful process if you have a lot of files to reorganise (after manually purging a large volume of test data, for example).

I did, at a previous employer, have access to a RGZLIB command. This reorganised all of the physical files in a library and made for a much more convenient purge. Unfortunately, this is ont a system supplied CL command and my current emplyer doesn’t have it.

So I wrote my own version.

RGZLIB is a simple command that will reorganise all of the physical file members in a selected library. Depending on the size of the library to be reorganised (and the size of the files in that library) this process can take a while to run, so I strongly suggest that you submit the command to batch.

My original plan was to write this in RPG and include some additional file clean-up options. However, it turns out that there is no API to retrieve a list of files in a library so the program, as it stands, is a very simple CL affair. If I do code up the additional functionality, I will put it into a seperate command to avoid over-complicating things.

As ever, the source is available on GitHub and you are free to browse or download it from there.

flattr this!

Fun with QShell

No comments

One thing that a lot of people fail to realise is that the IBM i includes a command environment based on POSIX and X/Open standards. This environment is known as QShell and consistes of two parts:

  • The shell interpreter (qsh) reads commands from an input source, interprets each command, and then runs the command using the services of the operating system.
  • The ulilities – external programs that provide additional functions.

You can use the QShell interactively, but the fun begins when you start integrating it with CL.

The below example is used in an interface that retrieves an FTP file from one location, processes it, and then sends the results on to another location. We wanted to retain the FTP logs and, for reasons best left unexamined, the powers that be decreed that these logs should accumulate in a database file. And they should have a timestamp.

Capturing the FTP log is a straightforward case of overriding the Output file to the log file/member. Including a timestamp is where the Qshell fun comes in.

Click here to see the sample subroutine

Member FTPLOG in file FTPLOGFILE is where the FTP logging data will be captured. This member is then copied to the permanent member as decreed by the PHB.

The example should speak for itself but what I am doing is creating an alias to the FTPLOG member, writing a single line to that member with a timestamp retirieved from the DateTime System value, and then dropping the alias.

If you want to get started with QShell, the best approach is to type Strqsh from a command line and then type help.

flattr this!

There are times (month end, for example) when you need to know which users of an application are signed on so you can respond accordingly. Reliably enough, the iSeries provides all the APIs you need to achieve this.

There are two APIs you need to know about:
QUSLJOB – List Job, generates a list of some or all jobs on the system. This information can be pushed into a user space.
QUSRTVUS – Retrieve User Space, pulls the information out of the user space.

The CL program, below the fold, shows these APIs in action. It does work, although it won’t make any changes – I’m still waiting for final approval to go ahead and write this – and I have filed off a few serial numbers to avoid copyright problems. Feel free to copy it, compile it and modify it according to your own needs. If you have any comments, feedback is always appreciated.

What the program does is read through a table of application users (USERTABLE) and, for each USERID, lists all active jobs for that user in a user space. A nested loop (at Label STEP01A) loops through each job found to retrieve the essential data.

What you do with this retrieved job information is up to you, but I’m thinking in terms of disabling the profile and ending the job.

Update: I’ve just noticed that copying and pasting the code into WordPress causes more than a few oddities in the rendering. So I’ve moved the code into a text file which you can download here: RtvActJob.CLLE

flattr this!