Question

  Asked: Jan 29 2008   11:00 PM GMT
  Asked by: Piano


Passing Parameters into a clle program from a Menu.


%PARMS, OPTIONS(*NOPASS), CLLE

Hello

I am wondering if there is a way to pass parameters from a menu into a CLLE program, whereby the parameter list could be variable. Most Menu options will pass one parameter to the CLLE program; namely the program name that will be called if security is passed. (PARM 1)

But, there are some menu options that already have parms passed into the CLLE program. So, I will need to pass additional parameters to the program, in addition to the program name. (PARM 1).

Rather than clone the CLLE program into a program that has one parm for the program name, and then additiional variable names would need to be declared and set with certain default values, prior to calling the RPG ILE program, I am wondering if there is a way to do this without having to create an additional CLLE program.

Thanks for your assistance

-Nick

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0



If I understand your request correctly, you want one CL program which can take from 1 to N parameters and then call the program name specified in the first parameter and passing parameters 2 through N (if they were passed to the CL program) to the specified program. If so, this should accomplish that goal:


Pgm Parm(&Pgm_Name &P1 &P2 &P3 &P4)
Dcl Var(&PGM_NAME) TYPE(*CHAR) LEN(10)
Dcl Var(&P1) Type(*Char) Len(1)
Dcl Var(&P2) Type(*Char) Len(1)
Dcl Var(&P3) Type(*Char) Len(1)
Dcl Var(&P4) Type(*Char) Len(1)
Dcl Var(&Temp) Type(*Char) Len(1)

ChgVar Var(&Temp) Value(&Pgm_Name)
MonMsg MsgID(MCH3601) Exec(Do)
RcvMsg MsgType(*Last)
SndPgmMsg +
Msg('Program name is a required parameter') +
ToPgmQ(*Ext)
Return
EndDo

ChgVar Var(&Temp) Value(&P1)
MonMsg MsgID(MCH3601) Exec(Do)
RcvMsg MsgType(*Last)
Call Pgm(&Pgm_Name)
Return
EndDo

ChgVar Var(&Temp) Value(&P2)
MonMsg MsgID(MCH3601) Exec(Do)
RcvMsg MsgType(*Last)
Call Pgm(&Pgm_Name) Parm(&P1)
Return
EndDo

ChgVar Var(&Temp) Value(&P3)
MonMsg MsgID(MCH3601) Exec(Do)
RcvMsg MsgType(*Last)
Call Pgm(&Pgm_Name) Parm(&P1 &P2)
Return
EndDo

ChgVar Var(&Temp) Value(&P4)
MonMsg MsgID(MCH3601) Exec(Do)
RcvMsg MsgType(*Last)
Call Pgm(&Pgm_Name) Parm(&P1 &P2 &P3)
Return
EndDo

Call Pgm(&Pgm_Name) Parm(&P1 &P2 &P3 &P4)
EndPgm


This sample only takes up to 4 optional parameters, but you should be able to easily extend this logic to any number that is needed.

One assumption in this sample is that you are only passing the simple program name in the first parameter and not a qualified program name. If you need to use a qualified program name then you will need to enlarge and reformat the value of &Pgm_Name to meet the requirements of the PGM parameter of the CALL command.

Within ILE there is the ability to dynamically create a variable length argument list using MI instructions such as CALLPGMV, but an approach using this support would be more appropriate for an ILE language such as RPG. In the case of CL the real work is touching and monitoring for the absence each parameter rather than actually passing the parameter. With RPG built-in %Parms support I would be tempted to take a different approach than the above example.

Bruce Vining
http://www.brucevining.com/


It was mentioned in the original request for a CLLE program, but I just wanted to add that this MUST be compiled as CLLE in order to work. You will get an error that the number of parameters was incorrect if you compile it as CLP and try to call it with fewer parameters than were defined.
Kevin C. Ketzler
Affiliated
  • AddThis Social Bookmark Button

Browse more Questions and Answers on AS/400.

Looking for relevant AS/400 Whitepapers? Visit the Search400.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Vatchy  |   Jan 30 2008  4:14PM GMT

Three alternative answers:

1) Go back to the System/36 days and use the local data area to pass parameters. They won’t mean anything to any program that doesn’t check for them.

2) Use a data area to pass parameters.

3) Use a data queue to pass the parameters.

 

Vatchy  |   Jan 30 2008  4:17PM GMT

For the answers I proposed, I am assuming that you are not using the native AS/400 menu format since it has almost no security. I write all of my menus in CL.

 

Sloopy  |   Jan 31 2008  3:32PM GMT

I have used Bruce Vining’s method before, in situations where a variable number of parameters must be passed.

It is worth pointing out that, although in Bruce’s example code the data parameter variables are length 1, the HLL programs that receive the parameters through the CALL operation can actually declare their parameters as whatever lengh and data type they like.

This is because the parameters are passed by address, and not by value. So you can call Bruce’s program like this:

CALL BRUCEPGM PARM(’MYPGM’ ‘MYDATA’ 0000123′)

Bruce’s program will call MYPGM and pass the parameters ‘MYDATA’ and 0000123 BY ADDRESS. If you looked into Bruce’s program in debug, you would see the value ‘M’ in &P1 and hex 00 in &P2.

In the program MYPGM the parameter list would declare the first parameter as character length 6, and the second parameter as 7 digit packed decimal. Debugging MYPGM would show those parameters contain the correct values.

Of course, you have to be careful with this. If you declared the first parameter in MYPGM as character length 7, the value in it would (probably) be ‘MYDATA?’, where ? = hex 00 - it is actually seeing the first character of the next parameter value. So, padding of character values and correct lengths of numerics is required with this method.

So, using Bruce’s program, you can pass different types and lengths of parameter values whenever you call it, depending on which HLL program will be called by it.

John Blenkinsop
NSRI London