Restructured Exented Executor: Nagaraju Domala
Restructured Exented Executor: Nagaraju Domala
Restructured Exented Executor: Nagaraju Domala
Nagaraju Domala
REXX – Types
Nagaraju Domala
If If then else
Do End
Do While
Select
(case)
Nagaraju Domala
Do Until
Do Forever
Leave
Nagaraju Domala
REXX – Books
Nagaraju Domala
REXX – Example Apps
Using Rexx to Power a Web Site, by Jim Standley
A Rexx-based Application Server, PDF file from Don Bourdage and Michael Beer
What’s Right with Rexx-- Using Rexx for General Application Development, PDF file by Gil Barmwater
A NetRexx Application Using Hibernate and JSF, PDF file from Rene Jansen
Tracking Gas Balloons with Rexx, PDF file from Christian Michel
On Demand Computing with Rexx, PDF file from Michael Beer
A Rexx-based Intranet Solution, PDF file from Johann Taschler
A Large NetRexx Application, PDF file from Rene Jansen
A Large Mainframe REXX Application, PDF file from Anthony Rudd
DB-123: A New Tool for Database and IT Migrations, PDF file from Thomas Schneider
The Stellar Sector Generator, by Stephan Aspridis
PPWizard, a pre-processor for HTML, Rexx, Visual Basic, or any other kind of text file, by Dennis Bareis
MemoWiki, this “personal wiki” tool is written in Rexx.
DLS Change Management System for OPS/MVS, PDF file about automating OPS/MVS, from Freddy Sonnemans
Job Processing System (JPS), PDF file about a scheduler written in Object Rexx, file from Morten Mork
Open Source Telephony, PDF file about moving to open source using Object Rexx, from David Ruggles
Discover Real Problem Solving with ooRexx and Excel Automation, PDF file from Les Koehler
http://www.rexxinfo.org/html/example_apps.html
Nagaraju Domala
Day II
Functions
Nagaraju Domala
Functions and Subroutines
Nagaraju Domala
Functions
Sequence of instructions that can
Receive data
Process that data, and
Return a value
Syntax is function(arguments)
Nagaraju Domala
Functions
Built-in functions -- These functions are built into the
language processor.
Blank function( )
Constantfunction(55)
Symbol function(symbol_name)
Literal function(‘With a literal string’)
Nagaraju Domala
Built-in functions
Nagaraju Domala
Arithmetic functions
ABS Returns the absolute value of the input number
Examples:
Nagaraju Domala
MAX
Returns the maximum numeric value from a list of
numeric values Syntax : MAX(number{,number}...)
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
Nagaraju Domala
SIGN
used to determine the sign of a number
Syntax : SIGN(number)
returns -1 if the number is negative
returns 0, if the number is zero
returns +1,if the number is positive
Examples :
SIGN('-22.811') returns -1
SIGN(0.0) returns 0
Nagaraju Domala
TRUNC
used to truncate a number to an integer portion and a
decimal fraction portion
Syntax : TRUNC(number{,n})
'n' is the number of decimal places to retain to the right
of the decimal point. If ‘n’ is omitted, no decimal places
are returned
Examples:
Nagaraju Domala
Comparison functions
COMPARE
DATATYPE
Nagaraju Domala
COMPARE
Used to compare two strings and return a zero if the strings are the same ,or a
non-zero number if they are not
Non-zero number is the position of the first mismatching character found
Syntax : COMPARE(string1,string2{,pad})
If the optional padding character is specified,then the shorter string is padded
and compared
Examples :
Nagaraju Domala
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)
Nagaraju Domala
Formatting functions
Nagaraju Domala
CENTER
Used to center one string within a certain length area and
pad on the left and right of the centered string with an
optional padding character
Syntax : CENTER(string, length{,pad})
The default padding character is spaces
Examples :
say center(‘msat’,10,’*’)
returns ***MSAT***
Nagaraju Domala
COPIES
Used to concatenate or append a string to itself a
certain number of times
Syntax : COPIES(string,n)
Examples:
COPIES('Hello',4) returns 'HelloHelloHelloHello'
Nagaraju Domala
FORMAT
Used to round off and format a number
Optional values can be passed which decides the number of
digits before and after the decimal point
Syntax : FORMAT(number{,{before}}{,{after}})
Examples:
FORMAT('78',3) returns rounded number ' 78'
FORMAT('-8.7',,2) returns rounded number '-8.70'
FORMAT('5.46',3,0) returns rounded number ' 5'
Nagaraju Domala
LEFT
Used to extract the leftmost characters of the
string
Syntax : LEFT(string,length{,pad})
Nagaraju Domala
LENGTH
used to return the length of the string passed to
the function
Syntax : LENGTH(string)
Examples :
LENGTH('LIFO') returns 4
LENGTH('Rubber baby buggy bumpers') returns 25
LENGTH('') returns 0
Nagaraju Domala
String manipulating functions
DELSTR Returns a string after deleting a specified number of
characters, starting at a specified point in the input string
Nagaraju Domala
INDEX
Used to find the position of one character string within another
character string
Syntax : INDEX(string,substring{,start})
'start' is an optional starting character position for the search
within ‘string’
Examples
INDEX('hello','ll') returns a 3
INDEX('say what','w ') returns a 0
INDEX('zyxwvu','vu',6) returns a 0
INDEX('zyxwvu','vu',2) returns a 5
Nagaraju Domala
POS
Returns the position, relative to 1, of one string within another.
Syntax : POS(substring,string{,startloc})
A zero is returned if substring is not found within ‘string’
Examples:
POS('M','ABCDEFGHIJKLMNOPQRSTUVWXYZ') returns 13
POS('Smith',‘Lenovo, Lynch, Pierce, Fenner, and Smith') returns 37
POS('hart','MVS is breaking my heart...',4) returns 0
Nagaraju Domala
REVERSE
This function reverses the order of all characters in a string
Syntax : REVERSE( string)
Example
say reverse(‘MSAT’)
returns ‘TASM’
Nagaraju Domala
STRIP
Used to remove the leading and/or trailing characters from a
character string
Syntax : STRIP(string{,{option}{,char}})
The default char for ‘char’ is blank
The ‘option’ can take either L or T or B and the default option is B
Examples :
STRIP(' February 11, 1989 ') returns 'February 11,1989'
STRIP('7642.7600',T,0) returns '7642.76'
STRIP('$$$$52.4',Leading,$) returns '52.4'
Nagaraju Domala
SUBSTR
Used to extract a portion of a string
Syntax : SUBSTR(string,n{,{length}{,pad}})
‘length’ is the length of extracted substring
if ‘length’ is omitted, the remainder of the string from char number ‘n’ is extracted
The extract string is padded on the right with ‘pad’ char, if there are not enough characters in the
extracted substring to reach ‘length’
SUBWORD is used to extract portion of a string starting from a word
Examples :
SUBSTR('Hi there',4) returns 'there'
SUBSTR('MVS',1,5) returns 'MVS '
SUBWORD("Where is this string",3,2) returns the string "this string"
Nagaraju Domala
Miscellaneous functions
ADDRES Returns the name of the environment to which
commands are currently being sent
DATE Returns the date in one of various optional
formats
TIME Returns the local time in the default 24-hour
clock format (hh:mm:ss) or in one of various optional
formats
Example :
Address tso /* commands are for TSO */
Address ispexec /* commands are for ISPF */
Nagaraju Domala
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 */
Nagaraju Domala
TIME
Returns the current time of day in a variety of different formats
and can also be used to perform elapsed time calculations
Syntax : TIME({option})
‘R’ - elapsed time clock to be set to zero
‘E’ - return elapsed time since previous TIME(‘R’)
‘H’ - No. of hours since midnight
‘L’ - hh:mm:ss:uuuuuu
‘S’ - No. of seconds since midnight
Examples :
Nagaraju Domala
USERID
Returns the current TSO user id
Format : USERID()
Example
say userid() /* returns the current user id */
Nagaraju Domala
WORD
Used to extract a specific word from within a string of words
Syntax : WORD(string,n)
The words in the string must be separated by blanks
‘n’ indicates that the nth word in the string is to be extracted
Examples :
WORD(’Arise Awake and Stop not',4) /* returns ’Stop' */
test = '1 2 3 4 5 6 7 8 9'
WORD(test,1) /* returns '1' */
WORD('Carolina moon, what are you doing over Gismo Beach?',10)
/* returns null string */
Nagaraju Domala
WORDS
Used to determine the number of words contained within a
string of words
Syntax : WORDS(string)
Examples :
WORDS(‘Arise, Awake and Stop not till the goal is reached’)
/* returns 10 */
WORDS('1234567890abcdefghikjlmnopqrstuvwxyz $@#!')
/* returns 2 */
Nagaraju Domala
External functions
In addition to the built-in functions, TSO/E provides
external functions that you can use to do some specific tasks.
LISTDSI
OUTTRAP
SYSDSN
Nagaraju Domala
LISTDSI
Returns in variables the dataset attributes of a specified
dataset
The function call is replaced by a function code that
indicates whether or not the call was successful. A non-zero
code indicates that the call was not successful
/*REXX*/
X=LISTDSI(“’MSAT.PDS.COBOL’”) /* x = function code */
IF X=0 THEN DO
SAY ‘SYSDSORG ‘ SYSDSORG
SAY ‘SYSLRECL ‘ SYSLRECL
END ELSE SAY ‘CALL UNSUCCESSFUL’
EXIT
Nagaraju Domala
LISTDSI
Note two sets of quotes in the call to LISTDSI
Nagaraju Domala
OUTTRAP
Traps TSO/E command output into a stem variable
The function call returns the name of the variable specified
Trapping is capturing the lines of data which otherwise
would have been displayed at the terminal
/*REXX*/
x=outtrap("a.") /* turns trap on. x=a. */
"listds ‘msat.rexx.exec' members"
x=outtrap("off") /* turns trap off. x=off */
say 'No of lines trapped ' a.0
EXIT
Nagaraju Domala
OUTTRAP
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
Nagaraju Domala
SYSDSN
Returns OK if the specified dataset exists; Otherwise returns
appropriate error messages
available = SYSDSN(“’MSAT.rexx.exec’”)
/* available could be set to "OK" */
Nagaraju Domala
Subroutines
Nagaraju Domala
Subroutines
Series of instructions that an exec invokes
Nagaraju Domala
Subroutines
Subroutines may be
Nagaraju Domala
Using subroutines
Passing variables
Passing arguments
Nagaraju Domala
Passing Variables
Nagaraju Domala
An example
number1 = 5
number2 = 10
CALL sub1
SAY answer
(Displays 15)
EXIT
sub1:
answer = number1 + number2
RETURN
Nagaraju Domala
Passing Arguments
Passed in main EXEC by
Received in subroutine by
Nagaraju Domala
An example
length = 10
width = 7
CALL sub4 length, width
SAY ‘The perimeter is ‘ RESULT ‘Meters’
EXIT
sub4:
ARG len, wid
perim = 2 * ( len + wid)
RETURN perim
Nagaraju Domala
Interrupt instructions
OR
These are
EXIT
SIGNAL
CALL/RETURN
Nagaraju Domala
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 */
Nagaraju Domala
SIGNAL label
Interrupts the normal flow of an exec
When SIGNAL is issued from within a loop, the loop automatically ends
Nagaraju Domala
SIGNAL label
SIGNAL
is useful for testing execs or to provide
an emergency course of action
Should
not be used as a convenient way to
move (jump) from one place in an exec to
another
Nagaraju Domala
SIGNAL
/*REXX*/
say ‘Before signal’ /* displayed */
signal bye
say ‘After signal’ /* never gets executed
exit
bye:
say ‘In signal’ /* displayed */
exit
Nagaraju Domala
CALL / RETURN
Nagaraju Domala
CALL
Used to invoke an internal or external subroutine and
built-in-functions
The called routine usually uses the ARG function to
extract the parameters passed by the call
Nagaraju Domala
RETURN
Used to pass control back to the caller of a
subroutine or function. An optional value can also be
passed
Syntax : RETURN {expression }
If invoked as a function ,the value in the return
instruction is substituted for the function call
If invoked as a subroutine , the value in the RETURN
instruction is stored in the REXX special variable
RESULT
If the RETURN instruction doesn’t have any
expression , then a null string is passed to the caller
Nagaraju Domala