Mainframe Path Start learning free
Core8 min readLesson 4 of 4

ISPF edit macros and error handling

REXX can drive ISPF itself. Edit macros automate changes inside the editor, ISPF services let execs show panels and work with libraries, and proper error handling makes your tools safe for other people to use.

An edit macro

An edit macro is a REXX exec run from the editor's command line. It talks to the editor with ISREDIT commands.

FIXDSN — change a dataset name everywhere in the member
/* REXX */
"ISREDIT MACRO (OLD NEW)"
if new = '' then do
  say 'Usage: FIXDSN old new'
  exit 8
end
"ISREDIT CHANGE" old new "ALL"
"ISREDIT (CNT) = CHANGE_COUNTS"
say word(cnt,1) 'changes made'
exit 0

Save it in a library allocated to SYSEXEC or SYSPROC, open a member in Edit, and type FIXDSN TEST.PAY PROD.PAY on the command line.

ISPF services

Handling errors

Catch problems instead of hiding them
/* REXX */
signal on novalue   /* unset variable = bug */
signal on error     /* non-zero command RC */
...
exit 0

error:
  say 'Command failed at line' sigl 'RC' rc
  exit 12
novalue:
  say 'Unset variable at line' sigl
  exit 16

Common mistakes

Edit macros without MACRO

The ISREDIT MACRO statement must come first, or the editor rejects the exec.

Changing all members with no backup

Macros run across many members are powerful. Test on a copy and keep a backup.

Exiting with 0 after a failure

Callers, including batch jobs, judge success by the exit code. Return a non-zero value when something went wrong.

What you will see at work

Key terms

Check your understanding.
Take this lesson's quiz and save your progress. Free.

Take the lesson quiz
← Datasets and TSO commands from REXXBack to REXX scripting on z/OS