Mastering REXX Programming Language on Mainframes

REXX for Mainframes: Simplifying Automation and Scripting

Hello, fellow programming enthusiasts! In this blog post, I will introduce you to REXX Automation on Mainframes – a fundamental and powerful concept in the REXX

language. Operators play a crucial role in performing calculations, comparisons, and logical operations. Understanding their syntax and behavior is essential for writing efficient REXX scripts. I will walk you through different types of operators, their usage, and how they help automate tasks effectively. By the end, you’ll have a clear grasp of how REXX operators enhance scripting capabilities. Let’s dive in!

Table of contents

An Introduction to REXX Programming for Mainframe Systems

REXX (Restructured Extended Executor) is a powerful, high-level scripting language widely used on IBM mainframes for automation, data processing, and system administration. Known for its simplicity and readability, REXX allows both beginners and experienced programmers to write efficient scripts with minimal effort. It integrates seamlessly with mainframe environments like TSO/E, ISPF, and CICS, enabling users to automate repetitive tasks, process datasets, and interact with system utilities. This guide will help you master REXX programming on mainframes, covering syntax, functions, and advanced techniques to optimize workflows, enhance productivity, and harness the full potential of mainframe computing.

What is REXX Programming in Mainframe Systems?

REXX (Restructured Extended Executor) is a high-level, interpreted programming language developed by IBM. It is designed for ease of use, making it an excellent choice for automation, scripting, and system programming on IBM mainframe environments such as TSO/E (Time Sharing Option Extensions), ISPF (Interactive System Productivity Facility), CICS (Customer Information Control System), and VM/CMS (Virtual Machine/Conversational Monitor System).

Understanding the Basics of REXX

REXX is an interpreted language, meaning that it is executed line by line rather than being compiled. This makes debugging and testing simpler.

Key Features of REXX:

  • Free-format Syntax: No strict rules for indentation or formatting.
  • Case-insensitive: Except for string literals, uppercase and lowercase letters are treated the same.
  • Automatic Data Typing: No need to declare variables; REXX treats all data as strings unless used in arithmetic expressions.
  • Powerful String Handling: REXX has built-in functions for manipulating text, making it useful for processing logs and reports.

Example: A Simple REXX Program

/* Simple REXX Program */
say "Welcome to REXX Programming on Mainframes!"

Output:

Welcome to REXX Programming on Mainframes!

Executing REXX Programs in a Mainframe Environment

REXX programs can be executed in different environments on IBM mainframes:

  • TSO/E (Time Sharing Option Extensions): Allows users to run REXX scripts interactively or in batch mode.
  • ISPF (Interactive System Productivity Facility): Used to develop menu-driven applications and interactive interfaces.
  • JCL (Job Control Language): REXX can be executed within JCL jobs for batch processing.
  • CICS (Customer Information Control System): Used for transaction processing and integrating with business applications.

Executing a REXX Script in TSO/E

To execute a REXX program stored in a dataset, use:

EXEC 'USERID.REXX.LIB(MYREXX)'

This command runs the REXX script MYREXX stored in the USERID.REXX.LIB dataset.

Automating Tasks with REXX in TSO/E

REXX scripts are widely used to automate tasks such as listing datasets, managing files, and submitting jobs.

Example: REXX Script to List Datasets in TSO/E

/* List Datasets using REXX */
ADDRESS TSO
"LISTCAT ENTRIES('USER.DATASET')"

This script retrieves details of the dataset USER.DATASET.

Using REXX with JCL for Batch Processing

JCL is the scripting language used to execute jobs on mainframes. REXX can be used to dynamically generate and submit JCL jobs, automating batch processing.

Example: REXX Script to Submit JCL

/* REXX to submit a JCL job */
ADDRESS TSO
"SUBMIT 'USERID.JCL.LIB(MYJOB)'"

This script submits a JCL job from the dataset USERID.JCL.LIB.

String Processing and Data Manipulation in REXX

REXX has powerful built-in functions for parsing, extracting, and manipulating strings.

Common String Functions in REXX

Example: Parsing a String in REXX

/* Parsing first and last name */
name = "John Doe"
parse var name first last
say "First Name:" first
say "Last Name:" last

Output:

First Name: John  
Last Name: Doe

Interfacing REXX with Other Mainframe Components

REXX can interact with various mainframe components, including JCL, DB2, and CICS.

Using REXX to Execute SQL Queries in DB2

ADDRESS DSNREXX
"EXECSQL DECLARE C1 CURSOR FOR SELECT NAME FROM EMPLOYEE"
"EXECSQL OPEN C1"

This script connects to DB2 and retrieves employee names.

Using REXX with CICS for Transaction Processing

ADDRESS CICS
"LINK PROGRAM('MYCICS') COMMAREA(data) LENGTH(100)"

This script interacts with a CICS application.

Debugging and Error Handling in REXX

REXX provides built-in debugging tools to trace execution and handle errors efficiently.

Using TRACE for Debugging

trace ?r
say "Debugging REXX program!"

The ?r option displays the execution flow step by step.

Handling Errors with SIGNAL

/* Handling errors in REXX */
signal on error
say 10 / 0  /* This will trigger an error */
exit

error:
say "An error occurred!"

This script detects division by zero and redirects execution to the error: label.

Why is REXX Programming Needed in Mainframe Systems?

Mastering REXX on mainframes is essential for professionals working in enterprise computing, system automation, and data processing. Below are the key reasons why REXX is valuable, explained in detail:

1. Ease of Automation

REXX simplifies task automation on IBM mainframes. It allows users to automate file processing, job execution, and system commands, reducing manual effort. By writing REXX scripts, routine administrative tasks can be executed efficiently, improving productivity and reducing errors.

2. Simplified Scripting for Beginners

Unlike complex programming languages like COBOL or PL/I, REXX has a simple and easy-to-understand syntax, making it an ideal starting point for mainframe beginners. The language is interpreted, meaning there is no need for compilation, and it provides immediate feedback, helping learners grasp concepts faster.

3. Powerful String Processing Capabilities

REXX is widely used for string manipulation and text processing. It provides built-in functions to extract, modify, search, and format strings efficiently. These features make it useful for data analysis, report generation, and log file processing in mainframe environments.

4. Integration with Mainframe Components

One of the biggest strengths of REXX is its ability to interface with other mainframe tools. It can be used within JCL (Job Control Language), TSO/E, ISPF, DB2 (SQL queries), and CICS (transaction processing). This flexibility allows developers to automate workflows and interact with various subsystems seamlessly.

5. Enhancing Job Execution with JCL

REXX enhances the capabilities of JCL by allowing dynamic job creation, submission, and monitoring. Instead of manually modifying JCL for different tasks, REXX can generate JCL dynamically and submit jobs automatically, improving efficiency in batch processing and system administration.

6. Simplifying System Administration

System administrators use REXX for performing system diagnostics, managing datasets, automating backups, and monitoring performance. It helps in troubleshooting issues and scheduling repetitive tasks, ensuring smooth mainframe operations with minimal human intervention.

7. Debugging and Error Handling

REXX offers powerful debugging tools and error-handling mechanisms, such as TRACE and SIGNAL, which help developers identify and resolve issues effectively. These features ensure that scripts run reliably, reducing unexpected failures in critical mainframe applications.

8. Enhancing Productivity with ISPF Panels

REXX can be used to develop interactive ISPF applications, providing a user-friendly interface for performing complex tasks. It allows users to build custom menus, dialog boxes, and automated data entry screens, making it easier for non-technical users to interact with mainframe systems.

9. Database Interaction with DB2

REXX can be integrated with DB2 to execute SQL queries, making it a valuable tool for database management and reporting. By using DSNREXX, developers can retrieve, update, and manipulate database records, reducing the need for separate SQL scripts.

10. Used in Enterprise-Level Applications

Many large enterprises and financial institutions rely on IBM mainframes for critical business operations. REXX is used extensively in these organizations to automate financial transactions, manage inventory systems, and monitor banking operations, making it a crucial skill for mainframe professionals.

Example of REXX Programming Language on Mainframes

To truly master REXX on IBM mainframes, one must understand its real-world applications, including automation, system interactions, JCL integration, dataset manipulation, and database operations. Below, I will walk through a detailed, step-by-step example covering different mainframe functionalities using REXX.

Scenario: Automating Job Submission, Dataset Processing, and Report Generation

Problem Statement:

A mainframe administrator needs to automate a batch job process that performs the following tasks:

  1. Check if a dataset exists; if not, create it.
  2. Write data into the dataset.
  3. Submit a JCL job to process the dataset.
  4. Retrieve job output logs and generate a summary report.

Step 1: Checking and Creating a Dataset in TSO/E

The first step is to verify if a dataset exists. If it doesn’t, we create it dynamically using REXX.

REXX Code to Check and Create a Dataset

/* REXX Script to Check and Create a Dataset */
dataset = "USERID.MY.DATASET"

/* Use LISTCAT to check if dataset exists */
ADDRESS TSO
"LISTCAT ENTRIES('"dataset"')"  
IF RC = 0 THEN DO
    SAY "Dataset already exists: " dataset
END
ELSE DO
    SAY "Dataset does not exist. Creating..."
    "ALLOCATE DATASET('"dataset"') NEW SPACE(1,1) UNIT(SYSDA) DSORG(PS) RECFM(F B) LRECL(80)"
    SAY "Dataset Created: " dataset
END
  • The script checks if the dataset exists using LISTCAT.
  • If it exists (RC = 0), it simply displays a message.
  • If it does not exist, it allocates the dataset dynamically using ALLOCATE.
  • The dataset is created with fixed block (FB) record format, 80-byte length.

Step 2: Writing Data to the Dataset

Now that we have a dataset, we need to write data into it.

REXX Code to Write Data

/* Write Data to a Dataset */
ADDRESS TSO
"EXECIO * DISKW '"dataset"' (STEM data. FINIS)"

/* Sample Data */
data.1 = "EmployeeID  Name       Salary"
data.2 = "101        John Doe    50000"
data.3 = "102        Alice Smith 60000"
data.4 = "103        Bob Brown   55000"
data.0 = 4 /* Number of lines */

/* Write data to the dataset */
"EXECIO "data.0" DISKW '"dataset"' (STEM data. FINIS)"
SAY "Data written to dataset successfully!"
  • Uses EXECIO to write data into the dataset.
  • data.0 stores the number of lines to be written.
  • The dataset now contains employee salary data.

Step 3: Submitting a JCL Job Using REXX

Next, we submit a JCL job to process this dataset.

JCL Job Stored in USERID.JCL.LIB(PROCESS)

//PROCESS JOB ('JOB123'),CLASS=A,MSGCLASS=A
//STEP1  EXEC PGM=SORT
//SORTIN  DD DSN=USERID.MY.DATASET,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN   DD *
   SORT FIELDS=(1,3,CH,A)
/*

This JCL sorts employee data based on EmployeeID.

REXX Code to Submit the JCL

/* Submit a JCL Job */
jclDataset = "USERID.JCL.LIB(PROCESS)"
ADDRESS TSO
"SUBMIT '"jclDataset"'"
SAY "JCL Submitted Successfully!"
  • The script submits the JCL job stored in USERID.JCL.LIB(PROCESS).
  • The job sorts the employee records in the dataset.

Step 4: Retrieving Job Output Logs

Once the job completes, we need to retrieve its output logs.

REXX Code to Retrieve Job Output

/* Retrieve Job Output */
ADDRESS SDSF
"ISFEXEC SELECT JOB(JOB123)"
"ISFEXEC FIND 'SORTOUT'"
DO WHILE RC = 0
    SAY ISFLINE
    "ISFEXEC NEXT"
END
  • Uses SDSF (System Display and Search Facility) to check job logs.
  • Searches for the SORTOUT section, which contains sorted employee records.

Step 5: Generating a Summary Report

Now, we create a summary report containing sorted employee data.

REXX Code for Report Generation

/* Generate Report */
reportFile = "USERID.REPORT.TXT"
SAY "Generating Report in: " reportFile
ADDRESS TSO
"EXECIO * DISKW '"reportFile"' (STEM sortedData. FINIS)"
SAY "Report Generated Successfully!"
  • The report file stores sorted employee data.
  • Uses EXECIO to write the sorted records into a text file for analysis.

Advantages of Using REXX Programming Language on Mainframes

Here are advantages of mastering REXX programming language on mainframes:

  1. Simplifies Mainframe Automation: REXX provides a straightforward way to automate repetitive tasks on mainframes, such as job scheduling, system monitoring, and log analysis, reducing manual effort and improving efficiency.
  2. Easy to Learn and Use: REXX has a simple, English-like syntax, making it easier to learn and use compared to other mainframe languages like COBOL, JCL, or Assembler, enabling faster development and debugging.
  3. Powerful String Manipulation: REXX excels at processing and manipulating text, making it ideal for parsing logs, generating reports, and handling configuration files in mainframe environments.
  4. Seamless Integration with Mainframe Components: REXX interacts easily with mainframe utilities like TSO (Time Sharing Option), ISPF (Interactive System Productivity Facility), and SDSF (System Display and Search Facility), enhancing system administration.
  5. Supports Both Batch and Interactive Processing: REXX can be used for both batch processing and interactive execution, allowing users to develop scripts for background automation as well as real-time command execution.
  6. Enhances Problem Determination and Debugging: REXX’s ability to capture system messages, log outputs, and dynamically execute commands makes it valuable for troubleshooting and diagnosing system issues on mainframes.
  7. Portability Across Multiple Platforms: While primarily used on mainframes, REXX also runs on Windows, Linux, and UNIX environments, allowing developers to write scripts that work across different systems with minimal modifications.
  8. Reduces Dependency on JCL for Complex Tasks: While JCL (Job Control Language) is essential for job execution, REXX allows for more advanced logic and decision-making, making job management more flexible and efficient.
  9. Extensibility Through External Calls: REXX can call external programs, issue database queries (via SQL interfaces), and interact with other programming languages (such as COBOL, C, and Python), making it a versatile tool for mainframe application development.
  10. High Demand for REXX Skills in Mainframe Jobs: Many enterprises still rely on IBM mainframes, and professionals with REXX expertise are valuable for system automation, performance monitoring, and application development, leading to strong career opportunities.

Disadvantages of Using REXX Programming Language on Mainframes

Here are disadvantages of mastering REXX programming language on mainframes:

  1. Limited Career Scope Outside Mainframes: While REXX is valuable in mainframe environments, it is not widely used in modern programming outside of legacy systems, limiting career opportunities in cloud computing, web development, and mobile applications.
  2. Less Demand Compared to Modern Languages: Many organizations are moving away from mainframes in favor of cloud-based solutions and modern programming languages like Python, Java, and Go, reducing the long-term demand for REXX expertise.
  3. Not Suitable for High-Performance Computing: REXX is an interpreted language, making it slower than compiled languages like C or Java for performance-intensive applications, limiting its use for large-scale data processing or real-time systems.
  4. Limited Support for Advanced Programming Concepts: Unlike modern languages, REXX lacks built-in support for object-oriented programming (OOP), multithreading, and complex data structures, making it less flexible for modern software development.
  5. Dependency on Mainframe Infrastructure: Since REXX is primarily used in IBM mainframe environments, learning it does not provide much benefit in environments that do not use mainframes, limiting its versatility.
  6. Integration Challenges with Modern Technologies: While REXX can interface with other languages, it is not as seamless as using API-friendly languages like Python or Java, making integration with modern applications more difficult.
  7. Steep Learning Curve for System-Specific Features: While REXX itself is easy to learn, mastering its use on mainframes requires understanding complex IBM system utilities like TSO, ISPF, and SDSF, making the learning process more challenging.
  8. Lack of Active Community and Modern Resources: Unlike Python or Java, REXX has a smaller developer community and fewer up-to-date tutorials, online courses, and open-source libraries, making it harder to find support and learning materials.
  9. Limited Job Market in Emerging Technologies: REXX skills are mainly relevant for legacy systems, and as companies modernize, fewer new projects require REXX expertise, making job growth uncertain in the long run.
  10. Risk of Mainframe System Decommissioning: As more enterprises move towards cloud computing, mainframe systems are gradually being phased out, which could make REXX knowledge less valuable over time compared to learning newer technologies.

Future Development and Enhancement of Using REXX Programming Language on Mainframes

Here are future developments and enhancements that could improve the relevance of mastering REXX programming language on mainframes:

  1. Integration with Cloud and Hybrid Environments: Enhancing REXX to work seamlessly with cloud platforms like AWS, Azure, and IBM Cloud would allow mainframe applications to interact with modern cloud-based services and extend their lifespan.
  2. Modern API Support for Web and Microservices: Adding built-in support for REST APIs, JSON, and microservices would enable REXX applications to communicate easily with modern web applications and enterprise systems.
  3. Enhanced Security Features: Strengthening security features like encryption, secure authentication, and access control would make REXX more suitable for handling sensitive mainframe data in modern IT environments.
  4. Improved Performance Optimization: Developing a Just-In-Time (JIT) compiler or optimizing REXX’s execution engine could significantly improve its performance, making it competitive with compiled languages for high-speed data processing.
  5. Expansion of Database Connectivity: Enhancing REXX with direct support for NoSQL databases like MongoDB, Cassandra, and modern SQL databases (PostgreSQL, MySQL) would allow it to handle diverse data storage needs.
  6. Multithreading and Parallel Processing Support: Introducing multithreading and parallel execution features would make REXX more powerful for handling large-scale data processing and automation tasks.
  7. Better Integration with Modern Programming Languages: Providing seamless interoperability with languages like Python, Java, and Go through native libraries or improved external call mechanisms would expand REXX’s capabilities.
  8. GUI Development and Modern UI Support: Enhancing REXX with graphical user interface (GUI) development tools would allow the creation of interactive applications, making it more user-friendly and applicable beyond traditional text-based interfaces.
  9. Increased Adoption in DevOps and Automation: Enhancing REXX for DevOps workflows, CI/CD pipelines, and modern automation frameworks would help mainframe teams integrate REXX scripts into modern IT operations.
  10. Revitalized Learning Resources and Community Support: Developing updated documentation, online training courses, and open-source libraries would encourage more developers to learn REXX, keeping it relevant in enterprise environments.

Discover more from PiEmbSysTech

Subscribe to get the latest posts sent to your email.

Leave a Reply

Scroll to Top

Discover more from PiEmbSysTech

Subscribe now to keep reading and get access to the full archive.

Continue reading