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.
/* 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
ADDRESS ISPEXEC "DISPLAY PANEL(MYPANEL)"shows a panel you designed.LIBDEFpoints ISPF at your own panel and message libraries for the session.LMINIT,LMOPEN,LMMLISTand related services list and process library members.
Handling errors
/* 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
The ISREDIT MACRO statement must come first, or the editor rejects the exec.
Macros run across many members are powerful. Test on a copy and keep a backup.
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
- A good edit macro can save hours when hundreds of JCL members need the same change.
- ISPF panels written in REXX are common for small in-house tools.
- Code reviews of REXX tools are standard practice, especially if they touch production datasets.
Key terms
Check your understanding.
Take this lesson's quiz and save your progress. Free.