Distinguish between empty and omitted parameter

[Autolink] Menu

You can check if a parameter has been ommitted using the function ARG. This is useful if you work with default values for parameter and if an empty string is a valid value for a parameter.
(Note that this is only possible in internal or external REXX functions or procedures!)

Example:

 
/* sample code to show how to distinguish between omitted and       */
/* empty parameter                                                  */

                    /* call the subroutine with omitted and empty   */
                    /* parameter                                    */
  call TestRoutine  '', 'v2', , 'v4'

exit

/* sample sub routine                                               */
TestRoutine:
  parse arg v1, v2, v3, v4, v5

  do i = 1 to 5
    if arg( i, 'E' ) = 1 then
    do
      say 'Parameter ' || i || ' was entered. '
      say '  The value is "' || arg( i ) || '"'
    end
    else
      say 'Parameter ' || i || ' was omitted. '
  end /* do i = 1 to 4 */
return


[Back: Parameters ...]
[Next: Using %0 ... %9 with OS/2 commands]