Passing Parameters into a clle program from a Menu.

520 pts.
Tags:
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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

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

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Vatchy
    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.
    1,410 pointsBadges:
    report
  • Vatchy
    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.
    1,410 pointsBadges:
    report
  • Sloopy
    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
    2,195 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following