Return to sysprog.net home page

españolfrançaisdeutsch

SITE SERVICES
Contact Us
Search
Site Map

NEWS
Business
Enterprise
Job Market
Security
Technology
Vendor

PROGRAMMING
Assembler
C and C++
COBOL
Java and XML
REXX

TOPICS
Business
Hardware
IT at Work
Linux
Management
Project Mgt
OS390 and zOS
Research
Storage
Testing & QA

TOOLS
Books
Magazines
Manuals
Organizations

Home —» REXX

REXX for mainframes


REXX is the language of choice for building workaday programming tools. It is a sensible alternative to Assembly Language for panel handling under ISPF and for parsing reports and other text-based input. REXX execs are easy to change and don't need to be compiled. The in-built TRACE function makes them simple to debug.

OS/390 REXX scripts can run in any MVS address space. For example, they can run as either batch jobs or TSO/E execs. They can issue TSO/E commands and use ISPF services, such as file tailoring, library management and panel display.

For more information on generating Java code using REXX see IBM's NetREXX home page.

Setting Up a User REXX Library

The following steps will set up a standard REXX library, so that REXX execs can be invoked from the TSO/E command line by member name only:

• Identify any existing libraries allocated to SYSEXEC:

==> TSO ISRDDN

• Allocate a Fixed Block, 80-byte PDS called: userid.REXX.EXEC

• Save the following text into a member called SETUP in the REXX library, changing lib1, lib2 etc. to the libraries already allocated to SYSEXEC:

/**** REXX ******************************/
/* Allocate User REXX Library to SYSEXEC*/
/****************************************/

"ALLOC FI(SYSEXEC) DA(REXX.EXEC,",
    "'lib1','lib2','lib3') SHR REUSE"

IF RC = 0 THEN
  ZEDSMSG = 'SYSEXEC allocated'
ELSE
  ZEDSMSG = 'SYSEXEC allocation failed'

"ISPEXEC SETMSG MSG(ISRZ000)"

RETURN

• Allocate the user REXX library to SYSEXEC:


==> TSO EX REXX.EXEC(SETUP) EX

Running a Sample REXX Exec

This is an example of a simple REXX exec edit macro. It excludes all lines of the member being edited except those containing the string specified.

• Save the following text into a member called IN in the REXX library:

/**** REXX ************************************/
/* Exclude all lines except those with string */
/**********************************************/

"ISREDIT MACRO (string)"

"ISREDIT X ALL"
"ISREDIT F ALL" (string)

RETURN

• Run the exec by typing the following on the TSO/E command line, replacing 'string' with the text to search for. If the text contains blanks, enclose it in apostrophes.

==> IN string


Edit Macros

One of the most useful REXX execs is an edit macro to change a specified string in all members of a PDS. In this example the driver EXEC is called DOEDIT, and the edit macro containing the string to change is called CHGALL.

• Save the following text into a member called CHGALL in the REXX library:

/**** REXX ***/
"ISREDIT MACRO"
"ISREDIT X ALL"
"ISREDIT C ALL 'dr jekyll' 'mr hyde'"
RETURN


• Save the following text in the REXX library as member DOEDIT:

/************************ REXX ********************************/
/* Edit all members of the currently allocated PDS except the */
/* member being edited. Pass name of edit macro as only parm. */
/**************************************************************/
"ISREDIT MACRO (editmac)"
/* Identify currently open PDS */
"ISREDIT (openpds) = DATAID"
/* Identify currently open member */
"ISREDIT (openmbr) = MEMBER"

/* Open PDS for input */
ADDRESS ISPEXEC
"LMOPEN DATAID("openpds") OPTION(INPUT)"
mbr = ' '
saverc = 0

/* Call edit macro for each member */
DO WHILE saverc = 0
  "LMMLIST DATAID("openpds") MEMBER(mbr) OPTION(LIST) STATS(NO)"
  saverc = rc
  IF (saverc = 0) & (mbr \= openmbr) THEN DO
    "EDIT DATAID("openpds") MEMBER("mbr") MACRO("editmac")"
  END
END

/* Free and close PDS */
"LMMLIST DATAID("openpds") OPTION(FREE)"
"LMCLOSE DATAID("openpds")"

EXIT


• Now any PDS can be edited by opening a new member in the PDS for edit (it needn't be saved) and typing on the TSO/E command line:

==> DOEDIT CHGALL


Tips and Tricks

• It's easier to spot syntax errors when editing REXX execs if they display in color. To turn colors on, enter HILITE REXX on the TSO/E command line. The result should look like this:

/* Read each line for update */
DO cnt = 1 to max WHILE eof ='NO'
  "EXECIO 1 DISKRU TESTDD"

• For tips on date formats in REXX execs, check out IBM's article on Handling DATES with REXX.

• See also Google Group: comp.lang.rexx.


TOP OF PAGE When a thing has been said, and said well, have no scruple. Take it and copy it. (Anatole France)