Progress0 of 0 lessons

REXX Basics: Using REXX within ISPF & Running REXX Scripts

REXX (Restructured Extended Executor) is a powerful mainframe scripting language that provides advanced features for automation and programming. REXX offers better string handling, arrays, functions, and structured programming compared to CLIST. Understanding REXX basics helps you create sophisticated automation scripts and ISPF applications. This tutorial covers REXX syntax, writing REXX scripts, using REXX within ISPF, running REXX scripts, and best practices.

REXX is widely used for mainframe automation, system utilities, and ISPF application development. It provides a more modern and powerful scripting environment than CLIST, with better error handling and data structures. Learning REXX basics enables you to create complex automation and interactive applications. This tutorial provides practical guidance for REXX development.

Understanding REXX

REXX is a powerful scripting language for mainframe automation.

What is REXX?

REXX (Restructured Extended Executor) is:

  • A powerful scripting language for mainframes
  • More advanced than CLIST
  • Supports structured programming
  • Provides arrays and functions
  • Better string manipulation

REXX Advantages

REXX advantages include:

  • Better string handling
  • Array support
  • Function libraries
  • Structured control statements
  • Better error handling
  • Portability

Writing REXX Scripts

REXX scripts are written as text members in PDS libraries.

Creating a REXX Script

To create a REXX script:

  • Use ISPF Edit to create a new member
  • Store in a PDS library (typically REXX library)
  • Start with /*REXX*/ comment
  • Write REXX statements
  • Save the member

Basic REXX Structure

A basic REXX script:

text
1
2
3
/*REXX*/ say 'Hello from REXX' exit 0

This shows a simple REXX script with comment, SAY command, and EXIT.

REXX Comment Indicator

The /*REXX*/ comment:

  • Indicates this is a REXX script
  • Should be the first line
  • Required for REXX execution
  • Helps system identify script type

REXX Syntax

Understanding REXX syntax is essential.

Variables

Variables in REXX:

  • No special prefix (unlike CLIST &)
  • Assigned with = operator
  • Case-insensitive
  • Automatic type conversion
  • Can contain strings or numbers

Example variable usage:

text
1
2
3
4
5
/*REXX*/ name = 'USERID' dsn = name || '.SOURCE.COBOL' say 'Dataset is' dsn exit 0

String Operations

REXX provides powerful string operations:

  • Concatenation with || operator
  • String functions (SUBSTR, POS, etc.)
  • Pattern matching
  • String parsing

Control Structures

REXX supports structured control:

  • IF/THEN/ELSE: Conditional execution
  • DO/END: Block statements
  • DO WHILE: Loops
  • DO UNTIL: Loops
  • SELECT/WHEN/OTHERWISE: Case statements

Example with IF/THEN:

text
1
2
3
4
5
6
7
8
/*REXX*/ parse arg dsn if dsn = '' then do say 'Error: Dataset name required' exit 8 end say 'Processing' dsn exit 0

Arrays

REXX supports arrays (stem variables):

  • Use stem notation (array.)
  • Dynamic sizing
  • Indexed access
  • Useful for data structures

Example array usage:

text
1
2
3
4
5
6
7
8
/*REXX*/ array.1 = 'First' array.2 = 'Second' array.3 = 'Third' do i = 1 to 3 say array.i end exit 0

Running REXX Scripts

REXX scripts are executed using the REXX command.

Basic Execution

To run a REXX script:

  • Use REXX command followed by script name
  • Specify PDS and member name
  • Pass arguments if needed
  • Script executes and returns

Example execution:

text
1
2
REXX 'USERID.REXX(MYSCRIPT)' REXX 'USERID.REXX(MYSCRIPT)' 'ARG1' 'ARG2'

Running from ISPF

To run from ISPF:

  • Use Option 6 (Command) for TSO commands
  • Type REXX command with script name
  • Or run from ISPF panels
  • Or call from other scripts

Passing Arguments

To pass arguments:

  • List arguments after script name
  • Access using PARSE ARG
  • Arguments are positional
  • Quote arguments with spaces

Using REXX within ISPF

REXX can interact with ISPF through ISPF services.

ISPF Services

REXX can use ISPF services for:

  • Displaying panels
  • Processing tables
  • Handling variables
  • Interacting with dialogs
  • Accessing ISPF functions

ISPF Function Calls

REXX calls ISPF functions:

text
1
2
3
4
5
6
7
8
/*REXX*/ address ispexec 'DISPLAY PANEL(MYPANEL)' if rc <> 0 then exit 8 'TBOPEN TABLE' /* Process table */ 'TBCLOSE TABLE' exit 0

Address ISpexec

The ADDRESS ISPEXEC command:

  • Directs commands to ISPF
  • Required for ISPF function calls
  • Enables ISPF interaction
  • Used for ISPF automation

REXX vs CLIST

Understanding differences helps choose the right tool.

REXX Advantages

REXX advantages:

  • Better string manipulation
  • Array support
  • Function libraries
  • Structured programming
  • Better error handling
  • More portable

CLIST Advantages

CLIST advantages:

  • Simpler syntax
  • Easier for simple tasks
  • Direct TSO command execution
  • Lower learning curve

When to Use Each

Use REXX for:

  • Complex automation
  • String manipulation
  • Data processing
  • ISPF applications
  • Reusable utilities

Use CLIST for:

  • Simple command sequences
  • Quick automation
  • Basic procedures

Common REXX Patterns

Common patterns for REXX development.

Argument Parsing

Parse arguments:

text
1
2
3
4
5
6
7
8
/*REXX*/ parse arg dsn member if dsn = '' then do say 'Error: Dataset name required' exit 8 end /* Process arguments */ exit 0

Error Handling

Handle errors:

text
1
2
3
4
5
6
7
8
/*REXX*/ address tso 'LISTCAT ENTRIES('dsn')' if rc <> 0 then do say 'Error: LISTCAT failed' exit rc end exit 0

Looping

Process multiple items:

text
1
2
3
4
5
/*REXX*/ do i = 1 to 10 say 'Processing item' i end exit 0

Best Practices

Following best practices improves REXX quality:

  • Use /*REXX*/ Comment: Always include REXX indicator
  • Validate Input: Validate arguments and input
  • Add Comments: Document REXX purpose and logic
  • Handle Errors: Check return codes and handle errors
  • Use Structured Code: Use structured programming techniques
  • Test Incrementally: Test REXX scripts as you develop
  • Use Functions: Create reusable functions
  • Document Usage: Document how to use the REXX script

Explain Like I'm 5: REXX

Think of REXX like a super-smart recipe for the computer:

  • REXX is like a very smart recipe that can do more things than a regular recipe (CLIST). It can do math, remember lists of things (arrays), use special tools (functions), and make decisions. It's like having a recipe that can also do calculations and remember things!
  • Writing REXX is like writing a smart recipe. You write instructions that the computer follows, but REXX can do more complex things like "if this number is bigger than 10, do this" or "remember this list of items." It's like writing a recipe that can think and remember!
  • Running REXX is like telling the computer "follow this smart recipe." The computer reads the REXX script and does all the steps, using its smart features to make decisions and remember things. It's like having a smart assistant that follows your detailed instructions!
  • REXX vs CLIST is like the difference between a simple recipe and a smart recipe. CLIST is like a basic recipe that tells you step by step what to do. REXX is like a smart recipe that can do math, remember lists, and make decisions. It's like having a basic cookbook vs. a smart cooking assistant!

So REXX is like a super-smart recipe for the computer that can do calculations, remember lists, make decisions, and do complex tasks automatically!

Practice Exercises

Complete these exercises to reinforce your REXX skills:

Exercise 1: Write Simple REXX

Practice basics: write a simple REXX script that displays a message, understand REXX structure, save and test the script, and learn basic REXX writing. Master basic REXX writing.

Exercise 2: REXX with Arguments

Practice arguments: write a REXX script that accepts arguments, use PARSE ARG, test with different arguments, and learn argument handling. Master REXX arguments.

Exercise 3: REXX with Logic

Practice logic: write a REXX script with IF/THEN logic, use control structures, test different conditions, and learn REXX logic. Master REXX control structures.

Exercise 4: REXX Arrays

Practice arrays: write a REXX script using arrays, understand stem variables, process array data, and learn REXX arrays. Master REXX arrays.

Exercise 5: REXX with ISPF

Practice ISPF: write a REXX script that uses ISPF services, understand ADDRESS ISPEXEC, interact with ISPF, and learn REXX-ISPF integration. Master REXX-ISPF integration.

Test Your Knowledge

1. What does REXX stand for?

  • Restructured Extended Executor
  • Restructured Executor Extension
  • Runtime Extended Executor
  • Restructured Execution Extension

2. How do REXX variables differ from CLIST?

  • REXX uses & prefix
  • REXX uses no special prefix
  • REXX uses $ prefix
  • REXX uses # prefix

3. How do you run a REXX script?

  • RUN command
  • REXX command
  • EXEC command
  • CALL command

4. What comment indicates a REXX script?

  • /*REXX*/
  • /*CLIST*/
  • /*SCRIPT*/
  • /*CODE*/

5. Can REXX interact with ISPF?

  • No, REXX cannot interact with ISPF
  • Yes, through ISPF services
  • Only through TSO
  • Only in batch

Related Concepts