Don't let CL programs trip you up. These tips show you how to do the following:
1. Retrieving the system date in a CL program
[ Return to top of page ]
You've retrieved the system date (QDATE) using RTVSYSVAL in my CL program and now you need to advance the date by one. How can you do this within the CL program?
Search400.com expert Tim Granatir says, you would have to use the convert date to convert your date to Julian, add 1 to it, check for leap year and make adjustments and then convert it back. A good example of this technique used to be found in the old TAATools in the ADDDAT command. Here is that example. This command has a six-character, date but that can easily be changed with a very slight modification.
2. Retrieving the width value in a file
[ Return to top of page ]
According to site expert Tim Granatir, a quick way to retrieve the width value in the printer file is to make up a small CL program and pass it the file name and library of your print file. In that CL program, execute the following command on your print file. Read that file in your CL program, and then return the values that you want to your calling program.
DSPFD FILE(QSYSPRT) TYPE(*ATR) OUTPUT(*OUTFILE) FILEATR(*PRTF) OUTFILE(QTEMP/QAFDPRT)
3. CL program to obtain IP addresses for all printers
[ Return to top of page ]
A user needed to write a CL program to obtain the IP addresses for all printers (LAN & RMTOUTQ) that they have on their system. The only OS command he could find was WRKOUTQD, but that does not allow output to *file and only one can be specified. He wondered if there is an API that he can call that does that?
Site expert Glen Bunnell says there is a process that you can go through to create this information. Below is an example CL that will create an external file with all the information that's required. You will need t
To continue reading for free, register below or login
To read more you must become a member of Search400.com
');
// -->

o write an RPG program or query to retrieve the desired information. The following are the steps that you need to do in order to make the CL work properly:
1. Create an externally described physical file for use by the CL. Below are the field specifications that will be needed:
2. Execute the following command:
DSPOBJD OBJ(QSYS/QGPL) OBJTYPE(*LIB) OUTPUT(*OUTFILE) OUTFILE(XXXX/DSPOBJ
(Replace the XXXX with the library that you want the information stored into.)
3. Create the following CL:
Replace the XXXX with the library name of where the object was created. Replace the HHHHHH with the name of the file that was created in step one.
4. Run the CL.
5. With the file created in step one, you can use an RPG program, iSeries query or even download the file and get all the necessary information that you need.
4. Determine if a file is empty or not in a CL program (READ FEEDBACK TO THIS TIP)
[ Return to top of page ]
Do you need to know if a file is empty or not in a CL program? Site expert Jim Mason says he isn't aware of any command that returns the number of records in a file, but you could easily create one with these steps.
CHKF (Check file command) to create:
CHKF FILE(MYLIB/MYFILE) NBRRCDS(&NBR)
The second parm in this command definition is a return variable type to return the record number to the caller. Running interactively, this should take about one or two seconds to complete on an iSeries.
In the CL program for your command:
1. DSPFD FILE(&FILENAME) TYPE(*MBRLIST) OUTPUT(*OUTFILE) OUTFILE(QTEMP/FD)
2. In a CALLED CL PGM, open the file QTEMP/FD.
3. Do RCVF cmd on QTEMP/FD. This reads in the first record for the first member in the file. It has a record format (QWHFDML) and 2 fields: MLFILE (filename) and MLNRCD (number of records). You now have the record count of the first member.
4. CHGVAR to set the return CL PGM VAR (&NBRRCDS) from the MLNRCD variable you accessed.
5. Calling a CL program from a VB program
[ Return to top of page ]
Calling a CL program from a Visual Basic program is essentially the same as if you were calling a COBOL or RPG program, according to Search400.com expert Shahar Mor. That means you can call it from VB using the program call object or the QCMDEXC stored procedure. Some good examples can be found here.
And since OLE database is thread-safe, you can run it on the server. That means that you can use the OLE database provider to call the CL program from your asp pages.
User Feedback to "Determine if a file is empty or not in a CL program"
Several Search400.com members wrote to say that you can use the RTVMBRD command to determine the number or records in a file. Here are few code examples:
From Karen Hodge --
From Kathy Adams --
From Bob Abbott --
From Warren Schultz --
From Domenico Finucci --
From Marilyn Spicer --