Sunday, September 20, 2009

Tutorial 2: REXX Syntax

Rexx is a free format language. It doesn’t have strict rules like Assembler, COBOL etc.

Rexx program must start with “REXX” within the first line (line 1) of the program. Usually, you will write /* REXX */ in the first line. Though if the first line is /* This is a REXX program */, it is perfectly valid.

You can have two REXX commands in the same line. They need to be delimited by semicolon - ;.

A = A + 1; B = B + 1; C = C + 1

A REXX instruction can be continued on the second line. Comma - , is used for this.
MESSAGE = ‘ This line is very long and needs to be continued’,
‘ on the second line’

The following are various symbols used.

Arithmetic Operators

+ Add
- Subtract
* Multiply
/ Divide
% Divide and return a whole number without a remainder
// Divide and return the remainder only
** Raise a number to a whole number power
-number Negate the number
+number Add the number to 0

Logical Operators

& AND
| Inclusive OR
&& Exclusive OR
\ Logical NOT

Comparison Operators
== Strictly Equal : The two strings must be identical (character by character) and of the same length to be considered strictly equal. Eg. “ “ == “ “ is false.

= Equal
\== Not strictly equal
\= Not equal
> Greater than
< Less than
><>
>= Greater than or equal to
\< Not less than
<= Less than or equal to
\> Not greater than

The not character, "¬", is same as the backslash ("\").

A REXX symbol or variable can consist of
A...Z uppercase alphabetic
a...z lowercase alphabetic
0...9 numbers
@ # $ ¢ ? ! . _ special characters

Rules for valid REXX variables are:

1. The first character cannot be 0 through 9 or a period (.)
2. The variable name cannot exceed 250 bytes
3. The variable name should not be RC, SIGL, or RESULT, which are REXX special variables

Compound Variables OR Arrays OR STEMs

Compound variables are a way to create a one or multi dimensional array or a list of variables in
REXX. Subscripts do not necessarily have to be numeric.

A compound variable contains at least one period with characters on both sides of it.
The following are examples of compound variables.

ARRAY.5
Array.Row.Col
employee.name.phone

The first variable in a compound variable always remains a symbol with no substitution. The remaining variables in a compound variable take on values previously assigned. If no value was previously assigned, the variable takes on the uppercase value of the variable name.

This means that if Row = 1 and Col = 2 then,
Array.Row.Col will mean Array.1.2 and if value assigned to this is '123' then,
Array.1.2 = '123'

However, if no value is assigned to this, then
Array.1.2 = 'Array.1.2'

This applies to single and multi-dimensional arrays.

You can initialize an array through this simple method,

Array. = 'Initial value'

This will make all the elements of this array take on the value 'Initial value'. This means,
Array.1.1 = 'Initial value'
Array.1.2 = 'Initial value'
Array.n.n = 'Initial value'

Concatenation Operators

To combine two items into one item, concatenation operator is used.


blank:

Concatenate terms and place one blank in between. Terms that are separated by more than one blank default to one blank when read. For example:
SAY true blue /* result is TRUE BLUE */

|| :
Concatenate terms and place no blanks in between. For example:
(8 / 2)||(3 * 3) /* result is 49 */

abuttal:

Concatenate terms and place no blanks in between. For example:
per_cent'%' /* if per_cent = 5o, result is 5o% */

Data Types

REXX being a free format language, there are no fixed data types that need to be declared before a variable can use a particular data type. A data value can be assigned directly to a variable and can be changed as required.

Eg. You can use the following assignment

Variable1 = 100

without Variable1 being defined/declared as of numeric data type.

In the next instruction the same variable can be assigned a Alphanumeric value.

Variable1 = ‘NUMBER100’

For the internal processing purpose a value is classified as any of the following data types.

A - Alphanumeric
N - Numeric
W - Whole number
L - Lowercase
U - Uppercase
M - Mixed case



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

Wednesday, September 9, 2009

Tutorial 1: The first REXX program and How to run a REXX Program

The first REXX program is very simple. It calls out the world.

/* REXX */
SAY 'HELLO WORLD'

Put this in a PDS member (ideally, create one like myhlq.REXX.EXEC).

Now, there are various ways by which you can invoke a REXX program.

1. From ISPF main panel, run the command

TSO EX 'myhlq.REXX.EXEC(HELLO)' EX


2. From READY Prompt, run the command,

EX 'myhlq.REXX.EXEC(HELLO)' EX


3. Using 3.4, browse to the PDS myhlq.REXX.EXEC.
Before the member HELLO, enter EX and press enter.

The above are the manual methods. What follow below are smart methods to run REXX program.

To understand the smart way, it is first important to undestand the concept of REXX libraries.
When you logon to ISPF, ISPF assigns a pre-defined set of DDNames to few PDS datasets. To view this set, you can enter the command TSO ISRDDN from the ISPF panel.

From the list displayed, the DDnames of interest here are SYSEXEC and SYSPROC. The PDS datasest shown against these DDnames are the PDS that TSO will look for, when you don't specify the PDS name and just specify the REXX program name to run. If you want to run your REXX program the smart way, you need to assign your personal PDS (myhql.REXX.EXEC) to this list for SYSEXEC or SYSPROC.

There are two ways to do this.

i. If your system adminstrator allows, you can run a CLIST or REXX program when you logon to ISPF. This will usually appear as a message when you logon. Ask you system admin if you can do this, as this is the best way to do this.
If it is a CLIST, add the following command in the CLIST,

CONCATD FI(SYSEXEC) DA('myhql.REXX.EXEC')

If it is a REXX, add the following command,

"ALLOC FILE(SYSEXEC) DATASET("'myhql.REXX.EXEC'","'isp.rexx.exec') SHR REUSE"

Note that in this case, you need to specify all the existing allocations to SYSEXEC (from ISRDDN). If you just specify your PDS in the DATASET, then the existing allocations will be lost.

ii. If the system admin does not allow running a REXX/CLIST, then execute the following command one time in your ISPF session.

TSO ALTLIB ACTIVATE APPL(EXEC) DSN('myhlq.REXX.EXEC')

The drawback of this method is that it works only in the session that you execute from. If you have more than one session open using split screens (this is the norm nowadays), you need to execute this command in all your sessions.

So, work out the best way that works for you.

Once the above is done,

4. You just need to execute command from ISPF,

TSO HELLO

5. From READY prompt, just enter

HELLO

6. You can also run the REXX program through a JCL. The following is the JCL step that you need.


//REXXBTCH EXEC PGM=IKJEFT01
//SYSEXEC DD DSN=MYHQL.REXX.EXEC,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSTSIN DD *
%HELLO
/*

If you have ISPF services within your REXX, then you need additional DDnames in your JCL step. You will essentially start ISPF in batch and then run the rexx program so that all the ISPF services are available when it runs in batch.

//REXXBTCH EXEC PGM=IKJEFT1B
//ISPLLIB DD DISP=SHR,DSN=USER.ISPLLIB
//ISPPLIB DD DISP=SHR,DSN=ISP.SISPPENU
//ISPMLIB DD DISP=SHR,DSN=ISP.SISPMENU
//ISPSLIB DD DISP=SHR,DSN=ISP.SISPSENU
//ISPPROF DD DSN=&TEMPPROF,DISP=NEW,PASS,DELETE)
//ISPLOG DD SYSOUT=*,DCB=(RECFM=VA,LRECL=125,BLKSIZE=129)
//ISPTABL DD DISP=SHR,DSN=&TEMPPROF
//ISPTLIB DD DISP=SHR,DSN=&TEMPPROF
// DD DISP=SHR,DSN=ISP.SISPTENU
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSEXEC DD DISP=SHR,DSN=MYHLQ.REXX.EXEC
//SYSTSIN DD *
ISPSTART CMD(%HELLO)
/*

Add additional DDnames as required in your installation. Contact your system admin for the correct list of concatenations required.


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

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