Q
Problem solve Get help with specific problems with your technologies, process and projects.

Pass a varying number of parameters to a CLP

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.


This was last published in September 2004

Dig Deeper on RPG iSeries programming

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close