[USflag] The American Programmer [USflag]

Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Everything about COBOL
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
  Sorting in REXX: The Bubble Sort
  REXX Password Generator
  Using REXX to capture displayed output of TSO command
  Count records in REXX
  REXX program to calculate present value of money
  REXX function to format a number in currency format
  REXX function to produce a fixed-length number
  REXX program to produce lottery numbers
  REXX: what does your phone number spell?
  REXX Practice Problems.
  Just Enough REXX Tutorial
  Setting up to Execute REXX Programs on TSO/ISPF
  How to execute a REXX program
  REXX Boolean operators
  Comparison of CLIST language and REXX
  REXX Comparison operators
  REXX Debugging: the TRACE verb
  Reserved REXX Variables
  Executing REXX through JCL.
  Writing ISPF Edit Macros in REXX
  REXX program to unload a PDS
  REXX book: The REXX Language on TSO
  REXX Functions Book
  QMF Procedures Written in REXX
  Using REXX Subroutines with the QMF Calc panel
  REXX error codes (RC)
  REXX programming language manuals
  Books on REXX programming
  The REXX Files
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > REXX   > REXX Language on TSO

REXX book: The REXX Language on TSO

Revised and Updated August 2012. Available at Amazon

[The REXX Language on TSO]
The REXX Language on TSO. (Published August 2012) ISBN 1479104779

The book at Amazon.FR

The book at Amazon.GE

The book at Amazon.IT

The book at Amazon.ES

The book at Amazon.UK

Learn how to write programs in the REXX language for TSO, MVS, OS/390, Z/os.
My first book on the REXX programming language, is out of print. This is my second book on REXX for TSO.
It improves on REXX in the TSO Environment in every way: it clarifies important points, it is better organized, and gives better examples.
There are very few other books in print about REXX in the TSO Environment.
This book quickly gets you started writing programs in REXX for MVS, OS/390, z/OS. It covers all REXX language elements, all TSO built-in functions, and the more important built-in functions.
Several REXX programs, macros, and user-written functions are illustrated and explained.

Gabe Gargiulo is the author of several mainframe books:
REXX Quick Reference    
REXX in the TSO Environment (Available new and used)
   MVS JCL (Out of Print)
Mastering OS2/REXX (Available new and used)   
ISPF Services: Using the Dialogue Manager, with REXX
MVS/TSO (Available new and used)

rexx programming book
Top of Page

Table of Contents REXX for TSO Book


Chapter 1: Overview of REXX REXX features Different ways to execute a REXX program Example of a REXX Program, with explanations

Chapter 2: Setting Up to Execute REXX in TSO/ISPF 1. Create a library 2. Specify details for allocating library 3. Create a member 4. Create the SETUP member in ISPF Editor 5. Execute the Setup Program 6. Try it

Chapter 3: The Basic Features The initial comment SAY - display on the terminal Variables Reserved variables The Literal The Label PULL - accept input from the terminal DO for looping Concatenating Data Strings EXIT to end your program Passing commands to TSO Short Description of all of REXX's Verbs or Keywords

Chapter 4: IF: the REXX conditional The simplest form of the IF A few things to think about Comparison operators The DO END sequence Boolean operators

Chapter 5: Looping: REXX repetition structure The simplest form The simple DO...END sequence The DO number ... END sequence The DO variable ... END sequence The DO that increments a variable The DO WHILE The DO UNTIL The DO FOREVER LEAVE ITERATE: Skipping back to the top of the loop

Chapter 6: SELECT: the CASE Structure Example Points of syntax Several instructions: example

Chapter 7: PARSE The basic form of PARSE Origins The Action of PARSE Short forms of PARSE Uses of PARSE: ARG The ARG in a main program The ARG in a user-written function or subroutine Uses of PARSE: PULL Uses of PARSE: EXTERNAL Uses of PARSE: VAR Uses of PARSE: VALUE Uses of PARSE: SOURCE Uses of PARSE: VERSION PARSE Templates: Just Variables PARSE Templates: A Literal PARSE Templates: A Variable in place of a Literal PARSE Templates: Column Delimiting With Numbers

Chapter 8: Debugging Interactive Debug What you can do during Interactive Debug Turning on Interactive Debug Codes displayed during Interactive Debug Tracing: the Smaller Guns Combinations of the TRACE verb

Chapter 9: Trapping Unexpected Conditions Situations you might want to trap Trapping Unexpected Conditions: General The trap that terminates The trap that continues Changing the name of the trap Trapping Unexpected Conditions: Syntax Trapping Unexpected Conditions: Error Trapping Unexpected Conditions: Failure Trapping Unexpected Conditions: Novalue Trapping Unexpected Conditions: Halt Trapping Unexpected Conditions: Contents of the Trap

Chapter 10: SIGNAL: the Extinct “GO TO” Signal: go there (but don’t come back)

Chapter 11: Math When does REXX do math? Math: Arithmetic Operators Math: Precision

Chapter 12: Passing Commands to Command Processors Passing commands to the environment How Do You Get REXX to Pass a Command to a Command Processor? What Do the Return Codes (RC) mean? What Command Processors Are Out There? How do You Send Commands to a Command Processor? Sending commands to TSO Sending commands to ISPF Sending commands to the ISPF Editor How Does Your Program Know if the Command Processor is There?

Chapter 13: Built-in Functions Some examples Basics of functions CALLing a function Some of the more important functions. Those Conversion Functions Built-in Functions: TSO Functions

Chapter 14: Writing Your Own Functions Example of Internal Function Internal, user-written functions What makes a function a function? Protecting Variables Example of External Function External, user-written functions Search Order for Functions and Subroutines

Chapter 15: Writing Your Own Subroutines Example Writing internal subroutines

Chapter 16: The Internal Data Queue, or Stack What is it? How do you put things into the Data Queue Data Queue or terminal dialogue? Functions used with the Data Queue Leftovers Clean up after yourself

Chapter 17: Compound Variables Compared to traditional subscripted variables Understanding compound variables Examples

Chapter 18: Reading and Writing Files: EXECIO The Basics The ALLOCATE command for reading Reading with EXECIO Reading whole file with EXECIO into Data Queue – example Reading one record at a time into Data Queue – example Reading whole file with EXECIO into an array – example Additional options for Reading The ALLOCATE command for writing Writing with EXECIO Writing whole file from Data Queue – example Writing whole file from an array - example

Chapter 19: The INTERPRET Instruction Why INTERPRET?

Chapter 20: Running REXX in Batch Example

Chapter 21: Example Programs, with Explanations STQUICK Program CANJOB Program SUBJCL1 Program SUBJCL2 Program SUBJCL3 Program UPDTMEMB Program CONTAINS Function EQWILD Function $HIDEALL Macro


Sample Pages (formatting not same as in the book)

(This is a part of the chapter) 11: Math

Math: Precision

If Einstein had had REXX he would have been twice the genius he was. (Or would he have been creating video games...). REXX does math to whatever precision you desire, limited only by the amount of computer memory you have available. REXX does everything in decimal numbers so you won't see approximate results.
Changing the precision.
The default precision is 9 digits. If a calculation generates more significant digits than that, REXX will round the answer and stop at 9 digits. You can change the precision to 100 or 1000 or 10000! On some systems you can go much higher than that. Useful for figuring your income tax.....
To change the precision to 100 digits:
The following example will show you what that means.
SAY 2 / 3
/*displays .666666667 (9 digits) */

SAY 2 / 3

66666666666666666667 */

Do Practice Problems 35 - 38.

15: Writing Your Own Subroutines


/* REXX */
/* instructions */
/* instructions */
/* instructions */

Writing internal subroutines

An internal subroutine is used to simplify coding - to avoid long cumbersome logic structures. I strongly encourage their use.
A subroutine looks like a function, but it's not a function.
Here are the characteristics of a subroutine:
  • invoked by: CALL subroutine-name
  • Example: CALL ADDEM
  • ARG is optional
  • RETURN is required but you don't have to pass information back on it
  • variables are generally shared with the main part of the program
  • there are no external subroutines in REXX.

Do Practice Problems 48 - 52.

Top of Page

Practice problems and suggested answers that go with the book. Practice problems     

REXX Example Programs shown in the book. Example Programs     

REXX Manuals from IBM

TSO Line Mode (Native TSO) commands. (such as DELETE, HRECALL, ALLOCATE, Line Mode EDIT) Essential for REXX and CLIST programmers

Writing ISPF Editor Macros in REXX

More information on setting up to use REXX on TSO


My REXX reference book on REXX functions Also contains information about TSO commands and macros.

REXX Error Codes

2 Expression > 64000 characters (OS/2 only)
3 Program is unreadable
4 Program interrupted
5 Machine storage exhausted
6 Unmatched /* or quote
7 WHEN or OTHERWISE expected
8 Unexpected THEN or ELSE
9 Unexpected WHEN or OTHERWISE
10 Unexpected or unmatched END
11 Control stack full
12 Clause > 500 characters
13 Invalid character in data
14 Incomplete DO/SELECT/IF
15 Invalid hex constant
16 Label not found
17 Unexpected PROCEDURE
18 THEN expected
19 String or symbol expected
20 Symbol expected
21 Invalid data on end of clause
22 Invalid character string
23 Invalid SBCS/DBCS mixed string
24 Invalid trace request
25 Invalid subkeyword found
26 Invalid whole number
27 Invalid do syntax
28 Invalid LEAVE or ITERATE
29 Environment name too long
30 Name or string > 250 characters
31 Name starts with numeric or "."
32 Invalid use of stem
33 Invalid expression result
34 Logical value not 0 or 1
35 Invalid expression
36 Unmatched "(" in expression
37 Unexpected "," or ")"
38 Invalid template or pattern
39 Evaluation stack overflow
40 Incorrect call to routine
41 Bad arithmetic conversion
42 Arithmetic overflow/underflow
43 Routine not found
44 Function did not return data
45 No data specified on function return
46 Invalid variable reference
47 Unassigned
48 Failure in system service
49 Interpreter failure

This book (scroll to the top of this page) will get you into programming with Classic REXX (Restructured eXtended eXecutor language) on IBM's mainframe running MVS, OS390 or Zos TSO/ISPF. You can run REXX online during a TSO session, or in a batch program with JCL.
REXX is a user-friendly interpreted scripting language developed by Michael Cowlishaw. It uses clear English-language verbs and parameters.
REXX is used for application prototyping and one-time jobs. REXX is generally interpreted and so there is a performance penalty.
REXX is used as the driver script for developing and running ISPF applications.

[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |