Restructured Exented Executor: Nagaraju Domala

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 63

REXX

Restructured EXented eXecutor


NAGARAJU DOMALA
REXX – A Summary

 You’ll be incredibly productive when freed from the


shackles of syntax-oriented programming.
 You’ll make fewer mistakes and spend less time
debugging. 
 You can develop large, complex applications very
quickly. 
 Your applications will have fewer bugs and be highly
reliable.  
 Power developers are the biggest beneficiaries of
an “easy” language like REXX.

Nagaraju Domala
REXX – Types

 "Classic" Rexx. This is a procedural


programming language
 Object Rexx. This is a superset of classic Rexx,
fully extended for object-oriented 
programming.
 NetRexx. This is a "Java-compatible," Rexx-like
language. It coexists interchangeably with 
Java code and runs under the Java Virtual
Machine

Nagaraju Domala
If If then else
Do End

Do While
Select

(case)

Nagaraju Domala
Do Until
Do Forever

Leave

Nagaraju Domala
REXX – Books

Rexx Programmer's Reference The REXX Language:


By A Practical Approach to Programming
Howard Fosdick By
Michail Cowlishaw

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

Built-in & External Functions


Subroutines
 Internal & External Subroutines
 Passing/Receiving Data
External Commands
Lab Exercise

Nagaraju Domala
Functions and Subroutines

Nagaraju Domala
Functions
 Sequence of instructions that can
Receive data
Process that data, and
Return a value

 All functions return a value to the exec that issued the


function call

 Syntax is function(arguments)

 No space between the function name and the left parenthesis

Nagaraju Domala
Functions
 Built-in functions -- These functions are built into the
language processor.

 User-written functions -- These functions are written


by an individual user or supplied by an installation and
can be internal or external.

o An internal function is part of the current exec


that starts at a label.
o An external function is a self-contained
program or exec outside of the calling exec
Nagaraju Domala
Functions - parameters

 Up to 20 arguments separated by commas

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

 MAX Returns the largest number from the list

 MIN Returns the smallest number from the list


specified

 SIGN Returns a number that indicates the sign of


the input number

 TRUNC Returns the integer part of the input number,


and optionally a specified number of decimal places
Nagaraju Domala
ABS
 Returns the absolute value of a number
 The absolute value of a number is the value of
the number without the sign being considered

Examples:

ABS(’56.7') returns the number 56.7 numeric digits 2


ABS(' -0.125') returns the number 0.13

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:

TRUNC(4096.6904) /* returns 4096, dropping decimal fraction */


TRUNC(0.3,3) /* returns 0.300 */

Nagaraju Domala
Comparison functions

 COMPARE

Returns 0 if the two input strings are identical


Returns the position of the first character that does not
match

 DATATYPE

Returns a value indicating data type of the input string, such


as a number or character

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 :

COMPARE('123','123') returns a 0 (exact match)


COMPARE('FO?? ','FO','?') returns a 5 (1st mismatch after padding)
COMPARE('abc','ak') returns a 2 (first mismatching char)
COMPARE('ZZ ','ZZ','x') returns a 3 (1st mismatch found 3 chars in)
COMPARE('MA ','MA') returns a 0 (exact match with padding)

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

 CENTER/CENTRE : Returns a string of a specified length


with the input string centered in it, with pad
characters added as necessary to make up the
length
 COPIES : Returns the specified number of
concatenated copies of the input string

 FORMAT : Returns the input number, rounded and


formatted to the number of digits specified
 LEFT : Returns a string of the specified length,
truncated or padded on the right as needed
 LENGTH Returns length of string passed to the
function

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})

 If string is shorter than length, the string returned


is padded with ‘pad’ char in the function call if
available or with the default pad character blank.
Examples:
LEFT('Wallawalla',4) returns 'Wall'
LEFT('Republicans',20,'-') returns 'Republicans---------'
LEFT('Motley Crue ',8) returns 'Motley C'

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

 INDEX Returns the character position of the first character of a


specified string found in the input string

 POS Returns the character position of one string in another

 REVERSE Returns a character string, the characters of which are in


reverse order (swapped end for end)

 STRIP Returns a character string after removing leading or trailing


characters or both from the input string

 SUBSTR Returns a portion of the input string beginning at a specified


character position
Nagaraju Domala
DELSTR
 Used to delete or remove one string from a 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

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

 USERID Returns the TSO/E user ID, if the REXX exec is


running in the TSO/E address space

 WORD Returns a specific word from within a string of


words

 WORDS Returns the number of words contained within a


string of words Nagaraju Domala
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

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 :

TIME() returns 09:18:04


TIME('L') returns 11:00:32.672567
TIME('H') returns 12 /* at noon */
TIME('R') returns 0 /* The first call */
TIME('E') returns 18.278190 /* apprx18 seconds later*/

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

“ - to indicate the parm is literal to REXX


‘ - to indicate the dsname is fully qualified
 The function code should always be checked after the call
 The output of the above REXX could be
SYSDSORG PO - PO- Partitioned Dataset
SYSLRECL 80 - Record length
Totally there are 33 variables that are set as a result of the
call to LISTDSI external function

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

 Performs a specific task

 The subroutine is invoked by the CALL instruction

 When the subroutine ends, it returns control to the


instruction that directly follows the subroutine call

 The instruction that returns control is the RETURN instruction

Nagaraju Domala
Subroutines

 Subroutines may be

 Internal and designated by a label, or


 external and designated by the member name that
contains the subroutine

 Internal subroutines generally appear after the main part of


the exec. So, when there is an internal subroutine, it is
important to end the main part of the exec with the EXIT
instruction

Nagaraju Domala
Using subroutines

 Sharing information can be done by

 Passing variables

 Passing arguments

Nagaraju Domala
Passing Variables

 Main exec and subroutine share the same variables by name

 Value of the variable is the same irrespective of where it has


been set

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

 CALL subroutine_name argument1, argument2, argument3,


etc.
 Up to 20 arguments can be passed

 Received in subroutine by

 ARG arg1, arg2, arg3, etc.


 The names of the arguments on the CALL and the ARG
instructions need not be the same
 information is passed by position, and not by name

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

 Tell the language processor to leave the exec entirely

 OR

 Leave one part of the exec and go to another part either


permanently or temporarily

 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 */

 When prog2 is called in an exec as x=prog2(), then


x will have the value 100

Nagaraju Domala
SIGNAL label
 Interrupts the normal flow of an exec

 It is an equivalent command for the infamous GOTO command in


other languages

 Causes control to pass to a specified label

 Unlike CALL, SIGNAL does not return to a specific instruction to


resume execution

 When SIGNAL is issued from within a loop, the loop automatically ends

Nagaraju Domala
SIGNAL label

 When SIGNAL is issued from an internal routine,


the internal routine will NOT return to its caller

 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

 When calling an internal subroutine, CALL passes control to a


label specified after the CALL keyword

 When the subroutine ends with the RETURN instruction, the


instructions following CALL are executed

 When calling an external subroutine, CALL passes control to the


exec name that is specified after the CALL keyword

 When the external subroutine completes, the RETURN


instruction returns to where you left off in the calling exec

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

call factorial x /* go get factorial of 'x' */


say result /* write result out */
exit
factorial: procedure /* factorial subroutine */
arg n /* parse 'x' */
if n=0 then return 1 /* quit when done */
call factorial n-1 /* call myself with x minus 1 */
return result * n /* build up answer in 'result' */

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

You might also like