1.66k likes | 3.04k Views
REXX. Objectives. Introduction to REXX Syntax and Functions Advanced Concepts. 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. Features of REXX.
E N D
Objectives • Introduction to REXX • Syntax and Functions • Advanced Concepts
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
Features of REXX • Ease of use • Free format • Convenient built-in functions
Features of REXX (Cont...) • Debugging capabilities • Interpreted language • Extensive parsing capabilities
Components of REXX • Instructions • Built-in functions • TSO/E external functions • Data stack functions
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
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)
Built-in functions • These functions are built into the language processor • Provide convenient processing options
TSO/E external functions • Interact with the system • Do specific tasks for REXX
Data stack functions • Store data for I/O • Other types of processing
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
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
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
Variables • 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
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
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
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.’
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 ‘’
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.”
Parsing • Separators - an example • phrase = ‘Dun & Bradstreet’ • PARSE VAR phrase part1 ‘&’ part2 • part1 contains ‘Dun ’ • part2 contains ‘ Bradstreet’
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
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
Parsing • Absolute column position - an example • quote = ‘Dun & Bradstreet’ • PARSE VAR quote part1 6 part2 • part1 contains ‘Dun &’ • part2 contains ‘Bradstreet’
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’
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 (-)
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’
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
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’
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
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
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
Arithmetic Operators - Priority • Priority from maximum to minimum • - + Prefix operators • ** Power (exponential) • * / % // Multiplication and division • + - Addition and subtraction
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
Comparison operators (Cont...) • \== Not strictly equal • \= Not equal • >< Greater than or less than (same as not equal) • \< Not less than • \> Not greater than
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
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
Logical Operators (Cont...) • The logical operators are • & ANDReturns 1 if both comparisons are true • | Inclusive ORReturns 1 if at least one comparison is true • && Exclusive ORReturns 1 if only one comparison (but not both) is true • Prefix \ Logical NOTReturns the opposite response
Concatenation operators • Combine two terms into one • Terms can be strings, variables, expressions, or constants • Concatenation can be significant in formatting output
Concatenation operators (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%
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
Conditional instructions • Instructions which set up at least one condition in the form of an expression • IF/THEN/ELSE, and • SELECT/WHEN/OTHERWISE
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
IF construct (Cont...) • IF expression THEN DO instruction instruction ENDELSE DO instruction instruction END
SELECT construct • can direct the execution to one of many choices. • SELECT WHEN expression THEN instruction WHEN expression THEN instruction : OTHERWISE instruction(s)END
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
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