Your first REXX exec
REXX is a simple, readable scripting language built into z/OS. People use it to automate the repetitive parts of mainframe work: checking datasets, running TSO commands, building reports and driving ISPF.
Where REXX runs
- TSO/ISPF — interactively, from the command line or option 6.
- Batch — through the TSO batch program IKJEFT01.
- z/OS Unix — from the shell.
- Automation products such as NetView and system automation, and inside CICS with REXX for CICS.
The smallest exec
/* REXX */ say 'Hello, mainframe' say 'Today is' date('W') date() exit 0
Running it
- Put the member in a dataset allocated to SYSEXEC or SYSPROC, then type
TSO HELLO. - Or run it directly:
TSO EXEC 'USER.REXX(HELLO)'. - In batch, run IKJEFT01 with SYSEXEC pointing at your library and the exec name in SYSTSIN.
Variables and input
Variables need no declaration and have no type; everything is a string, and numbers are strings that look like numbers. ARG reads the parameters the exec was called with, uppercased; PULL reads a line from the terminal.
/* REXX */ arg hlq count if count = '' then count = 3 total = count * 10 say 'Listing' hlq 'with' total 'lines'
Common mistakes
The member is treated as a CLIST. Always start with the REXX comment.
ARG converts input to capitals. Use PARSE ARG to keep the case as typed.
An unset variable's value is its own name in capitals, so typos silently become text. SIGNAL ON NOVALUE catches this.
What you will see at work
- Most teams have a shared exec library full of useful tools; reading them is a quick way to learn.
- Small REXX tools that save a team an hour a week are a great way to get noticed early.
- REXX is also used in system automation, so operations teams rely on it too.
Key terms
Check your understanding.
Take this lesson's quiz and save your progress. Free.