Mainframes 360
The one stop destination for System Z professionals

Saturday, March 10, 2012

Introduction to Rexx

Q. What is Rexx? Is Rexx easy to learn? Why should I program in Rexx?
250px-Rexx-img-lgThe acronym Rexx stands for REstructured eXtended eXecutor. Rexx was developed in the year 1979, by a programmer, Mike Cowlishaw, who is now a visiting professor at the University of Warwick. The language Rexx is recommended for beginners, because it has a simple instruction set – just a couple of dozen instructions.

Rexx is a free-form language. Unlike COBOL, a Rexx program does not have a definite structure – like DIVISIONs, SECTIONs and Paragraphs.

COBOL Programs have to be compiled(translated) to machine code, before you run them. On the other hand, Rexx is an interpreted language. Once you code a Rexx Program, you don't have to compile it. Instead, the Rexx Interpreter simply reads your source-code one line at a time, interprets it and executes it.

One of the reasons, why you should learn Rexx, is that it increases the productivity of the average Mainframe Programmer. Repetitive tasks which are tedious, and require manual labour can be automated using Rexx. Just like you use the FIND, CHANGE, SAVE Commands in the ISPF Editor, you may code your very own custom commands using Rexx. 

Rexx programs you can talk to other software applications that run on the Mainframe. A Rexx program can talk to the TSO Software. Like Windows on the PC Platform, ISPF is the Graphical User-Interface(GUI) software on the Mainframes platform, to do day-to-day common tasks such as creating files, editing files, deleting files etc. You can write a Rexx program, that ADDRESSes(talks to) ISPF. Rexx integrates beautifully with DB2, SDSF etc. Has it crossed your mind, you can write COBOL Programs too, to do all that I've said above. But, as a norm, you generally write programs in COBOL to implement business rules, build an Insurance Product like a Annuities system, or a banking product.
Q. How do you code comments in Rexx? What is the SAY instruction?
Comments in Rexx must be enclosed within a /* and a */. Every Rexx program should contain the word "Rexx" in its first line of source-code. Usually this will be a comment.

Its a good practise that you liberally sprinkle your Rexx Program with comments, explaining the purpose and meaning of the code. This helps your friends understand your code.

The SAY Instruction in Rexx is used to display text on the Mainframe Terminal. The syntax of the SAY Instruction is as follows -

SAY expression

Here's a simple Rexx Program to get you started with.


The SAY <expression> Instruction always prints the value of the expression on the Mainframe terminal. For example, say 'Hello World' would display Hello World on the screen.

Rexx does not require you to explicitly declare variables. For example, the variable number is assigned the integer-value 5. So, say number would display the value 5 on the Mainframe Screen. The variable text is assigned the character string 'I am learning Rexx'. say text would display 'I am learning Rexx' on the screen.
Q. How do I execute or run my Rexx Program?
To execute a Rexx Program, a simple and easy way is to type the character 'ex' as in execute, against the member-name in the Personal Data-set(PDS) Library you are using to store your Rexx Programs. I am going store all my Rexx Programs in my library SYSADM.DEMO.REXXLIB. The name of my program is REXX01. Look at the below screenshot, on how to run REXX01.


I typed ex against the member-name REXX01, and pressed Enter. Here's the output, you should be able to see.

Q. What are the Layout-rules in Rexx? What are Literal-strings?
As a kid, when you learnt cursive-writing at an early age, you follow some rules. Letters like an 'a' and 'o' should be of similar height. Every letter should have the correct slant.

Likewise, you should possess some fundamental knowledge about the rules in Rexx programs.

1. Start every sentence(instruction) on a new line. Rexx presumes that with a new-line, begins a new instruction. To continue an instruction over to the next line, put a

2. If you code two instructions on the same line, separate them with a semi-colon(;).

3. In computer programming languages, it is common to indent program source-code to improve readability. Learn to indent rexx instructions inside if-conditions, loops etc.

4. Don't make your program look stuffed. Liberally use, whitespace. Compilers and interpreters usually ignore whitespaces.

To many people who are thrown to work at a mainframe computer on their first job, they feel lost. Mainframe people seem to speak a completely different language and that doesn't make life easy. What's more, the books and manuals are incredibly hard to comprehend.

"What on earth is a Mainframe?" is an absolute beginner's guide to mainframe computers. We'll introduce you to the hardware and peripherals. We'll talk about the operating system, the software installed on a mainframe. We'll also talk about the different people who work on a mainframe. In a nutshell, we'll de-mystify the mainframe.

Readers based in India, can buy the e-book for Rs. 50 only or the print book. International readers based in the US and other countries can click here to purchase the e-book.