Here’s a fun – and useful – little command you can develop on the iSeries (or IBMi, AS400) in about 2 minutes. Since I use it constantly, I usually include some version of this on every system I work on. I’ll discuss how below.
The RUNQRY command can be utilized to run a raw query on a file (or table) that does not need to be defined using WRKQRY. To do so, simply type in:
runqry *n file_name
on a command line. The *n tells the command interpreter that you are using the default for the first parameter (which in this case is blank or *NONE).
Pressing Enter at this point will run a basic query and show data in it’s raw form – sort of like what you get when you type: select * from file_name in SQL.
Prompted it looks like
If you want to query the file and include record selection, you can enter it like this:
runqry *n file_name rcdslt(*yes)
which appears like this when prompted
Enter: The RQ Command
Early on, I used to name the command Q. However, I found that Q was frequently used by other individuals for other things. So, it became RQ (one more keystroke: 🙂 ). Here’s how to set it up:
( The only issues you may have is whether or not you have the correct authority to do this, and where the command should reside. The target library should be in the regular library list you’ll be use so you don’t constantly have to add the library prior to using the command. I suggest QUSRSYS or QGPL, but your library setup may vary. We’ll use QTEMP for this example so you can see how it works).
First, we use the CRTDUPOBJ command to create a copy of RUNQRY from the QSYS library.
On a command line type in:
crtdupobj runqry *libl *cmd qtemp rq
If you prompt it, it will look like
Next, we’ll change the command default to make it handier. On a command line, type;
chgcmddft qtemp/rq ‘rcdslt(*yes)’
(don’t forget the apostrophes!) Which looks like
What did we do here? The new default for the RCDSLT parameter in RQ is now *YES instead of *NO. You’ll see why in a moment.
To execute the new RQ command, type this into a command line:
rq *n file_name
and press enter. The following will come up;
When you get to the selection screen, you can take a look at the file’s layout – field names and attributes. Sure beats needing to print out a layout or visit the source member every time you want to find something.
If you press Enter at this point, the query will run without any kind of filtering. Or, if you want to subset the data, type in whatever valid selection criteria you want.
The bottom line is we reduced runqry *n file_name rcdslt( *yes)Â to rq *n file_name. We saved 15 or more keystrokes!
How to Use the Command
Frequently, if I’m creating a program where I update a number of fields from a file, I will use the RQ command to display the field names, and then copy/paste them into the programs source member.
While on the record selection screen, you can press F18 to see the record format name as well.
When I’m working in SEU and I need a field name I forgot, Ill just conjure up the F21 command line window, and RQ the file to get the name. Quick and easy!
Now you have useful brand-new command that can perform a lot of functions and increase your productivity. Have fun!
Word of the Day: User Story
In Agile software development, user stories are one of the most important tools for defining work. Rather than writing lengthy requirements documents, Agile teams use short, human-friendly descriptions of functionality from the user’s perspective. A well-crafted user story keeps the focus on what the user needs and why — leaving the how for later in […]