[USflag] The American Programmer [USflag]


Home
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
  Using REXX OUTTRAP
  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   > Just Enough REXX

The Joy of

REXX

REXX Tutorial

 


The purpose of this tutorial is to get you started with REXX when there is no other way - you don’t have time to go to a class, don’t want to buy a complete book on it and try to find the things you need to know.

This is nowhere near being complete. It just gets you going. It’s just a taste of REXX. Start using it. Enjoy it.

REXX is an interpreted language found in several environments, such as the mainframe, midrangem, CMS, CICS, Netview

It is a high level procedural language. It is on the same level as procedural languages such as COBOL, FORTRAN, PLI and C.

It is a complete programming language and includes facilities for reading and writing files, although it is limited to the simplest file structure: ordinary sequential files.

Its strength lies in its ability to do string manipulation, the simplicity of its logic structures and in the presence of many built-in functions that take the place of complex instructions.

It is often used to execute operating system commands under the control of its logic.

It is generally used without compilation, so this limits its execution speed; however this will be offset by the speed of development.

This short paper will talk about the following REXX features of REXX on TSO and CMS:

The initial comment

SAY to display on the terminal

The variable

PULL to accept input from the terminal

DO for looping

EXIT to end your program

Passing commands to TSO or CMS

 

 


Setting up to execute a REXX program under TSO/ISPF.

Create a library or PDS using ISPF option 3.2.

Name:

Its name should end in the type qualifier EXEC,

although this is not a requirement.

Example: ‘userid.REXX.EXEC’

Attributes:

The library should be defined as 80 character record length,

record format FB unless your company has other requirements.

Using the ISPF Editor (option 2) create a member in your REXX library

name it, as an example TESTREXX

type in a short program in REXX,

The following is an example:

/* REXX TESTREXX */

SAY "HELLO THIS IS A REXX PROGRAM"

Type SAVE on the command line.

Make TSO aware of your REXX library.

Type this on the command line:

TSO ALTLIB ACTIVATE APPL(EXEC) DA(‘userid.REXX.EXEC’)

You will need to do this once every time you log on to TSO

and once after you do a "split screen", in the new screen.

Execute your program

Type this on the command line of any ISPF panel,

including the editor:

TSO %TESTREXX

or whatever other member name you used in your REXX library.

The program should execute.

If three asterisks appear on the screen, press ENTER to clear them.

More Information

You can obtain more information about setting up to execute REXX on TSO

at this Web address:

http://theamericanprogrammer.com/programming/rexxsetp.shtml


Setting up to execute a REXX program under VM/CMS.

Using XEDIT create a file to that will contain your program. It will be on your "A" or primary read/write disk.

Name: a two part name.

the first part is up to you, use TESTREXX as an example

the second part must be EXEC

Type this from the READY prompt of CMS or on the command line of the FILELIST (or many other panels)

XEDIT TESTREXX EXEC

Type in your program, for example:

/* REXX */

SAY "HELLO"

An initial comment is required to distinguish REXX. From :EXEC and EXEC2.

Type SAVE on the command line of the editor. You do not need to leave the editor now.

To execute the program,

type CMS TESTREXX on the command line while in the editor.

type TESTREXX at the ready prompt

 

 

 

 


The Initial Comment

For REXX to work in all environments start your program with a REXX comment. The minimum comment required is /* REXX */ starting in column 1 of the first physical line of your program. Other words are allowed inside the comment as well. The ending delimiter, */, may be placed on a different line from the first.

Simplest example:

/* REXX */

SAY "HELLO"

Example with longer comment:

/* REXX program "TESTREXX" to illustrate

whether REXX works or not

*/

SAY "HELLO"

 


SAY - Display on the Terminal

REXX is above all simple. The way to display information on the terminal is with the SAY verb. Anything after the word SAY on the same line will be displayed.

Displaying a literal character string, or constant:

SAY "HELLO THERE"

Arithmetic:

SAY 1 + 1

REXX will gladly do arithmetic on the SAY. Just don’t put the arithmetic operation in quotations!

Variables:

(The next section will describe variables.)

NAME = "SUE"

SAY NAME

 


Variables

REXX makes using variables easy. There is no variable declaration or definition. Consequently there is no datatyping: all REXX variables may contain all types of data.

You first use a variable by assigning it a value.

Assigning a literal value:

NAME = "SUE"

Assigning another variable:

FIRST_NAME = NAME

Doing arithmetic:

TOTAL = 1 + 1

For REXX to see and interpret a variable, revealing what is contained in the variable, the variable must not be in quotations:

SAY NAME


PULL - accept input from the terminal

 

Use PULL with a variable to read in something you type at the terminal. You should place a SAY before the PULL so the user knows what to type in.

SAY "PLEASE TYPE IN YOUR NAME"

PULL NAME

PULL will convert to upper case.


DO for looping

DO allows you to repeat an instruction or several instructions. It can be used to initialize and increment a variable, and continue the loop until the variable is incremented to a certain value. This is equivalent to BASIC’s FOR loop, COBOL’s PERFORM, and most other languages’ DO.

This example will initialize the variable INDEX to 1, increment it by 1 and continue looping until INDEX is greater than 10. While inside the loop it will display the variable I. Running this will produce the numbers 1 through 10.

DO I = 1 TO 10

SAY I

END


EXIT to End Your Program

The verb EXIT will end your program. It is not needed if it would be the last line in your program. It is needed if some other code, such as a subroutine follows the logical end of the program.

 

SAY "PLEASE TYPE IN YOUR NAME"

PULL NAME

SAY NAME

DO I = 1 TO 10

SAY I

END

EXIT

 

 


Passing Commands to TSO

For a discussion of TSO commands, get my paper TSOCMDS at: http://theamericanprogrammer.com/programming/justenuf.shtml

To pass a TSO command to TSO, just place the TSO command first on a line, in quotations.

Here is an example of a very simple TSO command: LISTCAT

It will display a list of catalogued files whose name begins with your TSO userid.

Placed inside of a REXX program it would look like:

/* REXX */

"LISTCAT"

The quotations around LISTCAT are optional in this case due to its simplicity. However you will normally put your TSO commands inside of quotations. This avoids having REXX try to interpret things it shouldn’t be interpreting. The next example will illustrate:

/* REXX */

"SEND ‘HELLO’ USER(TSOUID2)"

It is passing the TSO command SEND ‘HELLO’ USER(TSOUID2) to TSO. TSO understands this command; REXX doesn’t. To keep REXX from trying to understand you place it in quotations. Then REXX treats it as a literal and will not try to interpret it.

It gets a bit more interesting when you have a variable in the TSO command and you do want REXX to interpret the variable. In this case, leave the variable out of the quotations but keep the rest inside.

/* REXX */

USERID = "TSOUID2"

"SEND ‘HELLO’ USER("USERID")"

Although it is confusing to the eye, the variable USERID is outside of quotations and so REXX will see it and interpret it, changing it to its value (TSOUID2) and passing the entire line, as it sees it, to TSO.

It will pass SEND ‘HELLO’ USER(TSOUID2) to TSO.


Passing Commands to CMS

 

To pass a CMS command to CMS, just place the CMS command first on a line, in quotations.

Here is an example of a very simple TSO command: ERASE JUNKDATA DATA A1

It will display a list of catalogued files whose name begins with your TSO userid.

Placed inside of a REXX program it would look like:

/* REXX */

"ERASE JUNKDATA DATA A1"

The quotations around this command are optional in this case due to its simplicity. However you will normally put your CMS commands inside of quotations. This avoids having REXX try to interpret things it shouldn’t be interpreting. The next example will illustrate:

/* REXX */

"MSG * HELLO"

It is passing the CMS command MSG * HELLO to CMS. CMS understands this command; REXX doesn’t. To keep REXX from trying to understand you place it in quotations. Then REXX treats it as a literal and will not try to interpret it.

It gets a bit more interesting when you have a variable in the CMS command and you do want REXX to interpret the variable. In this case, leave the variable out of the quotations but keep the rest inside.

/* REXX */

MESSAGE = "HELLO"

"MSG * " MESSAGE

Although it is confusing to the eye, the variable MESSAGE is outside of quotations and so REXX will see it and interpret it, changing it to its value (HELLO) and passing the entire line, as it sees it, to CMS.

It will pass MSG * HELLO to CMS.

 

 

 

Top of Page





























































































































































































List of books on REXX and other mainframe topics

[Books Computer]

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