Beruflich Dokumente
Kultur Dokumente
SESSION 1
Introduction to REXX
REXX basics
REXX Instructions
REXX Built-in Functions
REXX External functions
REXX TSO/E External commands
SESSION 2
Executing REXX in BATCH mode
Introduction to REXX Edit macros
Examples on REXX Edit macros
File Tailoring
ISPF Tables
REXX Quiz
What is REXX after all ?
Restructured EXtended eXecutor language
Programming Language
Free format language
Issues commands to different Host
environments
Has extensive mathematical capabilities
Suitable for beginners as well computer
professionals
USAGE of REXX
• Automating repetitive tasks
- Increases productivity
- Ex : Allocation of datasets for a release
- Ex : Deleting 7th char in all records of a file
• Interacting with TSO/ISPF dialog manager
- to create and display custom-made panels
- can store and retrieve variables
• Creating new commands
- Like TIME command, DATE can be created
• For personal programming tasks
- to send a mesg to other MVS users everytime you
logon
Writing a simple REXX exec
• An exec is nothing but a group of REXX statements in a
sequential dataset or a PDS member
• The first statement of an exec should be ‘ /* REXX */ ’,but
not in all cases
• A simple exec (In a PDS member,MYFIRST)
/*REXX*/
SAY ‘This is first REXX exec’
EXIT
• REXX is case insensitive
Executing a REXX exec
• Explicit execution from tso ready prompt
READY
EXEC ‘TATA.REXX.EXEC(MYFIRST)’ EXEC
READY
• Implicit execution requires the PDS library to be
concatenated to either SYSEXEC or the SYSPROC system
DDNAME’s.
READY
ALLOC DD(SYSEXEC) DSN(‘TATA.REXX.EXEC’) SHR REUSE
READY
%MYFIRST
From ISPF,one can execute it by issuing the following command at
command prompt
TSO MYFIRST
Executing a REXX exec
• A sequential dataset needs no allocation
• It can only be executed using the explicit method or the
long form
• From READY prompt,
READY
EXEC ‘TATA.SEQ.EXEC’ EXEC
READY
• CTP LOGON ALLOCATION
In CTP main panel,
Select 0 --> CTP parms
REXX - 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
REXX - Logical operators
& AND
(4 > 2) & (a = a) /* true, so result is 1 */
(2 > 4) & (a = a) /* false, so result is 0 */
| Inclusive OR
(4 > 2) | (5 = 3) /* at least one is true, so result is 1 *
(2 > 4) | (5 = 3) /* neither one is true, so result is 0 */
&& Exclusive OR
(4 > 2) && (5 = 3) /* only one is true, so result is 1 */
(4 > 2) && (5 = 5) /* both are true, so result is 0 */
Cool Man!
Life Made Easy…
REXX Instructions
•A line contains usually one instruction
• Comma(‘,’) is the continuation character
• Semi-colon(‘;’) is the instruction delimiter
• Example :
say ‘The quick fox jumps over’,
‘the lazy brown dog’; say ‘over’
Output :
The quick fox jumps over the lazy brown dog
over
• Note that the comma operator adds a space
REXX Instructions - SAY
• To write a line of output to the TSO terminal
• Syntax
SAY {expression}
• Expression can be of any size and REXX will split it up
according to line-width of the terminal
• Expression can contain variables, literals and functions
• Example
/*REXX*/
name=‘Roosevelt’
say ‘Welcome to TSO ‘ name
exit
• Output
Welcome to TSO Roosevelt
REXX instruction - PULL
• to read the input from the TSO terminal(When REXX data
stack is empty)
• Syntax : PULL var1 var2 var3…
• Example :
/*REXX*/
say ‘Enter your name :’
pull name
say ‘Good morning ‘ name
exit
• The output will be
Enter your name :
Lincoln
Good morning LINCOLN
• Note that PULL automatically converts input into
uppercase
REXX Instruction - UPPER
• to translate the contents of a single or several variables to
uppercase
• Syntax : UPPER var1 var2 var3 …
• Example :
/*REXX*/
name=‘Kennedy’
say ‘Name is ‘ name
upper name
say ‘Now name is ‘ name
exit
• Output
Name is Kennedy
Now name is KENNEDY
REXX Instruction - EXIT
• Used to unconditionally leave a program
• Can optionally pass back a string to the caller
• Syntax : EXIT {expression}
• Example named PROG2
/*REXX*/
a=10
exit a*10 /* passes back string 100 to the caller */
• When prog2 is called in an exec as x=prog2(),then x will
have the value 100
REXX Instruction - IF
• Used to conditionally execute a single REXX stmt or a
group of REXX statements
• Syntax : If expression then stmt;
else stmt;
• If expression is evaluated TRUE(1) then the THEN part is
performed and if FALSE(0) then the ELSE part is
performed.
• A group of REXX statements can be grouped together by
using DO…END
• Nested IF’s are allowed in REXX.
REXX Instructions - NOP
• The output
1
2
Contd...
REXX Instructions - DO
• Do..Until construct
/*REXX*/
I=1
Do until I > 3
say I
I= I+ 1
End
• The output will be
1
2
3
Contd...
REXX Instructions - DO
• The Do..Forever special construct
/*REXX*/
Do forever
say ‘infinite loop’
end
• The above exec results into an infinite loop
• Enough care should be taken to check the exit criteria of
the loop, before executing the exec
• The LEAVE instruction can be used to exit from the loop
REXX Instructions - LEAVE
• Causes REXX to stop executing the current DO-END loop and
control passes to the next statement after the END of the DO-END pair
• Syntax : LEAVE {name}
• Example
/*REXX*/
Do forever
Say ‘Enter the code :’
Pull code
If code = ‘BYE’ then Leave;
end
Exit
• The above exec will prompt the user for a code until the user enters
the code ‘BYE’.
• The ‘name’ will be used to exit from a particular loop in case of
several nested do loops
REXX Instructions - ITERATE
• Used to restart execution in a DO loop
• Syntax : ITERATE {name}
• If name is not specified ,ITERATE will step the innermost
active loop
• If name is specified,that particular loop is stepped
• Example
/*REXX*/
Do I = 1 to 3 by 1
If I = 2 then iterate I; /* name is not required */
say ‘I = ‘ I
end
• Output
I=1
REXX Instructions - SELECT
• Causes REXX to execute one of several different
instructions
• Most used when one of the several paths must be followed
• Example :
/*REXX*/
Say ‘Enter 1 for salad,2 for pizza :’
pull choice
select
when choice = 1 then say ‘Here is the salad’
when choice = 2 then say ‘Here is the pizza’
otherwise say ‘You have opted nothing’
End
• When the input is anything other than 1 or 2 then the
control is transferred to OTHERWISE clause.
REXX Instructions - INTERPRET
• Used to execute instructions that are built dynamically
• Allows to build the REXX statements in an exec
• Syntax : INTERPRET expression
• Example :
/*REXX*/
out='say hi there!!!'
Interpret out
stmts='do 3; say 'loop'; end'
Interpret stmts
exit
• Output will be
HI THERE!!!
LOOP
LOOP
REXX Instructions - NUMERIC
• Sets controlling limits that govern how REXX evaluates
and reports the results of arithmetic operations
• Syntax : NUMERIC DIGITS {expression}
• This tells REXX how many significant digits to use when
calculating and printing results
• Syntax : NUMERIC FORM { SCIENTIFIC | ENGINEERING }
• This tells REXX how arithmetic values that must be
expressed in exponential notation will be presented
• NUMERIC FUZZ {expression}
• This determines how much two numbers can be different
from each other and still be considered equal by REXX
REXX Instructions - NUMERIC
• Example
/*REXX*/
numeric digits 4
numeric fuzz 1
a=1000
b=1004
if a = b then say equal
else say unequal
exit
• Output
EQUAL
• Since the FUZZ value is 1,the rightmost is not considered
in the comparison.
• In the same example ,note that when B takes value 1005
and numeric digit is 5 ,the output is UNEQUAL ,as REXX
rounds off the value of B to 101,while eliminating its
rightmost digit
REXX Instructions - NUMERIC
• Numeric form scientific causes REXX to always place one
non-zero digit to the left of the decimal point
• Numeric form engineering makes REXX use powers of ten
in exponential notation that are always a multiple of three
• Example
/*REXX*/
numeric digits 5
numeric form scientific
a=123.45 * 1e11
say a form() /* 1.2345E+13 SCIENTIFIC */
numeric form engineering
a=123.45 * 1e11
say a form() /* 12.345E+12 ENGINEERING */
exit
REXX Instructions
• Tells REXX how to assign data to-one
PARSE
or more variables
• PARSE NUMERIC name returns the current settings of
numeric options DIGITS,FUZZ and FORM
• PARSE PULL makes REXX get the string from the REXX
data stack.If the stack is empty,REXX will get the string
from the terminal
• PARSE VALUE parses a string under the control of the
template
PARSE VALUE expression WITH template
• PARSE VAR indicates that the string to be parsed is not a
literal but a variable
• PARSE VERSION returns REXX interpreter level and the
date released
REXX Instructions - PARSE Ex.
• parse value ‘Napolean the great’ with w1 w2 w3
w1 = Napolean w2 = the w3 = great
• parse value ‘Napolean the great’ with w1 9 w2
w1 = ‘Napolean ‘ w2 = ‘the great’
• parse value 'salt+water=brine' with w1 '+' w2 '=' w3
w1 = salt w2 = water w3 = brine
• parse version vervar
say vervar
REXX370 3.48 01 May 1992
REXX Instructions - DROP
• Used to return one or more REXX variables to their initial
or uninitialised state
• Syntax : DROP name1 name2 name3….;
• Same variable can be dropped more than once
• Examples
drop a /* Unassigns the variable a*/
drop z.5 /* Unassigns the stem variable z.5 */
drop d. /* Unassigns all the vars starting with d. */
REXX Instructions - ADDRESS
• To indicate the destination of non-rexx commands
• Syntax ADDRESS destination
• The destination could be any one of these
TSO - Routes commands to TSO
ISPEXEC - Routes commands to ISPF/PDF
ISREDIT - Routes commands to the ISPF Edit macro
processor
Note : Other destinations exist,but beyond the scope of this
training
• Example :
Address tso ‘lista st’ /* the destination is set */
‘listds(‘tcs.rexx.exec’) members’ /* to TSO */
Address ispexec /* Dest. Changed and set */
REXX Instructions - Procedure
• used to protect the variables in existence when the function
or subroutine is called
• When a RETURN instruction is executed by the called
function or subroutine ,all variables saved by the
PROCEDURE instruction are restored to the state they were
in when saved
• Syntax : PROCEDURE { EXPOSE name1 {name2}…}
name1, name2 are not protected from the subroutine.That is
they are exposed to the subroutine
REXX Instructions - Procedure
Example
/*REXX */
lines=2
pages=3
call showlyns
say 'The line count is' lines ',the page count is' pages
/* 'say' above displays 10 for lines and 3 for pages */
exit
• Syntax : COPIES(string,n)
• Examples
COPIES('Hello',4) returns 'HelloHelloHelloHello'
COPIES('Say what?',0) returns '' (null string)
REXX Functions - DATATYPE
• used to determine the data type of the string passed
• Syntax : DATATYPE(string{,type})
• If type is omitted,NUM is returned if the string is a valid
number and CHAR is returned in all other cases
• If type is specified,either TRUE(1) or FALSE(0) is returned
• The valid types are as follows
A - Alphanumeric
N - Numeric
W - Whole number
L - Lowercase
U - Uppercase
M - Mixed case
• Examples
DATATYPE(' 44 ') returns NUM (numeric)
DATATYPE('*1**') returns CHAR (caharcter string)
DATATYPE('Wally','M') returns a 1 (mixed case)
DATATYPE('75.54','W') returns a 0 (not a whole number)
REXX Functions - DATE
• returns the current date
• An optional character can be passed to obtain date in
specific formats
• Syntax : DATE({option})
• Some of the chars that can be passed are
U returns date in USA format, 'mm/dd/yy’
J returns a Julian date in the form 'yyddd’
W returns the day of the week (e.g. 'Tuesday', 'Sunday', etc.)
• Examples
say date() /* returns 17 Dec 1999 */
say date('U') /* returns 12/17/99 */
say date('J') /* returns 99351 */
say date('W') /* returns Friday */
REXX Functions - DELSTR
• used to delete or remove one string from within another
string
• Syntax : DELSTR(string,n{,length})
• 'string' is the string from which a portion is to be deleted
starting with character number 'n', where 'n' is a positive
integer
• The length of the portion to be deleted is given by the
optional length parameter
• When ‘n’ is greater than the length of the string no action is
performed
• Examples
DELSTR('abcde',3,2) deletes 'cd', leaving 'abe'
DELSTR('zyxw',3) leaves 'zy', deleting 'xw'
DELSTR('12345',6) no change, since 6 is greater than string length
REXX Functions - DIGITS
• Takes no parameters
• Example
LENGTH('LIFO') returns 4
LENGTH('Rubber baby buggy bumpers') returns 25
LENGTH('') returns 0 (null string)
REXX Functions - MAX
• returns the maximum numeric value from a list of
numeric values
• Syntax : MAX(number{,number}...)
• The size of the numeric value returned is limited to the
current setting of NUMERIC DIGITS.
• Up to 20 numbers may be specified as arguments to
MAX.
• Calls to MAX can be nested if more are needed
• Examples :
MAX(21,22,81,67) returns 81
MAX(27.32,0.45,102.3) returns 102.3
• The MIN function is similar to MAX except that it returns the
minimum value
REXX Functions - POS
POS('M','ABCDEFGHIJKLMNOPQRSTUVWXYZ') returns 13
/*REXX*/
x=outtrap("a.") /* turns trap on. x=a. */
"listds 'rhkrish.rexx.exec' members"
x=outtrap("off") /* turns trap off. x=off */
say 'No of lines trapped ' a.0
OUTTRAP - External function
Contd..
• The output of the exec could be this
No of lines trapped 57
• Note that the no of lines trapped is stored in A.0
• All the trapped lines from A.1 to A.n can be used
• The outtrap function can be used to trap only a certain no
of lines.
OUTTRAP(“A.”,10)
Only 10 lines trapped.
SYSDSN - External Function
• Returns OK if the specified dataset exists; Otherwise
returns appropriate error messages
• Example call
available = SYSDSN(“’tcs.rexx.exec’”)
/* available could be set to "OK" */
"QSTACK" /* returns a 1 in RC */
"NEWSTACK" /* creates a new data stack*/
"NEWSTACK" /* creates another new data stack*/
"QSTACK" /* returns a 3 in RC */
REXX Command - EXECIO
• used to perform read and write operations against a
sequential dataset or a pds member
• The data is either read from the data set and placed on the
data stack or into a list of variables, or written from the data
stack or a list of variables into the data set
• Syntax for read operations :
Address TSO
"ALLOC F(IN) DA('SYS1.PROCBLIB(ASMHCL)') SHR"
"ALLOC F(OUT) DA(‘TATA001.DELETE.ME’) SHR"
"FREE F(IN,OUT)"
SAY ‘No of lines in input : ‘ data.0
EXIT
Note : This example uses stem variable data to read the contents of input
file.The Number of lines read will be stored in data.0.
Executing REXX in Batch
Executing REXX in batch
Need arises when the REXX exec takes longer time
to complete the execution.So time-consuming and low
priority execs can be run in background
Main advantage - Batch mode does not interfere with
persons use of the terminal
Only those execs which do not require any sort of
terminal interaction can be run in batch mode.
A JCL as shown in the next slide can be used to
invoke a REXX exec.
Executing REXX in Batch - JCL
//TSOBATCH EXEC PGM=IKJEFT01,DYNAMBR=30,REGION=4096K
//SYSEXEC DD DSN=TCS.REXX.EXEC,DISP=SHR
//SYSTSPRT DD SYSOUT=A
//SYSTSIN DD *
% SETUP
/*
//
The following points are to be noted :
• IKJEFT01 - TSO command processor program
• SYSEXEC - System DD card to which REXX libraries
are concatenated
• SYSTSPRT - Destination of the REXX output,as well
the TSO command processor
Contd.….
Executing REXX in Batch - JCL
Contd.….
• SYSTSIN - Instream card wherein TSO commands or
invocation of REXX execs can be issued
• The dataset TCS.REXX.EXEC is a PDS and has a
member of the name SETUP.
• The Instream data can be used to invoke an REXX exec
either implicitly or explicitly as indicated below
%SETUP >>>> Implicit
EXEC ‘TCS.REXX.EXEC(SETUP)’ EXEC >>>> Explicit
positioned
.ZFIRST The first data line Can be abbreviated .ZF
.ZLAST The last data line. Can be abbreviated .ZL
• Advanced panels
Point and Shoot Fields
Action Bar Choice
ISPF TABLES
ISPF Tables
• Example
“ISPEXEC TBSCAN FSTATUS ARGLIST(FCODE)”
• Example
/*REXX*/
address ispexec
"libdef isptabl dataset id('rhkrish.test.tables')"
"tbcreate rexxerr keys(ecode) names(etext) write"
do i = 1 to 49
ecode=i
etext= errortext(i)
"tbadd rexxerr order"
end
"tbclose rexxerr"
exit
ISPF Tables - Example - 2
• Searching the table for a particular value
/*REXX*/
address ispexec
"libdef isptabl dataset id('rhkrish.test.tables')"
"tbopen rexxerr nowrite"
say 'enter the error code (1-49) :'
pull ecode
"tbscan rexxerr arglist(ecode)"
if rc = 0 then say 'The error mesg is ' etext
else say 'row does not exist'
"tbclose rexxerr"
say 'Error mesg using function-' errortext(ecode)
exit
ISPF Tables - Example 3
• Displaying all the rows of a table
/*REXX*/
address ispexec
"libdef isptabl dataset id('rhkrish.test.tables')"
"tbopen rexxerr nowrite"
"tbskip rexxerr"
if RC ¬= 0 then do
say 'tbskip error RC - ' RC
exit
end
say "ECODE ETEXT"
do while RC = 0
say ecode etext
"tbskip rexxerr"
end
"tbclose rexxerr"
exit
List of References
• REXX in the TSO Environment - Gabriel F.Gargiulo
• Book manager in MVS
• Shelf Name Description
TSO_V2R5 TSO/E V2R5 Bookshelf
ISPF_V42 ISPF 4.2 for MVS Library
• Book Name Book Title
IKJ2C307 TSO/E V2R5 REXX/MVS User's Guide
ISPEEM01 Edit and Edit Macros
ISPSRV01 Services Guide