Tuesday, September 8, 2009

Introduction to Mainframe REXX


If you are developing or maintaining the traditional mainframe based applications, you would have heard of programming language called REXX (Restructured EXtended eXecutor Language). You may not have had chance to learn it simply because the application was mainly written in COBOL and that was your primary focus. And, most of the training programs, either external or corporate, do not teach REXX as a language in their initial mainframe training.


One fine day, your manager comes and asks you to learn REXX or you are thrust into a project which has lot of REXX code that you need to support. If you are not able to locate good resources to learn it, then it is not your fault. The best books available on REXX are the IBM's official REXX user's guide and reference book. There is another great book called ISPF Services Guide, but never gets mentioned with REXX.

This blog is an effort to make learning REXX easier. You will find easy to understand informal lessons that will clear the concepts and make your understanding of REXX easier.

Without much ado, lets get started.

Basics

The z/OS (MVS, OS/390 are the other names for the same OS) operating system consists of what is called as BCP. There are various components of BCP, that provide various services to the mainframe users. In addition to BCP, we have other common services in day-to-day use like TSO, ISPF, SDSF, etc. The first service that a typical user uses is TSO (Time sharing option). This is the service through which the user logs into the mainframe. The next service is ISPF (Interactive System Productive Facility). This is the service that provides various options to perform the tasks on mainframe, right from editing new programs, compiling programs, checking the output in spool, allocate datasets, and so on. TSO and ISPF are the two key services without which a user can not do anything on mainframe.

However, since z/OS is a command based environment and not graphical environment like windows, everything is done one command at a time. E.g. if you want to allocate a dataset, you need to issue a TSO command, ALLOC. Other option is to traverse the ISPF options to reach the panel that has the allocate option. Essentially, everything that you do on a mainframe is a command. This means that you need to manually perform all the routine tasks. If you perform lots of repetitive tasks on mainframe, it will be time consuming and an inefficient way of doing it.

Enter REXX.

REXX provides a way by which you can automate all your routine tasks. It does this either through a simple program or by using other ISPF facilities like Panels, Skeletons (more about them later). If you have to support REXX programs, understand that they would have been created mainly to automate some ISPF or TSO function. If you have to develop new REXX programs, then understand that you are automating what you would have done manually in ISPF.

What is REXX?

It is a programming language. The power of REXX comes from its ability to interact with all the essential components of the operating system like TSO, ISPF, SDSF, ISPF Editor directly. A REXX program can invoke a command in TSO or ISPF directly.

REXX Interfaces
If you need to allocate say 20 datasets, instead of manually creating those datasets by giving TSO ALLOC command 20 times, you can write a REXX program that loops 20 times and have one TSO ALLOC command. So, by just writing 4 lines of code, you achieve your purpose.

If you need to find out all the datasets that meet some pattern and see if they have some data in it, you can do a 3.4 and give that pattern and manually browse each dataset to see if it is empty. Imagine, how much time it will take if there are hundreds of datasets matching that pattern and if you have to do it daily, it will be simply boring. Instead, you can write a simple rexx program not exceeding 20 lines and you will get your result.

The examples can get increasingly complex and you see how much time you can save by automating such tasks. The other benefit is make the tasks interesting instead of boring, manual and repetitive.

So, there you see, where REXX can help you and what it can do for you.

How does REXX do it?

As mentioned before, REXX has access to all the functions of TSO, ISPF. So, for every function that ISPF provides on its panel, there is a REXX command or a REXX way to access that function. E.g. To allocate a dataset using TSO, you give the command

TSO ALLOC FI(F1) DA('HLQ.FILE1') NEW SPACE(1,1) CYL LRECL(80) RECFM(F B) BLKSIZE(0)

You can issue the same command through a REXX program as

ADDRESS TSO
"ALLOC FI(F1) DA('HLQ.FILE1') NEW SPACE(1,1) CYL LRECL(80) RECFM(F B) BLKSIZE(0)"

So, when you keep this command in a loop, you see how this task can be automated.

Likewise, if you can find a ISPF command, you can run it through REXX. And, the same for any other service available on mainframe.

Note: COBOL or PL/I also have the same capability. However, traditionally their uses are well defined. COBOL is used mainly for Business Applications based on Business Requirements. So, most COBOL programs are written to meet some specific Business requirement. PL/I programs are used for systems oriented tasks where Systems internals need to be exploited. REXX on the
other hand meets mainly programmer's needs. It is used to develop utilities that will reduce time taken to manually perform an operation. There will always be exception to the above classification, but generally that is the norm.

Features of REXX

1. It is a free format language. This means there is no fixed structure to a rexx program. Unlike COBOL where the instruction has to start in a particular column, a REXX instruction can start anywhere in the program line.

2. Lots of built-in functions. It provides a lot of functions to do string manipulations, number functions, Parsing funcitons in addition to the functions provided by ISPF and other services.

3. Very neat debugging capability. It provides an extremely easy to use debug capability.

4. Interpreted Language. REXX is an interpreted language. A compiler is also available. But, most of the programs out there are interpreted.

System Requirements:

To run the tutorials on this blog, you will need access to an IBM mainframe. Though REXX works in both z/OS and z/VM, this blog will focus on REXX on z/OS with TSO and ISPF.

In the next blog, we will see how to run a REXX program and how to set up your TSO sessions to run it efficiently.


© Paras Doshi, 2009.
Page copy protected against web site content infringement by Copyscape

3 comments:

  1. super website on mainframes.......

    if you have time visit my blogs..
    www.mmksworld.blogspot.com

    www.techdealxpress.blogspot.com

    leave ur comments...........

    ReplyDelete
  2. Excellent.... where is your next blog?

    ReplyDelete
  3. How do i read the line in which the cursor is placed using rexx? I tried below but its not returning the line it reads?

    "(Memline)= line .ZCSR"

    ReplyDelete