Here’s a fun- and useful – little command you can create on the iSeries (or IBMi, AS400) in about 2 minutes. I usually create some version of this on every system I work on because I use it constantly. I’ll explain how below.
First, the basics.
The RUNQRY command can be used to run a ‘raw’ query on a file (or table) that does not have to be defined using WRKQRY. To do so, all you have to do is type in:
runqry *n file-name. Prompted it looks like
on a command line. The ‘*n’ tells the command interpreter that you are using the default for the fist parameter.
This will list whatever file you’ve typed in in a ‘raw’ format, sort of like what you get when you type:
select * from file-name
If you want to use the query with record selection, your can enter it this way:
runqry *n file-name rcdslt(*yes), which looks like
if the command is prompted.
The RQ Command
I used to always name the command simply ‘Q’, but I found that ‘Q’ was often used by other people. So, it became RQ (one more keystroke :)). Here’s how to set it up:
First, we use the CRTDUPOBJ command to create a copy of RUNQRY. The original RUNQRY is located in the QSYS library, but with CRTDUPOBJ you really don’t need to know that.
(The only issues you might have is whether you have the proper authority to do this, and what library you want to put the command in. The library should be in the common library list you’ll be using so you don’t always have to add the library before executing the command. I suggest QUSRSYS or QGPL, but your library setup may differ. We’ll use QTEMP for this example so you can see how it works).
crtdupobj runqry *libl *cmd qtemp rq.
If you prompt it, it will look like
Great, now you have a duplicate of RUNQRY in QGPL with the name of RQ. But, what good does that do, other than saving 4 key strokes? Nothing until we do this:
chgcmddft qtemp/rq ‘rcdslt(*yes)’. Or
What did we do here? We changed the default that was included with RUNQRY for the RCDSLT parameter from it’s default of *NO to *YES. We’ve moved from having to enter
runqry *n file-name rcdslt(*yes)
rq *n file-name
How to Use the Command
Of course, the most obvious is to look at raw file data.
If you want to view a file, in a formatted columnar style (like SQL), just type in the command and hit Enter twice.
If you want to search for values using the record selection screen, type in the command and hit Enter once. Type in your selection criteria, his Enter again, and you’re golden.
But, that’s not the RQ command’s only use.
When you get to the selection screen, you can look at the file’s layout – field names and attributes. Sure beats having to print out a layout or visit the source member every time you want to find something.
At the selection screen you can press F18 to see the record format name.
Quite often, if I’m writing a program where I need to load several fields from a file, I will use the RQ command to display the field names, and then copy/paste them into the program’s source member.
Other times, when I’m working in SEU and I need a field name I forgot, I’ll just invoke the F21 command line window, and RQ the file to get the name. Quick and easy!
Of course, the other parameters can be used, as needed, to dump the file to a printer or outfile (same as RUNQRY).
So, now you have handy new command that can perform a ton of functions and increase your productivity. Have fun!
Copyright 2015 WallyDay.com