Sie sind auf Seite 1von 134

REXX

CTS-PAC Version 1.6 1


Objectives

 Introduction to REXX

 Syntax and Functions

 Advanced Concepts

CTS-PAC Version 1.6 2


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

CTS-PAC Version 1.6 3


Features of REXX

 Ease of use

 Free format

 Convenient built-in functions

CTS-PAC Version 1.6 4


Features of REXX (Cont...)

 Debugging capabilities

 Interpreted language

 Extensive parsing capabilities

CTS-PAC Version 1.6 5


Components of REXX
 Instructions
 Built-in functions
 TSO/E external functions
 Data stack functions

CTS-PAC Version 1.6 6


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

CTS-PAC Version 1.6 7


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)

CTS-PAC Version 1.6 8


Built-in functions
 These functions are built into the language processor
 Provide convenient processing options

CTS-PAC Version 1.6 9


TSO/E external functions
 Interact with the system
 Do specific tasks for REXX

CTS-PAC Version 1.6 10


Data stack functions
 Store data for I/O
 Other types of processing

CTS-PAC Version 1.6 11


Syntax of REXX

CTS-PAC Version 1.6 12


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

CTS-PAC Version 1.6 13


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

CTS-PAC Version 1.6 14


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

CTS-PAC Version 1.6 15


Variables and expressions

CTS-PAC Version 1.6 16


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

CTS-PAC Version 1.6 17


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

CTS-PAC Version 1.6 18


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

CTS-PAC Version 1.6 19


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.‟

CTS-PAC Version 1.6 20


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 „‟

CTS-PAC Version 1.6 21


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.”

CTS-PAC Version 1.6 22


Parsing
 Separators - an example
 phrase = „Dun & Bradstreet‟
 PARSE VAR phrase part1 „&‟ part2
 part1 contains „Dun ‟
 part2 contains „ Bradstreet‟

CTS-PAC Version 1.6 23


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

CTS-PAC Version 1.6 24


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

CTS-PAC Version 1.6 25


Parsing
 Absolute column position - an example
 quote = „Dun & Bradstreet‟
 PARSE VAR quote part1 6 part2
 part1 contains „Dun &‟
 part2 contains „Bradstreet‟

CTS-PAC Version 1.6 26


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‟

CTS-PAC Version 1.6 27


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

CTS-PAC Version 1.6 28


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‟

CTS-PAC Version 1.6 29


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

CTS-PAC Version 1.6 30


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‟

CTS-PAC Version 1.6 31


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

CTS-PAC Version 1.6 32


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

CTS-PAC Version 1.6 33


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

CTS-PAC Version 1.6 34


Arithmetic Operators -
Priority
 Priority from maximum to minimum
 -+ Prefix operators
 ** Power (exponential)
 * / % // Multiplication and division
 +- Addition and subtraction

CTS-PAC Version 1.6 35


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

CTS-PAC Version 1.6 36


Comparison operators (Cont...)
 \== Not strictly equal
 \= Not equal
 >< Greater than or less than (same as not equal)
 \< Not less than
 \> Not greater than

CTS-PAC Version 1.6 37


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

CTS-PAC Version 1.6 38


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

CTS-PAC Version 1.6 39


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

CTS-PAC Version 1.6 40


Concatenation operators
 Combine two terms into one
 Terms can be strings, variables, expressions, or
constants
 Concatenation can be significant in formatting output

CTS-PAC Version 1.6 41


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%

CTS-PAC Version 1.6 42


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

CTS-PAC Version 1.6 43


Control of
program flow

CTS-PAC Version 1.6 44


Conditional instructions
 Instructions which set up at least one condition in the
form of an expression

 IF/THEN/ELSE, and

 SELECT/WHEN/OTHERWISE

CTS-PAC Version 1.6 45


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

CTS-PAC Version 1.6 46


IF construct (Cont...)
 IF expression THEN
DO
instruction
instruction
END
ELSE
DO
instruction
instruction
END

CTS-PAC Version 1.6 47


SELECT construct
 can direct the execution to one of many choices.
 SELECT
WHEN expression THEN instruction
WHEN expression THEN instruction
:
OTHERWISE
instruction(s)
END

CTS-PAC Version 1.6 48


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

CTS-PAC Version 1.6 49


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

CTS-PAC Version 1.6 50


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

CTS-PAC Version 1.6 51


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

CTS-PAC Version 1.6 52


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

CTS-PAC Version 1.6 53


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

CTS-PAC Version 1.6 54


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

CTS-PAC Version 1.6 55


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

CTS-PAC Version 1.6 56


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

CTS-PAC Version 1.6 57


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

CTS-PAC Version 1.6 58


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

CTS-PAC Version 1.6 59


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

CTS-PAC Version 1.6 60


Functions and Subroutines

CTS-PAC Version 1.6 61


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

CTS-PAC Version 1.6 62


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

CTS-PAC Version 1.6 63


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

CTS-PAC Version 1.6 64


Built-in functions

CTS-PAC Version 1.6 65


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

CTS-PAC Version 1.6 66


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
CTS-PAC Version 1.6 67
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)

CTS-PAC Version 1.6 68


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

CTS-PAC Version 1.6 69


Conversion functions
 D2X Decimal to Hexadecimal
 X2B Hexadecimal to binary
 X2C Hexadecimal to Character
 X2D Hexadecimal to Decimal

CTS-PAC Version 1.6 70


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

CTS-PAC Version 1.6 71


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

CTS-PAC Version 1.6 72


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

CTS-PAC Version 1.6 73


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
CTS-PAC Version 1.6 74
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
CTS-PAC Version 1.6 75
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

CTS-PAC Version 1.6 76


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

CTS-PAC Version 1.6 77


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

CTS-PAC Version 1.6 78


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

CTS-PAC Version 1.6 79


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

CTS-PAC Version 1.6 80


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

CTS-PAC Version 1.6 81


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

CTS-PAC Version 1.6 82


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
CTS-PAC Version 1.6 83
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
CTS-PAC Version 1.6 84
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
CTS-PAC Version 1.6 85
Date formats
 Syntax of the date function id DATE(option)
 A variety of options are available
 The full option, or it‟s first alphabet, can be passed as
argument
 A list of options follows

CTS-PAC Version 1.6 86


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

CTS-PAC Version 1.6 87


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)

CTS-PAC Version 1.6 88


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

CTS-PAC Version 1.6 89


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

CTS-PAC Version 1.6 90


Time formats
 Syntax of the Time function is TIME(option)
 A variety of options are available
 The full option, or it‟s first alphabet, can be passed as the
argument
 A list of options follows

CTS-PAC Version 1.6 91


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

CTS-PAC Version 1.6 92


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

CTS-PAC Version 1.6 93


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

CTS-PAC Version 1.6 94


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

CTS-PAC Version 1.6 95


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

CTS-PAC Version 1.6 96


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)

CTS-PAC Version 1.6 97


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

CTS-PAC Version 1.6 98


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

CTS-PAC Version 1.6 99


Subroutines

CTS-PAC Version 1.6 100


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

CTS-PAC Version 1.6 101


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

CTS-PAC Version 1.6 102


Using subroutines

 Sharing information can be done by

 Passing variables

 Passing arguments

CTS-PAC Version 1.6 103


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

CTS-PAC Version 1.6 104


An example
 number1 = 5  sub1:
 number2 = 10  answer = number1 +
 CALL sub1 number2
 SAY answer  RETURN
(Displays 15)
 EXIT

CTS-PAC Version 1.6 105


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

CTS-PAC Version 1.6 106


An example
 number1 = 10  sub2: PROCEDURE
 CALL sub2  number1 = 7
 SAY number1 number2  number2 = 5
(displays 10 NUMBER2)  RETURN
 EXIT

CTS-PAC Version 1.6 107


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

CTS-PAC Version 1.6 108


An example
 number1 = 10  sub3: PROCEDURE
 CALL sub3 EXPOSE number1
 SAY number1 number2  number1 = 7
(displays 7 NUMBER2)  number2 = 5
 EXIT  RETURN

CTS-PAC Version 1.6 109


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

CTS-PAC Version 1.6 110


An example
 length = 10  sub4:
 width = 7  ARG len, wid
 CALL sub4 length, width  perim = 2 * ( len + wid)
 SAY „The perimeter is „  RETURN perim
RESULT „Meters‟
 EXIT

CTS-PAC Version 1.6 111


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.

CTS-PAC Version 1.6 112


Using REXX

CTS-PAC Version 1.6 113


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

CTS-PAC Version 1.6 114


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

CTS-PAC Version 1.6 115


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

CTS-PAC Version 1.6 116


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

CTS-PAC Version 1.6 117


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

CTS-PAC Version 1.6 118


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

CTS-PAC Version 1.6 119


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

CTS-PAC Version 1.6 120


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

CTS-PAC Version 1.6 121


ISPF functions

CTS-PAC Version 1.6 122


Panels
 Display panels, accept data and pass on data for
processing
 Syntax is
 ADDRESS ISPEXEC
 “Display panel(XXXXXX)”

CTS-PAC Version 1.6 123


Tables
 All table services like TBCREATE, TBADD,
TBUPDATE, TBDELETE etc.
 Syntax is
 ADDRESS ISPEXEC
 “TBADD tbl-name ....”
 “TBDELETE tbl-name...” etc.

CTS-PAC Version 1.6 124


Skeletons
 ISPF Skeleton services like generating JCLs from
skeletons
 Syntax is
 ADDRESS ISPEXEC
 “ftopen”
 “ftincl skelname”
 “ftclose temp”
 ADDRESS TSO
 “submit ztempf”

CTS-PAC Version 1.6 125


LM Functions
 Dataset list
 Member list
 Copy members
 Delete members
 manipulate statistics of members

CTS-PAC Version 1.6 126


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

CTS-PAC Version 1.6 127


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

CTS-PAC Version 1.6 128


Input/Output processing
 Operations with datasets
 All datasets with a defined record format are allowed
(except RECFM=U)

CTS-PAC Version 1.6 129


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

CTS-PAC Version 1.6 130


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.

CTS-PAC Version 1.6 131


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

CTS-PAC Version 1.6 132


References
 TSO/E Version 2 REXX/MVS User‟s 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

CTS-PAC Version 1.6 133


Thank
You!

CTS-PAC Version 1.6 134

Das könnte Ihnen auch gefallen