Sunteți pe pagina 1din 134

1

REXX Fundamentals
A Property of IBM-HR Access development Project
REXX
2
REXX Fundamentals
A Property of IBM-HR Access development Project
Objectives

Introduction to REXX

Syntax and Functions

Advanced Concepts
3
REXX Fundamentals
A Property of IBM-HR Access development Project
Introduction
What is REXX ?
Restructured EXtended eXecutor
Interpreted command language
Very useful for linking TSO, ISPF and other functions
Useful for developing custom-made utilities
4
REXX Fundamentals
A Property of IBM-HR Access development Project
Features of REXX

Ease of use

Free format

Convenient built-in functions
5
REXX Fundamentals
A Property of IBM-HR Access development Project
Features of REXX (Cont...)

Debugging capabilities

Interpreted language

Extensive parsing capabilities
6
REXX Fundamentals
A Property of IBM-HR Access development Project
Components of REXX
Instructions
Built-in functions
TSO/E external functions
Data stack functions
7
REXX Fundamentals
A Property of IBM-HR Access development Project
Instruction
Keyword
Tells the language processor to do something
Assignment
Gives a value to a variable or changes the current value of a
variable
Label
A symbolic name followed by a colon
Identifies a portion of the exec
Commonly used in subroutines and functions, and with the
SIGNAL instruction
8
REXX Fundamentals
A Property of IBM-HR Access development Project
Instruction (Cont...)
Null
Comment or a blank line
Ignored by the language processor
Makes an exec easier to read
Command (both REXX commands and host commands)
9
REXX Fundamentals
A Property of IBM-HR Access development Project
Built-in functions
These functions are built into the language processor
Provide convenient processing options
10
REXX Fundamentals
A Property of IBM-HR Access development Project
TSO/E external functions
Interact with the system
Do specific tasks for REXX
11
REXX Fundamentals
A Property of IBM-HR Access development Project
Data stack functions
Store data for I/O
Other types of processing
12
REXX Fundamentals
A Property of IBM-HR Access development Project
Syntax of REXX
13
REXX Fundamentals
A Property of IBM-HR Access development Project
Character Type of REXX
A REXX instruction can be in lower case, upper case, or
mixed case
Alphabetic characters are changed to uppercase, unless
enclosed in single or double quotation marks
The two types of quotation marks cannot be mixed
If any word in the statement is a variable, REXX
substitutes the value
14
REXX Fundamentals
A Property of IBM-HR Access development Project
Format
REXX uses a free format
A line usually contains one instruction except when it
ends with a comma (,) or contains a semi-colon (;).
Comma is the continuation character
Indicates that the instruction continues to the next line
Semi-colon indicates the end of the instruction
Used to separate multiple instructions on one line
15
REXX Fundamentals
A Property of IBM-HR Access development Project
Environment / Address
ADDRESS TSO for native TSO commands
ADDRESS ISPEXEC for ISPF services
ADDRESS ISREDIT for ISPF edit macros
These are required to invoke the environment for
function calls
16
REXX Fundamentals
A Property of IBM-HR Access development Project
Variables and expressions
17
REXX Fundamentals
A Property of IBM-HR Access development Project
Variables
Character or group of characters that represents a value
e.g. count = 1000
Variable names can consist of:
A....Z / a - Z alphabetic
0....9 numbers
@ # $ ? ! . _ special characters
18
REXX Fundamentals
A Property of IBM-HR Access development Project
Variables (Cont...)
Restrictions on the variable name are:
The first character cannot be 0 through 9 or a period (.)
The variable name cannot exceed 250 bytes
The variable name should not be RC, SIGL, or RESULT,
which are REXX special variables
19
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Separates data by comparing the data to a template (or
pattern of variable names)
Preserves the case of the input data
PARSE UPPER converts data to uppercase
Separators in a template can be
blank,
string,
variable, or
number that represents column position
20
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Blank - an example
Each variable name gets one word of data in sequence
except for the last, which gets the remainder of the data
PARSE VALUE Value with Blanks. WITH pattern
type
pattern contains Value
type contains with Blanks.
21
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Blank - another example
PARSE VALUE Value with Extra Variables. WITH
data1 data2 data3 data4 data5
data1 contains Value
data2 contains with
data3 contains Extra
data4 contains Variables.
data5 contains
22
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Substitution - an example
PARSE VALUE Value with Periods in it. WITH pattern .
type .
pattern contains Value
type contains Periods
the periods replace the words with and in it.
23
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Separators - an example
phrase = Dun & Bradstreet
PARSE VAR phrase part1 & part2
part1 contains Dun
part2 contains Bradstreet
24
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Number: Numbers in a template to indicate the column
at which data must be separated
Unsigned integer indicates an absolute column position and
Signed integer indicates a relative column position
25
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Absolute column position
An unsigned integer or an integer prefixed with an equal
sign (=) in a template
The first segment starts at column 1 and goes up to, but
does not include, the information in the column number
specified
The subsequent segments start at the column numbers
specified
26
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Absolute column position - an example
quote = Dun & Bradstreet
PARSE VAR quote part1 6 part2
part1 contains Dun &
part2 contains Bradstreet
27
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Absolute column position - another example
quote = Dun & Bradstreet
PARSE VAR quote part1 5 part2 7 part3 1 part4
part1 contains Dun
part2 contains &
part3 contains Bradstreet
part4 contains Dun & Bradstreet
28
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Relative column position
A signed integer in a template separates the data according
to relative column position
The starting position is relative to the starting position of the
preceding part.
Can be either positive (+) or negative (-)
29
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Relative column position - an example
quote = Dun & Bradstreet
PARSE VAR quote part1 +5 part2 +5 part3
part1 contains Dun &
part2 contains Brad
part3 contains street
30
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Variables
Define and use variables to provide further flexibility of a
PARSE VAR instruction
Define the variable prior to the parse instruction
Enclose the variable in parenthesis - this variable must be an
unsigned integer
Use a sign outside the parenthesis to indicate how REXX is
to interpret the unsigned integer
REXX substitutes the numeric value for the variable
31
REXX Fundamentals
A Property of IBM-HR Access development Project
Parsing
Variables - an example
quote = Dun & Bradstreet
movex = 4
PARSE VAR quote part5 +6 part6 +4 part7
-(movex) part8
part5 contains Dun &
part6 contains Brad
part7 contains street
part8 contains Bradstreet
32
REXX Fundamentals
A Property of IBM-HR Access development Project
Expressions
Something that needs to be calculated/evaluated
Consists of numbers, variables, or strings, and one or
more operators
Four types of operators
Arithmetic
Comparison
Logical and
Concatenation
33
REXX Fundamentals
A Property of IBM-HR Access development Project
Arithmetic Operators
Work on valid numeric constants or on variables that
represent valid numeric constants
+ Add
- Subtract
-number Negate the number
+number Add the number to 0
34
REXX Fundamentals
A Property of IBM-HR Access development Project
Arithmetic Operators (Cont...)
* Multiply
** Raise a number to a whole number power
/ Divide
% Divide and return a whole number without a
remainder (quotient only)
// Divide and return the remainder only
35
REXX Fundamentals
A Property of IBM-HR Access development Project
Arithmetic Operators -
Priority
Priority from maximum to minimum
- + Prefix operators
** Power (exponential)
* / % // Multiplication and division
+ - Addition and subtraction
36
REXX Fundamentals
A Property of IBM-HR Access development Project
Comparison operators
Do not return a number value
Return either a true or false response in terms of 1 or 0
respectively
== Strictly Equal
= Equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
37
REXX Fundamentals
A Property of IBM-HR Access development Project
Comparison operators (Cont...)
\== Not strictly equal
\= Not equal
>< Greater than or less than (same as not equal)
\< Not less than
\> Not greater than
38
REXX Fundamentals
A Property of IBM-HR Access development Project
Strictly Equal and Equal
Operators
When two expressions are strictly equal, everything
including the blanks and case (when the expressions are
characters) is exactly the same
When two expressions are equal, they are resolved to be
the same
39
REXX Fundamentals
A Property of IBM-HR Access development Project
Logical Operators
Return a true (1) or false (0) value when processed
Combine two comparisons and return the true (1) or
false (0) value depending on the results of the
comparisons
Used in complex conditional instructions
Can act as checkpoints to screen unwanted conditions
40
REXX Fundamentals
A Property of IBM-HR Access development Project
Logical Operators (Cont...)
The logical operators are
& AND
Returns 1 if both comparisons are true
| Inclusive OR
Returns 1 if at least one comparison is true
&& Exclusive OR
Returns 1 if only one comparison (but not both) is true
Prefix \ Logical NOT
Returns the opposite response
41
REXX Fundamentals
A Property of IBM-HR Access development Project
Concatenation operators
Combine two terms into one
Terms can be strings, variables, expressions, or
constants
Concatenation can be significant in formatting output
42
REXX Fundamentals
A Property of IBM-HR Access development Project
Concatenation operators
(Cont...)
blank concatenate terms, one blank in between
e.g. TRUE BLUE result is TRUE BLUE
|| concatenate terms, no blanks in between
e.g. a||.b result is a.b
abuttal concatenate terms, no blanks in between
e.g. per_cent% if per_cent = 50, result is 50%
43
REXX Fundamentals
A Property of IBM-HR Access development Project
Overall Operator Priority
\ - + Prefix operators
** Power (exponential)
* / % // Multiply and divide
+ - Add and subtract
blank || abuttal Concatenation operators
== = >< Comparison operators
& Logical AND
| && inclusive OR, exclusive OR
44
REXX Fundamentals
A Property of IBM-HR Access development Project
Control of
program flow
45
REXX Fundamentals
A Property of IBM-HR Access development Project
Conditional instructions
Instructions which set up at least one condition in the
form of an expression

IF/THEN/ELSE, and

SELECT/WHEN/OTHERWISE
46
REXX Fundamentals
A Property of IBM-HR Access development Project
IF construct
Can direct the execution of an exec to one of two
choices
IF expression
THEN instruction
ELSE instruction
for more than one instruction for a condition, begin the
set of instructions with a DO and end them with an END
47
REXX Fundamentals
A Property of IBM-HR Access development Project
IF construct (Cont...)
IF expression THEN
DO
instruction
instruction
END
ELSE
DO
instruction
instruction
END
48
REXX Fundamentals
A Property of IBM-HR Access development Project
SELECT construct
can direct the execution to one of many choices.
SELECT
WHEN expression THEN instruction
WHEN expression THEN instruction
:
OTHERWISE
instruction(s)
END
49
REXX Fundamentals
A Property of IBM-HR Access development Project
SELECT construct
for more than one instruction for a possible path, begin
the set of instructions with a DO and end them with an
END

However, if more than one instruction follows the
OTHERWISE keyword, DO and END are not necessary
50
REXX Fundamentals
A Property of IBM-HR Access development Project
Looping instructions
Tell the language processor to repeat a set of instructions
A loop can repeat a specified number of times or
Can use a condition to control repeating
Two types of loops
Repetitive repeat instructions a certain number of times
Conditional use a condition to control repeating
51
REXX Fundamentals
A Property of IBM-HR Access development Project
Repetitive loops
Repeat a set of instructions a specified number of times
e.g. DO i = 1 to 5
SAY Hello !
END
The step can also be controlled
e.g. DO i = 1 to 10 STEP 2
SAY Hello !
END
52
REXX Fundamentals
A Property of IBM-HR Access development Project
Repetitive loops
DO FOREVER/END - infinite loops
EXIT when a condition is reached
LEAVE instruction - leaves the loop
e.g. DO FOREVER
IF X = 0 THEN LEAVE
53
REXX Fundamentals
A Property of IBM-HR Access development Project
Conditional loops
DO WHILE
DO WHILE expression
instruction(s)
END
Test the expression before the loop executes the first time
and repeat only when the expression is true
54
REXX Fundamentals
A Property of IBM-HR Access development Project
Conditional loops
DO UNTIL
DO UNTIL expression
instruction(s)
END
Test the expression after the loop executes at least once and
repeat only when the expression is false
55
REXX Fundamentals
A Property of IBM-HR Access development Project
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
56
REXX Fundamentals
A Property of IBM-HR Access development Project
EXIT
Causes an exec to unconditionally end
Return to where the exec was invoked
Can also return a value to the caller of the exec
57
REXX Fundamentals
A Property of IBM-HR Access development Project
SIGNAL label
Interrupts the normal flow of an exec
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
58
REXX Fundamentals
A Property of IBM-HR Access development Project
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
59
REXX Fundamentals
A Property of IBM-HR Access development Project
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
60
REXX Fundamentals
A Property of IBM-HR Access development Project
CALL / RETURN
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
61
REXX Fundamentals
A Property of IBM-HR Access development Project
Functions and Subroutines
62
REXX Fundamentals
A Property of IBM-HR Access development Project
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
63
REXX Fundamentals
A Property of IBM-HR Access development Project
Functions - parameters
Up to 20 arguments separated by commas
Blank function( )
Constant function(55)
Symbol function(symbol_name)
Literal function(With a literal string)
function(function(arguments))
Another function
function(With a literal string, 55, option)
Combination of argument types
64
REXX Fundamentals
A Property of IBM-HR Access development Project
Functions - Types
Built-in functions built into the language processor
User-written functions --
Written by an individual user or supplied by an installation
Internal function is part of the current exec that starts at a
label
External function is a self-contained program or exec
outside of the calling exec
65
REXX Fundamentals
A Property of IBM-HR Access development Project
Built-in functions
66
REXX Fundamentals
A Property of IBM-HR Access development Project
Arithmetic functions
ABS Returns the absolute value of the input
number
DIGITS Returns the current setting of
NUMERIC DIGITS
FORM Returns the current setting of
NUMERIC FORM
FUZZ Returns the current setting of
NUMERIC FUZZ
MAX Returns the largest number from the list
67
REXX Fundamentals
A Property of IBM-HR Access development Project
Arithmetic functions
MIN Returns the smallest number from
the list specified

RANDOM Returns a quasi-random, non-
negative whole number in the range 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
68
REXX Fundamentals
A Property of IBM-HR Access development Project
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

SYMBOL Returns this state of the symbol
(variable, literal, or bad)
69
REXX Fundamentals
A Property of IBM-HR Access development Project
Conversion functions
Convert one type of data representation to another type
of data representation
B2X Binary to hexadecimal
C2D Character to Decimal
C2X Character to Hexadecimal
D2C Decimal to Character
70
REXX Fundamentals
A Property of IBM-HR Access development Project
Conversion functions
D2X Decimal to Hexadecimal
X2B Hexadecimal to binary
X2C Hexadecimal to Character
X2D Hexadecimal to Decimal
71
REXX Fundamentals
A Property of IBM-HR Access development Project
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
72
REXX Fundamentals
A Property of IBM-HR Access development Project
Formatting functions
JUSTIFY Returns a specified string
formatted by adding pad characters between words to
justify to both margins

LEFT Returns a string of the specified
length, truncated or padded on the right as needed
73
REXX Fundamentals
A Property of IBM-HR Access development Project
Formatting functions
RIGHT Returns a string of the specified
length, truncated or padded on the left as needed

SPACE Returns the words in the input
string with a specified number of pad characters
between each word
74
REXX Fundamentals
A Property of IBM-HR Access development Project
String manipulating
functions
ABBREV Returns a string indicating if one
string is equal to the specified number of leading
characters of another string

DELSTR Returns a string after deleting a
specified number of characters, starting at a specified
point in the input string

DELWORD Returns a string after deleting a
specified number of words, starting at a specified word
in the input string
75
REXX Fundamentals
A Property of IBM-HR Access development Project
String manipulating
functions
FIND Returns the word number of the
first word of a specified phrase found within the input
string

INDEX Returns the character position of
the first character of a specified string found in the input
string

INSERT Returns a character string after
inserting one input string into another string after a
specified character position
76
REXX Fundamentals
A Property of IBM-HR Access development Project
String manipulating
functions
LASTPOS Returns the starting character
position of the last occurrence of one string in another

LENGTH Returns the length of the input
string

OVERLAY Returns a string that is the target
string overlaid by a second input string
77
REXX Fundamentals
A Property of IBM-HR Access development Project
String manipulating
functions
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
78
REXX Fundamentals
A Property of IBM-HR Access development Project
String manipulating
functions
SUBSTR Returns a portion of the input
string beginning at a specified character position

SUBWORD Returns a portion of the input
string starting at a specified word number

TRANSLATE Returns a character string with
each character of the input string translated to another
character or unchanged
79
REXX Fundamentals
A Property of IBM-HR Access development Project
String manipulating
functions
VERIFY Returns a number indicating
whether an input string is composed only of characters
from another input string or returns the character
position of the first unmatched character

WORD Returns a word from an input
string as indicated by a specified number

WORDINDEX Returns the character position in
an input string of the first character in the specified word
80
REXX Fundamentals
A Property of IBM-HR Access development Project
String manipulating
functions
WORDLENGTH Returns the length of a specified
word in the input string

WORDPOS Returns the word number of the
first word of a specified phrase in the input string

WORDS Returns the number of words in
the input string
81
REXX Fundamentals
A Property of IBM-HR Access development Project
Miscellaneous functions
ADDRES Returns the name of the
environment to which commands are currently being
sent

ARG Returns an argument string or
information about the argument strings to a program or
internal routine

BITAND Returns a string composed of the
two input strings logically ANDed together, bit by bit
82
REXX Fundamentals
A Property of IBM-HR Access development Project
Miscellaneous functions
BITOR Returns a string composed of the
two input strings logically ORed together, bit by bit

BITXOR Returns a string composed of the
two input strings eXclusive ORed together, bit by bit

CONDITION Returns the condition
information, such as name and status, associated with
the current trapped condition
83
REXX Fundamentals
A Property of IBM-HR Access development Project
Miscellaneous functions
DATE Returns the date in one of various
optional formats

ERRORTEXT Returns the error message
associated with the specified error number

EXTERNALS Returns the number of elements
in the terminal input buffer. In TSO/E, always a 0

LINESIZE Returns the current terminal line
width minus 1
84
REXX Fundamentals
A Property of IBM-HR Access development Project
Miscellaneous functions
QUEUED Returns the number of lines
remaining in the external data queue at the time when
the function is invoked

SOURCELINE Returns either the line number of
the last line in the source file or the source line specified
by a number

TIME Returns the local time in the
default 24-hour clock format (hh:mm:ss) or in one of
various optional formats
85
REXX Fundamentals
A Property of IBM-HR Access development Project
Miscellaneous functions
TRACE Returns the trace actions currently in
effect

USERID Returns the TSO/E user ID, if the
REXX exec is running in the TSO/E address space

VALUE Returns the value of a specified symbol
and optionally assigns it a new value

XRANGE Returns a string of all 1-byte codes (in
ascending order) between and including specified
starting and ending values
86
REXX Fundamentals
A Property of IBM-HR Access development Project
Date formats
Syntax of the date function id DATE(option)
A variety of options are available
The full option, or its first alphabet, can be passed as
argument
A list of options follows
87
REXX Fundamentals
A Property of IBM-HR Access development Project
Date formats
Base(or Basedate) Returns the number of complete
days (that is, not including the current day) since and
including the date, January 1, 0001, in the format:
dddddd (no leading zeros or blanks)
The expression DATE(B)//7 returns a number in the range
0-6, where 0 is Monday and 6 is Sunday
Thus, this function can be used to determine the day of the
week independent of the language
88
REXX Fundamentals
A Property of IBM-HR Access development Project
Date formats
Century Returns the number of days,
including the current day, since and including January 1
of the last year that is a multiple of 100 in the format:
ddddd (no leading zeros)
Example: A call to DATE(C) is made on March 13,
1992, so the number of days from January 1, 1900, to
March 13, 1992, (33675) is returned

Days Returns the number of days, including
the current day, so far in this year in the format: ddd (no
leading zeros or blanks)
89
REXX Fundamentals
A Property of IBM-HR Access development Project
Date formats
European Returns date in dd/mm/yy format

Julian Returns date in yyddd format

Month Returns full English name of the
current month, for example, August

Normal Returns date in the format:
dd mon yyyy. This is the default
90
REXX Fundamentals
A Property of IBM-HR Access development Project
Date formats
Ordered Returns date in the format:
yy/mm/dd (suitable for sorting)

Standard / Sorted Returns date in the format:
yyyymmdd (suitable for sorting)

USA Returns date in mm/dd/yy format

Weekday Returns the English name for the day of
the week, in mixed case, for example, Tuesday
91
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Syntax of the Time function is TIME(option)
A variety of options are available
The full option, or its first alphabet, can be passed as the
argument
A list of options follows
92
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Civil
Returns the time in Civil format: hh:mmxx
The hours take the values 1 through 12
The minutes take the values 00 through 59
The minutes are followed immediately by the letters am or
pm
The hour has no leading zero
The minute field shows the current minute (rather than the
nearest minute) for consistency with other TIME results
93
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Elapsed
Returns sssssssss.uuuuuu, the number of
seconds.microseconds since the elapsed-time clock was
started or reset
No leading zeros or blanks
Setting of NUMERIC DIGITS does not affect the number
The fractional part always has six digits
94
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Hours
Returns up to two characters
Gives the number of hours since midnight
Format is hh
No leading zeros or blanks, except for a result of 0
95
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Long
Returns time in the format: hh:mm:ss.uuuuuu (uuuuuu is in
microseconds)
The first eight characters of the result follow the same rules
as for the Normal form
The fractional part is always six digits
96
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Minutes
Returns up to four characters
Gives the number of minutes since midnight
Format is mmmm
No leading zeros or blanks, except for a result of 0
97
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Normal
This is the default
Returns the time in the format hh:mm:ss
Hours take the values 00 through 23
Minutes and seconds take 00 through 59
All these are always two digits
Any fractions of seconds are ignored (times are never
rounded up)
98
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Reset
Returns sssssssss.uuuuuu, the number of
seconds.microseconds since the elapsed-time clock was
started or reset
Also resets the elapsed-time clock to zero
The number has no leading zeros or blanks
Setting of NUMERIC DIGITS does not affect the number
The fractional part always has six digits
99
REXX Fundamentals
A Property of IBM-HR Access development Project
Time formats
Seconds
Returns up to five characters
Gives the number of seconds since midnight
Format is sssss
No leading zeros or blanks, except for a result of 0
100
REXX Fundamentals
A Property of IBM-HR Access development Project
Subroutines
101
REXX Fundamentals
A Property of IBM-HR Access development Project
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
102
REXX Fundamentals
A Property of IBM-HR Access development Project
Subroutines
Subroutines may be
Internal and designated by a label, or
external and designated by the member name that contains
the subroutine

IMPORTANT NOTE
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
103
REXX Fundamentals
A Property of IBM-HR Access development Project
Using subroutines

Sharing information can be done by

Passing variables

Passing arguments
104
REXX Fundamentals
A Property of IBM-HR Access development Project
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
105
REXX Fundamentals
A Property of IBM-HR Access development Project
An example
number1 = 5
number2 = 10
CALL sub1
SAY answer
(Displays 15)
EXIT
sub1:
answer = number1 +
number2
RETURN
106
REXX Fundamentals
A Property of IBM-HR Access development Project
Shielding Variables
Done by using PROCEDURE instruction immediately
after the subroutine label
All variables used in the subroutine become local to the
subroutine
Shielded from the main part of the exec
107
REXX Fundamentals
A Property of IBM-HR Access development Project
An example
number1 = 10
CALL sub2
SAY number1 number2
(displays 10 NUMBER2)
EXIT
sub2: PROCEDURE
number1 = 7
number2 = 5
RETURN
108
REXX Fundamentals
A Property of IBM-HR Access development Project
Exposing Variables
To protect specific variables
use the EXPOSE option with the PROCEDURE instruction
followed by the variables that are to remain exposed to the
subroutine
109
REXX Fundamentals
A Property of IBM-HR Access development Project
An example
number1 = 10
CALL sub3
SAY number1 number2
(displays 7 NUMBER2)
EXIT
sub3: PROCEDURE
EXPOSE number1
number1 = 7
number2 = 5
RETURN
110
REXX Fundamentals
A Property of IBM-HR Access development Project
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
111
REXX Fundamentals
A Property of IBM-HR Access development Project
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
112
REXX Fundamentals
A Property of IBM-HR Access development Project
Compound variables
Compound variable is a single-dimensional array,
denoted by <variable name>.
The variable name itself can be more than one level
The rules that apply to a variable name also apply to a
compound variable
Very useful in array manipulation, input/output etc.
113
REXX Fundamentals
A Property of IBM-HR Access development Project
Using REXX
114
REXX Fundamentals
A Property of IBM-HR Access development Project
Conventions
Datasets are named as
<high level qualifier>.REXX.EXEC
The last level .EXEC is optional
Each member must have the first line as /* REXX */
This makes the command processor (TSO) invoke the
REXX interpreter
115
REXX Fundamentals
A Property of IBM-HR Access development Project
Concatenations
Datasets containing REXX EXECs must be
concatenated to SYSEXEC or SYSPROC

Concatenation to SYSEXEC makes execution faster, as
it is above SYSPROC in the search order
116
REXX Fundamentals
A Property of IBM-HR Access development Project
MODEL command
Useful for giving an on-line model for ISPF function
calls
Edit a member in a REXX dataset, and issue the MODEL
command
A list of all ISPF services is displayed
Choose the desired service
A copy of the syntax is embedded
Change it as required
117
REXX Fundamentals
A Property of IBM-HR Access development Project
Execution
How and where can REXX execs be executed
From TSO READY prompt (if no ISPF services are used)
From inside ISPF
From inside another exec
118
REXX Fundamentals
A Property of IBM-HR Access development Project
Debugging REXX Execs
TRACE C
any command that follows is traced before it is executed
then it is executed, and the return code from the command is
displayed

TRACE E
any host command that results in a non-zero return code is
traced after it executes
the return code from the command is displayed
119
REXX Fundamentals
A Property of IBM-HR Access development Project
Debugging REXX Execs
Trace ?I (Intermediates)
Stops execution after each instruction
Trace ?R (Results)
Displays the result of execution of each step, but runs
continuously
These help to trace the progress of the EXEC
EXECUTIL TS (Trace start) and TE (trace end) can also
be used to start and end the tracing of a REXX
120
REXX Fundamentals
A Property of IBM-HR Access development Project
Debugging REXX Execs
RC Return code of the last instruction executed
SIGL Set to the line number from where the transfer
occurred
These variables can also be used to trace the exec
121
REXX Fundamentals
A Property of IBM-HR Access development Project
TSO/E External functions
All TSO commands can be issued
Enclose them within quotation marks
e.g. "LISTDS my.dataset STATUS"
Variables can also be passed
e.g. "LISTDS" name "STATUS"
here, name is a variable used in the REXX
122
REXX Fundamentals
A Property of IBM-HR Access development Project
ISPF functions
123
REXX Fundamentals
A Property of IBM-HR Access development Project
Panels
Display panels, accept data and pass on data for
processing
Syntax is
ADDRESS ISPEXEC
Display panel(XXXXXX)
124
REXX Fundamentals
A Property of IBM-HR Access development Project
Tables
All table services like TBCREATE, TBADD,
TBUPDATE, TBDELETE etc.
Syntax is
ADDRESS ISPEXEC
TBADD tbl-name ....
TBDELETE tbl-name... etc.
125
REXX Fundamentals
A Property of IBM-HR Access development Project
Skeletons
ISPF Skeleton services like generating JCLs from
skeletons
Syntax is
ADDRESS ISPEXEC
ftopen
ftincl skelname
ftclose temp
ADDRESS TSO
submit ztempf
126
REXX Fundamentals
A Property of IBM-HR Access development Project
LM Functions
Dataset list
Member list
Copy members
Delete members
manipulate statistics of members
127
REXX Fundamentals
A Property of IBM-HR Access development Project
Data stack
Place for storing variables temporarily
Manipulated using PUSH and QUEUE
No limits on the length and format of the data items
Theoretically no limit on the number of items to be
stacked - limited only by practical considerations
128
REXX Fundamentals
A Property of IBM-HR Access development Project
Data stack
PUSH works LIFO (Last-In-First-Out)
puts items to the top of the stack

QUEUE works FIFO (First-In-First-Out)
puts items on the bottom of the stack

In both cases, elements are removed by PULL
QUEUED() gives the number of items put on a stack in
a single EXEC
129
REXX Fundamentals
A Property of IBM-HR Access development Project
Input/Output processing
Operations with datasets
All datasets with a defined record format are allowed
(except RECFM=U)
130
REXX Fundamentals
A Property of IBM-HR Access development Project
DISKR
EXECIO DISKR for reading the dataset/member
EXECIO 0 DISKR mydd (OPEN - just opens the dataset
EXECIO 25 ...- reads 25 lines
EXECIO * ... - reads all the lines
EXECIO * DISKR myindd 100 (FINIS - reads all
lines from line 100
In all the above cases, the lines are read on to the STACK
EXECIO * DISKR myindd (STEM newvar. - reads
into a stem of variables called newvar
131
REXX Fundamentals
A Property of IBM-HR Access development Project
DISKW
Options for DISKR also hold for DISKW
Writes to dataset/member
Can be written from stem/stack
Numerous other options available for positioning,
skipping, LIFO/FIFO etc.
132
REXX Fundamentals
A Property of IBM-HR Access development Project
An example
Use REXX to
List all datasets following a particular pattern
For each dataset, list all the members starting with a
particular pattern

This can be done by
Using LMDLIST to get the dataset list
Then using LMMLIST on each dataset to get the member
list
Match patterns, and display appropriate members
133
REXX Fundamentals
A Property of IBM-HR Access development Project
References
TSO/E Version 2 REXX/MVS Users Guide
TSO/E Version 2 REXX/MVS Reference
Both these books are available on our file server
(IBM Book Manager for Windows)
Programming in REXX by Charles Daney, J.Ranade
IBM series
134
REXX Fundamentals
A Property of IBM-HR Access development Project
Thank
You!

S-ar putea să vă placă și