Is there any way to pass a varying number of parameters to a CLP, and check how many parameters were passed, as you can in RPG?
Yes, and it is a bit of a kludge in CL -- though in the new ILE CL in V5R3 there is now, I believe, an equivalent to the %PARM BIF. I will assume you mean non-ILE, pre-V5R3 CL.
You need to define TWO sets of variables in the CL source. The first set consists of the actual parameters being passed on the PGM statement. The second set consists of the variables you will actually use in the program.
Usually the only reference you will make to the first set is to use CHGVAR to copy the incoming parameters to your internal copies. After each CHGVAR you must place MONMSG MSG (MCH0000), or MONMSG MSG(MCH3601). Either will trap the error 'Reference to an unpassed parameter'.
After the CHGVARs your internal variables will contain either the values passed or the initial values you set for them.
You can pass values back through the incoming parameters in exactly the same way - just put the MONMSG after the CHGVAR to trap the 'unpassed parameter' error.
This technique is most useful when writing Command Processing Programs for your own commands, where values are returned through RTNVALs to the program running the command -- I have lots of those!
MORE INFORMATION ON THIS TOPIC
The Best Web Links: tips, tutorials and more.
Ask your programming questions--or help out your peers by answering them--in our live discussion forums.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.
Dig Deeper on RPG iSeries programming
Related Q&A from John Blenkinsop
When an error occurs on an IBM command, the diagnostic messages are sent first, then an escape message, which you can monitor. On AS/400 you see the ... Continue Reading
Learn how to 'append data to the file' with the FTP DIR command, and eliminate the hassle of having to end the FTP session and restart to view ... Continue Reading
RPGIV will 'think of' incoming integer fields as binary, and then will redefine them in the program structures as PACKED. So, when you chain a record... Continue Reading