A special variable is one that may be set automatically during processing of a REXX program. There are three special variables: RC, RESULT, and SIGL. None of these has an initial value, but the program may alter them. (For information about RESULT, see page RETURN.)
For ERROR and FAILURE, the REXX special variable RC is set to the command return code, as usual, before control is transferred to the condition label.
For SIGNAL ON SYNTAX, RC is set to the syntax error number.
Following any transfer of control because of a CALL or SIGNAL, the program line number of the clause causing the transfer of control is stored in the special variable SIGL. Where the transfer of control is because of a condition trap, the line number assigned to SIGL is that of the last clause processed (at the current subroutine level) before the CALL or SIGNAL took place. This is especially useful for SIGNAL ON SYNTAX when the number of the line in error can be used, for example, to control a text editor. Typically, code following the SYNTAX label may PARSE SOURCE to find the source of the data, then call an editor to edit the source file positioned at the line in error. Note that in this case you may have to run the program again before any changes made in the editor can take effect.
Alternatively, SIGL can be used to help determine the cause of an error (such as the occasional failure of a function call) as in the following example:
signal on syntax
a = a + 1 /* This is to create a syntax error */
say 'SYNTAX error not raised'
exit
/* Standard handler for SIGNAL ON SYNTAX */
syntax:
say 'REXX error' rc 'in line' sigl':' "ERRORTEXT"(rc)
say "SOURCELINE"(sigl)
trace ?r; nop
This code first displays the error code, line number, and error message. It then displays the line in error, and finally drops into debug mode to let you inspect the values of the variables used at the line in error.