RATE THIS ANSWER
+1
Click to Vote:
1
0
Last Answered:
Jan 30 2008 2:32 PM GMT
by BigKat
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