%PARMS built-in function
The return number of parameters built-in function (%PARMS) returns the number of parameters that were passed to the program in which %PARMS is used.
The %PARMS built-in function can be used anywhere that CL supports an arithmetic expression. %PARMS can be used alone or as part of a more complex arithmetic expression. For example, %PARMS can be used to compare the number of parameters that were passed to the program to a numeric CL variable in the COND parameter of an IF or WHEN command. %PARMS can also be used to set the value of a CL command parameter, if the associated command object defines the parameter with EXPR(*YES) and TYPE of *DEC, *INT2, *INT4, *UINT2, or *UINT4.
%PARMS()
When %PARMS is used in a program that was called by a bound call, the value returned by %PARMS is not available if the calling program or procedure does not pass a minimal operational descriptor. The ILE CL or ILE RPG compiler always passes one, but other languages do not. So if the caller is written in another ILE language, it will need to pass an operational descriptor on the call. If the operational descriptor is not passed, the value returned by %PARMS cannot be trusted. The value returned by %PARMS will be -1 if the system can determine that the operational descriptor was not passed, but in some cases when the system cannot detect this, the value returned by %PARMS may be an incorrect value that is zero or greater.
The following examples are about the return number of parameters built-in function:
- Return number of parameters when the program was called by a program call by
CALL. The name of the following program is
PARMSTESTS.
PGM PARM(&PARM1 &PARM2 &PARM3) DCL VAR(&PARM1) TYPE(*DEC) LEN(5 2) DCL VAR(&PARM2) TYPE(*CHAR) LEN(10) DCL VAR(&PARM3) TYPE(*INT) SELECT WHEN COND(%PARMS() *EQ 0) THEN(DO) SNDPGMMSG MSG('0 parm was passed in') GOTO LP0 ENDDO WHEN COND(%PARMS() *EQ 1) THEN(DO) SNDPGMMSG MSG('1 parm was passed in') GOTO LP1 ENDDO WHEN COND(%PARMS() *EQ 2) THEN(DO) SNDPGMMSG MSG('2 parms were passed in') GOTO LP2 ENDDO WHEN COND(%PARMS() *EQ 3) THEN(DO) SNDPGMMSG MSG('3 parms were passed in') GOTO LP3 ENDDO OTHERWISE CMD(GOTO CMDLBL(LPE)) ENDSELECT LP3: SNDPGMMSG MSG('parm3:' *BCAT %CHAR(&PARM3)) LP2: SNDPGMMSG MSG('parm2:' *BCAT &PARM2) LP1: SNDPGMMSG MSG('parm1:' *BCAT %CHAR(&PARM1)) RETURN LP0: SNDPGMMSG MSG('no parameter at all!') RETURN LPE: SNDPGMMSG MSG('error in %parm()') ENDPGM
The output of the above program is:PGM DCL VAR(&VARDEC) TYPE(*DEC) LEN(5 2) VALUE(123.45) DCL VAR(&VARCHAR) TYPE(*CHAR) LEN(10) + VALUE(OUTERPGM) DCL VAR(&VARINT) TYPE(*INT) VALUE(-123) CALL PGM(PARMSTESTS) PARM(&VARDEC &VARCHAR + &VARINT) ENDPGM
3 parms were passed in parm3: -123 parm2: OUTERPGM parm1: 123.45
- Return number of parameters when the program was called by a bound call by
CALLPRC. Still use program PARMSTESTS in the above
example.
The output of the above program is:PGM DCL VAR(&VARDEC) TYPE(*DEC) LEN(5 2) VALUE(123.45) DCL VAR(&VARCHAR) TYPE(*CHAR) LEN(10) + VALUE(OUTERPGM) DCL VAR(&VARINT) TYPE(*INT) VALUE(-123) CALLPRC PRC(PARMSTESTS) PARM((&VARDEC)) ENDPGM
1 parm was passed in parm1: 123.45
- Return number of parameters when the program was called by another ILE language, such as ILE C.
Still use program PARMSTESTS in the above
example.
The output of the above program is:#include <stdlib.h> #include <stdio.h> #include <decimal.h> void PARMSTESTS (decimal(5,2)*, char*, int*); #pragma descriptor (void PARMSTESTS (void, "", void)) int main(void) { decimal(5,2) vardec = 123.45; char varchar[10] = "OUTERPGMC"; int varint = -123; PARMSTESTS(&vardec, varchar, &varint); return 0; }
3 parms were passed in parm3: -123 parm2: OUTERPGMC parm1: 123.45
- If you specify the special value *OMIT for any parameter in the parameter list in a bound call
by CALLPRC, the number of *OMIT will count in the return number of parameters by
%PARMS. Add MONMSG MCH3601 before the fist execution statement in
PARMSTESTS.
The output of the above program is:PGM DCL VAR(&VARDEC) TYPE(*DEC) LEN(5 2) VALUE(123.45) DCL VAR(&VARCHAR) TYPE(*CHAR) LEN(10) + VALUE(OUTERPGM) DCL VAR(&VARINT) TYPE(*INT) VALUE(-123) CALLPRC PRC(PARMSTESTS) PARM((&VARDEC) (*OMIT) (*OMIT)) ENDPGM
3 parms were passed in Pointer not set for location referenced. Pointer not set for location referenced. parm1: 123.45