x = OUTTRAP('VAR.')
....your programming here that results in system messages
y = OUTTRAP('OFF')
all of the sys-generated messages should now be stored in the var. stem variable (in case you want to look at them). I don't know 100% if this captures all messages, I used it to grab the Job infos when submitting a JCL thru Rexx.