|
VM provides a
comprehensive scripting language called REXX. If you’re not familiar
with it, read the REXX/VM User’s Guide which contains a very
well-written tutorial for learning this powerful language. Still more
information can be found in the REXX/VM Reference. Here are a few tips
that will make your REXX code easier to maintain and debug.
Include these statements
in your initialization code:
HT =
"HT"
RT =
word("HT RT",cmsflags(cmstype)+1)
This sets the variable
RT
to the current CMSTYPE value. Now if you want to suppress the output of
a CMS command you can code
"SET
CMSTYPE" HT
"COMPARE THIS FILE A THAT FILE A"
SaveRC
= rc
"SET
CMSTYPE" RT
if
SaveRC <> 0 then ...
This code suppresses
any output from the COMPARE command and leaves the current value of
CMSTYPE HT unchanged.
You
probably know about the REXX
trace
statement. There’s also a
trace function
that’s quite useful when debugging. When you’ve completed debugging a
section of code, surround it with trace calls:
TRSave = trace("OFF")
/*
...working code... */
call trace(TRSave)
This disables any tracing
around the working code, and then turns it back on to continue
debugging.
It’s a good idea to
familiarize yourself with the
signal instruction.
It allows you to trap and handle certain conditions, such as non-zero
return codes from system commands or REXX syntax errors. It will also
allow you to trap uninitialized variables. Consider this code:
signal on novalue
/*
code to be tested */
exit
NoValue:
parse source . . EXECfn EXECft EXECfm .
VarName = Condition('D')
queue 'COMMAND :'SIGL
queue 'COMMAND EMSG Variable "'VarName'" is Uninitialized'
address command 'XEDIT' EXECfn EXECft EXECfm
exit
When an uninitialized REXX
variable is referenced, a branch is made to label
novalue where
we XEDIT the EXEC being run, navigate to the line in error, and display
the name of the offending variable in an XEDIT error message. This same
technique can be used for any other condition that
signal
can trap.
Do you have something to add to this tip? Add it
to the VSEWiki page! |