When to Quote Variables in Functions and/or Procedures

[Autolink] Menu

Some functions and procedures need the name of a variable as parameter. They use this variable to store the result. Examples for this type of function are SysFileTree and SysGetEA.

To make sure, that the function/procedure stores the result in the variable you intended, in these functions and procedures you should always enclose the variable name in quotes.

Example:

 
/* */
  call rxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  call SysLoadFuncs
                     /* init some variables for testing                */
   mystem  = 'TEST'
   mystem1 = 4
                     /* correct use of the variable (see below);       */
                     /* because the variable mystem is enclosed in     */
                     /* quotes, mystem.0 will correctly return the     */
                     /* total number of entries matching the wildcard  */
                     /* file spec 'c:\*.*' and mystem.# will contain   */
                     /* the value of each entry (where # is a number   */
                     /* from 1 to the value of mystem.0)               */
   call SysFiletree 'c:\*.*', 'mystem'

                     /* incorrect use of variable; when the variable   */
                     /* mystem is not quoted in the function call,     */
                     /* REXX uses the value of the variable mystem     */
                     /* (i.e., 'TEST', initialized earlier) as         */
                     /* the name of the stem for the result.  Thus,    */
                     /* the value of mystem.0 will be 'MYSTEM.0',      */
                     /* the number of entries matching the wildcard    */
                     /* spec will be stored in test.0, and test.# will */
                     /* contain the entries themselves (where # is a   */
                     /* number from 1 to the value of test.0)          */
   call SysFiletree 'c:\*.*', mystem

                     /* incorrect use of variable; REXX uses the value */
                     /* of the variable mystem1 as the name of the     */
                     /* stem for the result.  This statement will      */
                     /* raise a syntax error because the value of      */
                     /* mystem1 is '4' and variables in REXX cannot    */
                     /* begin with a number. */
   call SysFiletree 'c:\*.*', mystem1


[Back: Using Persistent Variables]
[Next: List all defined variables]