MainframeSupports
tip week 7/2020:

If you ever executed DB2 commands from REXX you most likely have encountered weird problems and strange messages occuring if the call to DSN fails. Such a simple thing as misspelling the DB2 subsystem name can trigger the problems.

For many years I have ignored those problems. If it had been essential for me to avoid the problems I have used a CLIST instead (yes, you really read CLIST). Then recently I was seized by the sacred fire and decided to do something about it. CLIST out, pure REXX programming in.

The strange messages originates from the interface between REXX and DSN using the builtin stack in REXX. If the stack contains data when your REXX terminates the remaining data on the stack will be executed as TSO commands. Most of the commands known to DSN are not known to TSO and thus TSO replies with error messages, but it looks like it is your REXX issuing these error messages. The solution is to empty the REXX stack before termination of your REXX program. I have made a small example issuing a -DIS UTIL(*) and printing the result:

/* REXX DISUTIL */
ARG SSID
PUSH "END"
PUSH "-DIS UTIL(*)"
CALL MSG('ON')
CALL OUTTRAP('COMMAND.')
ADDRESS TSO "DSN SYSTEM("SSID")"
CALL OUTTRAP('OFF')
CALL MSG('OFF')
DO LINENO = 1 TO COMMAND.0
  SAY COMMAND.LINENO
END
DO LINENO = 1 TO QUEUED()
  PULL
END
EXIT

If you execute this REXX named DISUTIL you will call it using TSO %DISUTIL DB2A if your subsystem is named DB2A. First thing is to tell the REXX stack what is the last command you want DSN to execute. This is why the REXX starts with PUSH "END". Next thing is to push the second last command and so forth. When everything has been put on the stack you can call DSN. To trap the output I use OUTTRAP and the output is printed using SAY. Last but most important a DO loop removes any remaining data left on the stack.

Assume DB2A is not active on the MVS where you execute the TSO %DISUTIL DB2A command, DSN will fail. I have not included any error processing to illustrate you can manage without even though it is bad practise. When DSN fails OUTTRAP will not catch anything and COMMAND.0 will be zero. However QUEUED() will return a number greater than zero and thus the final loop will remove the unprocessed commands for DSN. Subsequently the REXX will terminate without any strange error messages.

Previous tip in english        Forrige danske tip        Tip list