REXX Programming — Mainframe Scripting Guide
In this tutorial, you'll learn about REXX Programming. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
REXX (Restructured Extended Executor) is a versatile scripting language for IBM mainframes that simplifies system automation, data parsing, and application integration on z/OS — think of it as the Mainframe equivalent of Python for glue logic and rapid prototyping.
What You'll Learn
REXX syntax fundamentals, string parsing, file I/O, host command integration, and how to build automation scripts that control Mainframe applications and system resources.
Why It Matters
Every Mainframe shop runs REXX. It is the go-to language for automating repetitive tasks — submitting JCL jobs, parsing system logs, generating reports, and building ISPF dialog applications. REXX is to z/OS what Bash is to Linux: the universal glue that holds automation together.
Durga Antivirus Pro uses REXX-style string parsing for log analysis during scheduled security audits. DodaZIP employs REXX-like scripting for batch compression job Orchestration.
Real-World Use
A system administrator writes a REXX exec that monitors CICS Transaction logs every hour, extracts error patterns using regex parsing, and automatically submits a JCL job to restart the region if a critical failure is detected — all without human intervention.
Learning Path
flowchart LR A["Mainframe Basics"] --> B["COBOL Programming"] B --> C["JCL Job Control"] C --> D["REXX Programming
You are here"] D --> E["TSO/E Commands"] style D fill:#f90,color:#fff
What Is REXX?
REXX was created by IBM in 1979 as a human-friendly scripting language. Unlike COBOL or assembler, REXX is interpreted — you write a script (called an "exec") and run it immediately without a compile step.
REXX's key strengths:
- Easy syntax: Reads like plain English with minimal punctuation
- Dynamic typing: Variables hold any type — no declarations needed
- Powerful parsing: Built-in
PARSEinstruction for string manipulation - Host command integration: Call TSO, ISPF, or MVS commands directly
- Numerical precision: Arbitrary-precision arithmetic out of the box
Your First REXX Exec
A REXX script is stored as a member in a PDS or as a sequential file. Here is a minimal example:
/* HELLO EXEC - First REXX program */
SAY "Hello from REXX!"
SAY "Today is:" DATE()
SAY "Time is:" TIME()
EXIT 0
Expected output:
Hello from REXX!
Today is: 24 Jun 2026
Time is: 14:30:00
Variables and Strings
REXX variables are untyped and created by assignment:
/* Variables in REXX */
name = "Durga Antivirus Pro"
version = 4.2
users = 50000
SAY "Product:" name "Version:" version "Users:" users
total = users * 2
SAY "Projected users:" total
Expected output:
Product: Durga Antivirus Pro Version: 4.2 Users: 50000
Projected users: 100000
String Parsing with PARSE
The PARSE instruction is REXX's most powerful feature:
/* PARSE examples */
data = "SMITH,JOHN,20000,ACCOUNTING"
PARSE VAR data last "," first "," salary "," dept
SAY "Last:" last "First:" first
SAY "Salary:" salary "Dept:" dept
/* Positional parsing */
text = "12:30:45"
PARSE VAR text hh ":" mm ":" ss
SAY "Hour:" hh "Minute:" mm "Second:" ss
Expected output:
Last: SMITH First: JOHN
Salary: 20000 Dept: ACCOUNTING
Hour: 12 Minute: 30 Second: 45
Host Command Integration
REXX can issue TSO commands directly using the ADDRESS instruction:
/* TSO commands from REXX */
ADDRESS TSO
"LISTCAT ENTRIES('SYS1.PARMLIB')"
"ALLOCATE FILE(DD1) DATASET('USER.TEST.DATA') SHR"
"EXECIO * DISKR DD1 (STEM LINE. FINIS"
DO i = 1 TO LINE.0
SAY "Line" i":" LINE.i
END
This pattern lets you build complex automation by chaining TSO, ISPF, and MVS commands within a single REXX script. Doda Browser uses a similar chaining pattern for tab management operations.
Common Errors
1. Forgetting to initialize stem variables
Always set stem.0 before using stem arrays in loops.
2. Confusing SAY with queue
SAY writes to the terminal. QUEUE writes to the external data queue.
3. Missing EXIT 0
Always end with EXIT 0 for clean return codes in JCL.
4. Assuming case sensitivity
REXX is case-insensitive for instructions but preserves case in strings.
5. Not using TRACE for debugging
TRACE A shows all instructions as they execute — invaluable for debugging.
Practice Questions
What does the PARSE instruction do in REXX? It splits a string into variables based on delimiter patterns or positional markers.
How do you issue a TSO command from REXX? Use
ADDRESS TSO "command"or within anADDRESS TSOblock.What is a stem variable in REXX? A compound variable like
name.1,name.2— REXX's array equivalent.How do you read a dataset in REXX? Use
EXECIO * DISKR filename (STEM var. FINISto read lines into a stem.What does TRACE A do? Interactively displays every instruction and its result during execution.
Challenge: Write a REXX exec that reads a JCL dataset, finds all //JOB statements, and reports each job name and class.
FAQ
What's Next
| Tutorial | What You'll Learn |
|---|---|
| TSO/E Commands Guide | Master the time-sharing environment on z/OS |
| ISPF & PDF Guide | Build interactive dialog panels |
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Updated 2026-06-24.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro