Parameters(), PCount()
These functions tell you how many parameters were passed to a procedure or function, but there's a subtle difference between them.
Usage |
nParmCount = PARAMETERS() nParmCount = PCOUNT() |
Example |
* Demonstrate the difference between PARAMETERS() and PCOUNT() DO rtn1 WITH 1,2,3 DO rtn2 WITH 1,2,3 PROCEDURE rtn1 PARAMETERS a, b, c ? "Parameters() returns", PARAMETERS() && 3 ? "Now I'll use a function" = myudf(a) ? "Now parameters() returns", PARAMETERS() && 1! RETURN PROCEDURE rtn2 PARAMETERS a, b, c ? "Pcount() returns", PCOUNT() && 3 ? "Now I'll use a function" = myudf(a) ? "Now pcount() returns", PCOUNT() && still 3 RETURN PROCEDURE myudf() PARAM x RETURN |
DO rtn1 WITH 1,,3you still get 3 from both PARAMETERS() and PCOUNT().The problem here is that, no matter which way this is handled, the ability to leave parameters out in the middle makes the whole business of parameter checking much harder. As it stands, there's no way to really check which parameters were passed and which were omitted. So you need to be extra careful to check each parameter for validity and not make assumptions about what was passed and what wasn't.
See Also |