rexx.ppt
TRANSCRIPT
CTS-PAC Version 1.6 1
REXXREXXREXXREXX
CTS-PAC Version 1.6 2
ObjectivesObjectivesObjectivesObjectives
Introduction to REXX
Syntax and Functions
Advanced Concepts
CTS-PAC Version 1.6 3
IntroductionIntroductionIntroductionIntroduction
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 4
Features of REXXFeatures of REXXFeatures of REXXFeatures of REXX
Ease of use
Free format
Convenient built-in functions
CTS-PAC Version 1.6 5
Features of REXX Features of REXX (Cont...)(Cont...)Features of REXX Features of REXX (Cont...)(Cont...)
Debugging capabilities
Interpreted language
Extensive parsing capabilities
CTS-PAC Version 1.6 6
Components of REXXComponents of REXXComponents of REXXComponents of REXX
Instructions Built-in functions TSO/E external functions Data stack functions
CTS-PAC Version 1.6 7
InstructionInstructionInstructionInstruction
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 8
Instruction Instruction (Cont...)(Cont...)Instruction Instruction (Cont...)(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 9
Built-in functionsBuilt-in functionsBuilt-in functionsBuilt-in functions
These functions are built into the language processor Provide convenient processing options
CTS-PAC Version 1.6 10
TSO/E external functionsTSO/E external functionsTSO/E external functionsTSO/E external functions
Interact with the system Do specific tasks for REXX
CTS-PAC Version 1.6 11
Data stack functionsData stack functionsData stack functionsData stack functions
Store data for I/O Other types of processing
CTS-PAC Version 1.6 12
Syntax of REXXSyntax of REXXSyntax of REXXSyntax of REXX
CTS-PAC Version 1.6 13
Character Type of REXXCharacter Type of REXXCharacter Type of REXXCharacter 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 14
FormatFormatFormatFormat
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 15
Environment / AddressEnvironment / AddressEnvironment / AddressEnvironment / 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 16
Variables and expressionsVariables and expressionsVariables and expressionsVariables and expressions
CTS-PAC Version 1.6 17
VariablesVariablesVariablesVariables
Character or group of characters that represents a valuee.g. count = 1000
Variable names can consist of: A....Z / a - Z alphabetic 0....9 numbers @ # $ ¢ ? ! . _ special characters
CTS-PAC Version 1.6 18
Variables Variables (Cont...)(Cont...)Variables Variables (Cont...)(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 19
ParsingParsingParsingParsing
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 20
ParsingParsingParsingParsing
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 21
ParsingParsingParsingParsing
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 22
ParsingParsingParsingParsing
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 23
ParsingParsingParsingParsing
Separators - an example phrase = ‘Dun & Bradstreet’ PARSE VAR phrase part1 ‘&’ part2 part1 contains ‘Dun ’ part2 contains ‘ Bradstreet’
CTS-PAC Version 1.6 24
ParsingParsingParsingParsing
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 25
ParsingParsingParsingParsing
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 26
ParsingParsingParsingParsing
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 27
ParsingParsingParsingParsing
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 28
ParsingParsingParsingParsing
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 29
ParsingParsingParsingParsing
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 30
ParsingParsingParsingParsing
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 31
ParsingParsingParsingParsing
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 32
ExpressionsExpressionsExpressionsExpressions
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 33
Arithmetic OperatorsArithmetic OperatorsArithmetic OperatorsArithmetic 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 34
Arithmetic Operators Arithmetic Operators (Cont...)(Cont...)Arithmetic Operators Arithmetic Operators (Cont...)(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 35
Arithmetic Operators - Arithmetic Operators - PriorityPriority
Arithmetic Operators - Arithmetic Operators - PriorityPriority
Priority from maximum to minimum - + Prefix operators ** Power (exponential) * / % // Multiplication and division + - Addition and subtraction
CTS-PAC Version 1.6 36
Comparison operatorsComparison operatorsComparison operatorsComparison 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 37
Comparison operators Comparison operators (Cont...)(Cont...)Comparison operators Comparison operators (Cont...)(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 38
Strictly Equal and Equal Strictly Equal and Equal OperatorsOperators
Strictly Equal and Equal Strictly Equal and Equal OperatorsOperators
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 39
Logical OperatorsLogical OperatorsLogical OperatorsLogical 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 40
Logical Operators Logical Operators (Cont...)(Cont...)Logical Operators Logical Operators (Cont...)(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 41
Concatenation operatorsConcatenation operatorsConcatenation operatorsConcatenation 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 42
Concatenation operators Concatenation operators (Cont...)(Cont...)
Concatenation operators Concatenation operators (Cont...)(Cont...)
blank concatenate terms, one blank in betweene.g. TRUE BLUE result is TRUE BLUE
|| concatenate terms, no blanks in betweene.g. “a”||”.b” result is a.b
abuttal concatenate terms, no blanks in betweene.g. per_cent‘%’ if per_cent = 50, result is 50%
CTS-PAC Version 1.6 43
Overall Operator PriorityOverall Operator PriorityOverall Operator PriorityOverall 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 44
Control of Control of program flowprogram flow
Control of Control of program flowprogram flow
CTS-PAC Version 1.6 45
Conditional instructionsConditional instructionsConditional instructionsConditional 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 46
IF constructIF constructIF constructIF construct
Can direct the execution of an exec to one of two choices
IF expression THEN instructionELSE 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 47
IF construct IF construct (Cont...)(Cont...)IF construct IF construct (Cont...)(Cont...)
IF expression THEN DO
instructioninstruction
ENDELSE
DOinstructioninstruction
END
CTS-PAC Version 1.6 48
SELECT constructSELECT constructSELECT constructSELECT construct
can direct the execution to one of many choices. SELECT
WHEN expression THEN instructionWHEN expression THEN instruction:OTHERWISEinstruction(s)
END
CTS-PAC Version 1.6 49
SELECT constructSELECT constructSELECT constructSELECT 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 50
Looping instructionsLooping instructionsLooping instructionsLooping 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 51
Repetitive loopsRepetitive loopsRepetitive loopsRepetitive 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 52
Repetitive loopsRepetitive loopsRepetitive loopsRepetitive loops
DO FOREVER/END - infinite loopsEXIT when a condition is reached
LEAVE instruction - leaves the loope.g. DO FOREVER
IF X = 0 THEN LEAVE
CTS-PAC Version 1.6 53
Conditional loopsConditional loopsConditional loopsConditional 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 54
Conditional loopsConditional loopsConditional loopsConditional 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 55
Interrupt instructionsInterrupt instructionsInterrupt instructionsInterrupt 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 56
EXITEXITEXITEXIT
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 57
SIGNAL labelSIGNAL labelSIGNAL labelSIGNAL 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 58
SIGNAL labelSIGNAL labelSIGNAL labelSIGNAL 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 59
CALL / RETURNCALL / RETURNCALL / RETURNCALL / 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 60
CALL / RETURNCALL / RETURNCALL / RETURNCALL / 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 61
Functions and SubroutinesFunctions and SubroutinesFunctions and SubroutinesFunctions and Subroutines
CTS-PAC Version 1.6 62
FunctionsFunctionsFunctionsFunctions
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 63
Functions - parametersFunctions - parametersFunctions - parametersFunctions - 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 64
Functions - TypesFunctions - TypesFunctions - TypesFunctions - 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 65
Built-in functionsBuilt-in functionsBuilt-in functionsBuilt-in functions
CTS-PAC Version 1.6 66
Arithmetic functionsArithmetic functionsArithmetic functionsArithmetic 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 67
Arithmetic functionsArithmetic functionsArithmetic functionsArithmetic 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 68
Comparison functionsComparison functionsComparison functionsComparison 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 69
Conversion functionsConversion functionsConversion functionsConversion 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 70
Conversion functionsConversion functionsConversion functionsConversion functions
D2X Decimal to Hexadecimal X2B Hexadecimal to binary X2C Hexadecimal to Character X2D Hexadecimal to Decimal
CTS-PAC Version 1.6 71
Formatting functionsFormatting functionsFormatting functionsFormatting 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 72
Formatting functionsFormatting functionsFormatting functionsFormatting 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 73
Formatting functionsFormatting functionsFormatting functionsFormatting 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 74
String manipulating String manipulating functionsfunctions
String manipulating String manipulating functionsfunctions
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 75
String manipulating String manipulating functionsfunctions
String manipulating String manipulating functionsfunctions
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 76
String manipulating String manipulating functionsfunctions
String manipulating String manipulating functionsfunctions
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 77
String manipulating String manipulating functionsfunctions
String manipulating String manipulating functionsfunctions
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 78
String manipulating String manipulating functionsfunctions
String manipulating String manipulating functionsfunctions
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 79
String manipulating String manipulating functionsfunctions
String manipulating String manipulating functionsfunctions
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 80
String manipulating String manipulating functionsfunctions
String manipulating String manipulating functionsfunctions
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 81
Miscellaneous functionsMiscellaneous functionsMiscellaneous functionsMiscellaneous 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 82
Miscellaneous functionsMiscellaneous functionsMiscellaneous functionsMiscellaneous 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 83
Miscellaneous functionsMiscellaneous functionsMiscellaneous functionsMiscellaneous 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 84
Miscellaneous functionsMiscellaneous functionsMiscellaneous functionsMiscellaneous 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 85
Miscellaneous functionsMiscellaneous functionsMiscellaneous functionsMiscellaneous 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 86
Date formatsDate formatsDate formatsDate 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 87
Date formatsDate formatsDate formatsDate 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 88
Date formatsDate formatsDate formatsDate 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 89
Date formatsDate formatsDate formatsDate 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 90
Date formatsDate formatsDate formatsDate 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 91
Time formatsTime formatsTime formatsTime 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 92
Time formatsTime formatsTime formatsTime 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 93
Time formatsTime formatsTime formatsTime 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 94
Time formatsTime formatsTime formatsTime 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 95
Time formatsTime formatsTime formatsTime 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 96
Time formatsTime formatsTime formatsTime 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 97
Time formatsTime formatsTime formatsTime 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 98
Time formatsTime formatsTime formatsTime 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 99
Time formatsTime formatsTime formatsTime 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 100
SubroutinesSubroutinesSubroutinesSubroutines
CTS-PAC Version 1.6 101
SubroutinesSubroutinesSubroutinesSubroutines
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 102
SubroutinesSubroutinesSubroutinesSubroutines
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 103
Using subroutinesUsing subroutinesUsing subroutinesUsing subroutines
Sharing information can be done by
Passing variables
Passing arguments
CTS-PAC Version 1.6 104
Passing VariablesPassing VariablesPassing VariablesPassing 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 105
An exampleAn exampleAn exampleAn example number1 = 5 number2 = 10 CALL sub1 SAY answer
(Displays 15) EXIT
sub1: answer = number1 +
number2 RETURN
CTS-PAC Version 1.6 106
Shielding VariablesShielding VariablesShielding VariablesShielding 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 107
An exampleAn exampleAn exampleAn example number1 = 10
CALL sub2 SAY number1 number2
(displays 10 NUMBER2) EXIT
sub2: PROCEDURE number1 = 7 number2 = 5 RETURN
CTS-PAC Version 1.6 108
Exposing VariablesExposing VariablesExposing VariablesExposing 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 109
An exampleAn exampleAn exampleAn example number1 = 10 CALL sub3 SAY number1 number2
(displays 7 NUMBER2) EXIT
sub3: PROCEDURE EXPOSE number1
number1 = 7 number2 = 5 RETURN
CTS-PAC Version 1.6 110
Passing ArgumentsPassing ArgumentsPassing ArgumentsPassing 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 111
An exampleAn exampleAn exampleAn 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
CTS-PAC Version 1.6 112
Compound variablesCompound variablesCompound variablesCompound 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 113
Using REXXUsing REXXUsing REXXUsing REXX
CTS-PAC Version 1.6 114
ConventionsConventionsConventionsConventions
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 115
ConcatenationsConcatenationsConcatenationsConcatenations
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 116
MODEL commandMODEL commandMODEL commandMODEL 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 117
ExecutionExecutionExecutionExecution
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 118
Debugging REXX ExecsDebugging REXX ExecsDebugging REXX ExecsDebugging 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 119
Debugging REXX ExecsDebugging REXX ExecsDebugging REXX ExecsDebugging 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 120
Debugging REXX ExecsDebugging REXX ExecsDebugging REXX ExecsDebugging 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 121
TSO/E External functionsTSO/E External functionsTSO/E External functionsTSO/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 122
ISPF functionsISPF functionsISPF functionsISPF functions
CTS-PAC Version 1.6 123
PanelsPanelsPanelsPanels
Display panels, accept data and pass on data for processing
Syntax is ADDRESS ISPEXEC “Display panel(XXXXXX)”
CTS-PAC Version 1.6 124
TablesTablesTablesTables
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 125
SkeletonsSkeletonsSkeletonsSkeletons
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 126
LM FunctionsLM FunctionsLM FunctionsLM Functions
Dataset list Member list
Copy members Delete members manipulate statistics of members
CTS-PAC Version 1.6 127
Data stackData stackData stackData 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 128
Data stackData stackData stackData 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 129
Input/Output processingInput/Output processingInput/Output processingInput/Output processing
Operations with datasets All datasets with a defined record format are allowed
(except RECFM=U)
CTS-PAC Version 1.6 130
DISKRDISKRDISKRDISKR
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 131
DISKWDISKWDISKWDISKW
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 132
An exampleAn exampleAn exampleAn 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 133
ReferencesReferencesReferencesReferences
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 134
Thank Thank You!You!
Thank Thank You!You!