Programming
Free Tools!
The QUSRTOOL library has many unique programs and commands to provide tools which are otherwise not a part of your operating system. QUSRTOOL is not supported as a normal part of the operating system. You cannot call software support and report a bug. To order the QUSRTOOL update or report a bug in one of the tools, have your System Engineer send a note to QUSRTOOL on RCHASA04.
- Tim Johnston
Dynamic Source Member Manipulation
Source physical files may be processed in RPG like a normal database file. This allows a simple method of creating your own tools to provide documentation or even manipulate members. For instance, prior to running FMTDTA the sort specs could be updated with run-time options.
Decimal data errors from "fields" with leading blanks can be avoided by defining them as character and doing a MOVE into the same size numeric field. In RPG, this performs the near equivalent of a "fix decimal data error" compiler option.
- Douglas Handy
A Better DSPPFM
Here's a way that I can view data in a physical file instantly. An alternative to DSPPFM with some attractive benefits is the RUNQRY command. On any command line, type the following:
RUNQRY *NONE libname/filename
A formatted display of the file contents appears. If you prompt RUNQRY command, other parameters allow for record selection and spooling to *PRINT.
- Cynthy Johnson
Formatted Record Dumps
Here's a way to get a formatted dump of records in a physical or logical file:
On any command line type the following:
CPYF LIBNAME/FILENAME TOFILE(*PRINT)
All records in the PF or LF are printed in CHAR format.
CPYF LIBNAME/FILENAME TOFILE(*PRINT) OUTFMT(*HEX)
All records in the PF or LF are printed in CHAR and HEX.
But wait....there's more!!! If you specify a LOGICAL file name, the records are printed in their logical access path order! I use this to help check for duplicate keys. All the select/option parameters of CPYF apply, so you don't have to print all records if the file is very large.
- Cynthy Johnson
What's This Program's Name?
Don't hard-code program names. A CL program can obtain its own name via the following code fragment:
DCL VAR(&SENDER) TYPE(*CHAR) LEN(80) DCL VAR(&PGM) TYPE(*CHAR) LEN(10) DCL VAR(&MSGKEY) TYPE(*CHAR) LEN(4) SNDPGMMSG MSG(' ') TOPGMQ(*SAME) MSGTYPE(*INFO) + KEYVAR(&MSGKEY) RCVMSG PGMQ(*SAME) MSGTYPE(*INFO) SENDER(&SENDER) + RMV(*YES) MSGKEY(&MSGKEY) CHGVAR VAR(&PGM) VALUE(%SST(&SENDER 56 10))
RPG programs can obtain their names from the program status data structure:
....1....+....2....+....3....+....4....+....5....+....6....+ I SDS I *PROGRAM PGM -or- I 1 10 PGM ....1....+....2....+....3....+....4....+....5....+....6....+
- Bryan Leaman
QRYF User Tool
If you have trouble figuring out OPNQRYF string structure, a command in QUSRTOOL called QRYF can help. This command makes the select criteria easier. If you still want to use OPNQRYF instead, run QRYF and after it has run, check the job log. The log will show you the OPNQRYF command structure QRYF created for you. QRYF creates a SNDPGMMSG with the correct OPNQRYF structure inside of it. It's a great way to learn OPNQRYF.
- Dean Hoffman
Two Queries are Better Than One
To improve performance of Query/400 where large files (over 100,000 records) are joined, use paired queries. The first query selects records and uses a database file for output (the choice of "data in file" option is important here). The second query uses the file created by the first query and sorts it, using either a printer or another database file for output. Our query performance improved three to one using this method.
- Debbie DeDuck
Don't Use LDA to Pass Parameters
When submitting a program for processing in batch, pass any data as parameters to the program CALL instead of using the *LDA. This allows you to determine what options were selected for the job by looking at the job log. It also minimizes the possibility of overwriting data in the *LDA written out by third-party software and it eliminates the need to retrieve the information from the *LDA in the batch CL. For example:
SBMJOB CMD(CALL PGM(BPGM01) PARM(&PARM1 &PARM2 ...))
- William MacKenzie Picou
Search Indexes Galore
The Start Search Index (STRSCHIDX) command which supports keyword searches is available for specific areas of interest:
Search Index Library Name Utilities QPDA QHPW1 Query QQRYLIB QHQU1 RPG QRPG QHRG1 Office Vision QOFC QHWP1 RJE Comm. QRJE QHRJE
(Be sure you have authority and that the library is included in your library list.)
- Charles S. O'Rourke, III
Manuals at Your Fingertips
Copy Chapter 7 of the System Programming Reference Summary (Error Messages That Can Be Monitored) from the CD-ROM to a DOS file. Then upload to a source member on the AS/400. The next time you need to know what message to monitor for, use the SEU browse and scan facility to check.
I'll never understand why IBM didn't include this as part of the command prompter or help text!
- Brian Coyle
Subfiles with Pizzazz
While subfiles can be very powerful in how they handle information, in some circumstances they are very limiting. For example, consider a screen design that would display multiple customers and their invoices. This could possibly be done with a fold but the information would be redundant from line to line for a single customer.
The trick that I use is to make a subfile with one field that is as long as is necessary. I format this field in an RPG program before writing it to the subfile. This way I have one line with all the pertinent customer information and underneath it one line for every invoice. But there is one trick that will make this screen look even better.
When I am formatting the subfile line in the RPG program I stick hexadecimal bytes in between the fields depending on what screen attribute would be best, such as color, underline, or reverse image.
This method allows you to use the power of a subfile with the enhancements of selected screen attributes to create a first class screen presentation.
- Rick Romanek
Create Your Own QTEMP
Create a library (SCRATCH) for submitting queries to batch. Users can create queries in this library and then submit them for batch processing. This library is cleared via a nightly/weekly processing routine. Queries can now be submitted instead of running in QTEMP interactively. Temporary queries can be cleaned up automatically.
Use this library for all temporary objects such as DFUs and as a work area for restores.
- Kevin Heiman
Shared Spool Files
If you need to run several programs, each of which creates a report, and want them all in a single print file, you need to override or change your printer file to use a shared access path. If you are using the default printer file QSYSPRT, you could do this with the command OVRPRTF FILE(QSYSPRT) SHARE(*YES). Then you must open the printer file and keep it open. This can be done with a very small RPG program which contains a dummy printer output (99N99 EXCPT), and then executes a RETRN without setting on LR. You will need a dummy MOVE *ON *INLR also, or the RPG will not compile.
Simply call the RPG program at the start of your job, and then execute a RCLRSC at the end (or condition the initial RPG program with an *ENTRY parameter which causes it to actually set LR on when you wish to end printer continuation mode). The main thing is having a shared access path, which remains open during the time you wish to have all printer output directed to the shared spool file entry.
- Kathreen Kruse
INDARA in Display and Printer Files
Use INDARA in display and printer files. This will help you to avoid recompiling display or printer files when you change indicator numbers or move an indicator in the source file. There is no change needed for the RPG program.
- Greg Prior
Query/400 Run-time Record Selection
You can specify record selection at run-time for exisiting Query/400 programs. Simply do:
RUNQRY QRY(query name) RCDSLT(*YES)
When executed, this command presents the Query/400 record selection panel with the previously defined criteria, allowing you to modify or add selection criteria. After the desired changes are made, press Enter to run the query program.
- Eugene Arencibia
One Source File Only
Use a single source file for all of the source for a library or a development project. This keeps you from needing to jump around in different files with PDM.
- Greg Prior
LATEST COMMENTS
MC Press Online