When programming in RPGLE it is possible not to pass all the parameters between programs or procedures, using *OMIT in the calling code and %PARMS in the called code. The same functionality is not available in CL.
I needed to make a modification to an existing CL program, which is called from many other programs. If it was called from one program I needed to pass a parameter to it, if it was called by the others I did not need to use the parameter as a default value is used. I needed to make this quickly, before today’s night run. It would take too long to:
- Identify all the programs that call the program I need to modify.
- Change all the programs.
- Have all the programs tested by the IT tester.
- Prepare and stage them all for the move into production.
- Find an authorized person to move them all into production.
Was there a way I could just modify the two programs, the one calling program with the parameter and the called program, in a way that if the called program was called without the parameter it would not error? That way only two objects would need to be modified, tested, staged, and deployed, and I could be done in time.
The error MCH3601 occurs if you call a program passing no or too few parameters. Therefore, if I could monitor for that message I could know if the parameter was passed. I also found that you cannot use the "passed" variable unless it was used when the program was called.
With this in mind I can create a program that looks like:
01 PGM PARM(&P_FLD) 02 DCL VAR(&P_FLD) TYPE(*CHAR) LEN(10) 03 DCL VAR(&FLD) TYPE(*CHAR) LEN(10) 04 CHGVAR VAR(&FLD) VALUE(&P_FLD) 05 MONMSG MSGID(MCH3601) + EXEC(CHGVAR VAR(&FLD) VALUE('Default'))
I have defined two variables, &P_FLD and &FLD, which are defined identically. &P_FLD is the passed parameter. On line 4 I try to move the value in &P_FLD to &FLD. If a value was passed this line executes without error. If no value was passed the line errors, which is caught by the monitor message on line 5, and the default value is moved to &FLD.
This article was written for IBM i 7.1, and it should work with earlier releases too.