rexx

Post on 24-Nov-2014

285 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

04/08/23 1

REXX

04/08/23 2

ObjectivesObjectives

Introduction to REXX

Syntax and Functions

Advanced Concepts

04/08/23 3

IntroductionIntroduction

What is REXX ?– Restructured EXtended eXecutor– Interpreted command language– Very useful for linking TSO, ISPF and other

functions– Useful for developing custom-made utilities

04/08/23 4

Features of REXXFeatures of REXX

Ease of use

Free format

Convenient built-in functions

04/08/23 5

Features of REXX (Cont...)Features of REXX (Cont...)

Debugging capabilities

Interpreted language

Extensive parsing capabilities

04/08/23 6

Components of REXXComponents of REXX

InstructionsBuilt-in functionsTSO functionsData stack functions

04/08/23 7

InstructionInstructionKeyword

– 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 CALL/SIGNAL instruction

04/08/23 8

Instruction (Cont...)Instruction (Cont...)

Command (both REXX commands and host commands)

04/08/23 9

Built-in functionsBuilt-in functions

These functions are built into the language processor

Provide convenient processing options

04/08/23 10

TSO external functionsTSO external functions

Interact with the systemDo specific tasks for REXX

04/08/23 11

Data stack functionsData stack functions

Store data for I/O Other types of processing

04/08/23 12

Syntax of REXXSyntax of REXX

04/08/23 13

Character Type of REXXCharacter Type of REXXA REXX instruction can be in lower case, upper

case, or mixed caseAlphabetic 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

04/08/23 14

FormatFormatREXX uses a free formatA 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

04/08/23 15

Environment / AddressEnvironment / Address

ADDRESS TSO for native TSO commandsADDRESS ISPEXEC for ISPF servicesADDRESS ISREDIT for ISPF edit macros These are required to invoke the environment for

function calls

04/08/23 16

Variables and expressionsVariables and expressions

04/08/23 17

VariablesVariables

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

04/08/23 18

Variables (Cont...)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

04/08/23 19

ParsingParsingSeparates data by comparing the data to a

template (or pattern of variable names)Preserves the case of the input dataPARSE UPPER converts data to uppercaseSeparators in a template can be

– blank, – string,– variable, or– number that represents column position

04/08/23 20

ParsingParsing

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

04/08/23 21

ParsingParsing

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 ‘’

04/08/23 22

ParsingParsing

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

04/08/23 23

ParsingParsing

Separators - an example– phrase = ‘Dun & Bradstreet’– PARSE VAR phrase part1 ‘&’ part2– part1 contains ‘Dun ’– part2 contains ‘ Bradstreet’

04/08/23 24

ParsingParsing

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

04/08/23 25

ParsingParsing

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

04/08/23 26

ParsingParsing

Absolute column position - an example – quote = ‘Dun & Bradstreet’– PARSE VAR quote part1 6 part2

• part1 contains ‘Dun &’

• part2 contains ‘Bradstreet’

04/08/23 27

ParsingParsing

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’

04/08/23 28

ParsingParsing

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

04/08/23 29

ParsingParsing

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’

04/08/23 30

ParsingParsing

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

04/08/23 31

ParsingParsing

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’

04/08/23 32

ExpressionsExpressions

Something that needs to be calculated/evaluatedConsists of numbers, variables, or strings, and

one or more operatorsFour types of operators

– Arithmetic– Comparison– Logical and– Concatenation

04/08/23 33

Arithmetic 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

04/08/23 34

Arithmetic Operators (Cont...)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

04/08/23 35

Arithmetic Operators - PriorityArithmetic Operators - Priority

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

04/08/23 36

Comparison operatorsComparison operatorsDo not return a number valueReturn 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

04/08/23 37

Comparison operators (Cont...)Comparison operators (Cont...)

– \== Not strictly equal– \= Not equal– >< Greater than or less than (same as not equal)– \< Not less than– \> Not greater than

04/08/23 38

Strictly Equal and Equal OperatorsStrictly 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

04/08/23 39

Logical 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 instructionsCan act as checkpoints to screen unwanted

conditions

04/08/23 40

Logical Operators (Cont...)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 NOTReturns the opposite response

04/08/23 41

Concatenation operatorsConcatenation operators

Combine two terms into oneTerms can be strings, variables, expressions, or

constantsConcatenation can be significant in formatting

output

04/08/23 42

Concatenation operators (Cont...)Concatenation operators (Cont...)

blankconcatenate 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%

04/08/23 43

Overall Operator PriorityOverall Operator Priority \ ¬ - + Prefix operators** Power (exponential)* / % // Multiply and divide+ - Add and subtractblank || abuttal Concatenation operators== = >< Comparison operators& Logical AND | && inclusive OR, exclusive

OR

04/08/23 44

Control of program flow

Control of program flow

04/08/23 45

Conditional instructionsConditional instructions

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

IF/THEN/ELSE, and

SELECT/WHEN/OTHERWISE

04/08/23 46

IF 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

04/08/23 47

IF construct (Cont...)IF construct (Cont...) IF expression THEN

DOinstructioninstruction

ENDELSE

DOinstructioninstruction

END

04/08/23 48

SELECT constructSELECT construct

can direct the execution to one of many choices.SELECT

WHEN expression THEN instructionWHEN expression THEN instruction:OTHERWISEinstruction(s)

END

04/08/23 49

SELECT 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

04/08/23 50

Looping instructionsLooping instructions

Tell the language processor to repeat a set of instructions

A loop can repeat a specified number of times orCan use a condition to control repeatingTwo types of loops

– Repetitive repeat instructions a certain number of times

– Conditional use a condition to control repeating

04/08/23 51

Repetitive 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

04/08/23 52

Repetitive 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

04/08/23 53

Conditional 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

04/08/23 54

Conditional 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

04/08/23 55

Interrupt 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

04/08/23 56

EXITEXIT

Causes an exec to unconditionally endReturn to where the exec was invokedCan also return a value to the caller of the

exec

04/08/23 57

SIGNAL labelSIGNAL label

Interrupts the normal flow of an execCauses control to pass to a specified labelUnlike CALL, SIGNAL does not return to a

specific instruction to resume executionWhen SIGNAL is issued from within a loop, the

loop automatically ends

04/08/23 58

CALL / 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

04/08/23 59

CALL / 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

04/08/23 60

Functions and SubroutinesFunctions and Subroutines

04/08/23 61

FunctionsFunctionsSequence 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

04/08/23 62

Functions - 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

04/08/23 63

Functions - 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

04/08/23 64

Functions - Types

User-written functions – Example/*REXX*/

f=INIT_RTN(2,5) say f /* it displays the result of user written

function */ EXIT INIT_RTN:

arg a,b c=a+b

RETURN c

04/08/23 65

Built-in functionsBuilt-in functions

04/08/23 66

Arithmetic functionsArithmetic functions

ABS Returns the absolute value of the input number

MAX Returns the largest number from the list

MIN Returns the smallest number from the list specified

04/08/23 67

Arithmetic functions

ABS('12.3') -> 12.3

ABS(' -0.307') -> 0.307

MAX(-7,-3,-4.3) -> -3

MAX(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,MAX(20,21)) -> 21

MIN(12,6,7,9) -> 6

MIN(17.3,19,17.03) -> 17.03

04/08/23 68

Arithmetic functionsArithmetic functions

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

04/08/23 69

Arithmetic functionsArithmetic functionsSIGN('12.3') -> 1

SIGN(' -0.307') -> -1

SIGN(0.0) -> 0

TRUNC(12.3) -> 12

TRUNC(127.09782,3) -> 127.097

TRUNC(127.1,3) -> 127.100

TRUNC(127,2) -> 127.00

04/08/23 70

Comparison functionsComparison functionsCOMPARE

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

04/08/23 71

Comparison functionsComparison functions

COMPARE(ACC,ACD) /* 3 */

DATATYPE(123) /* NUM OR CHAR */

A.3=5; J=3 ;

SYMBOL('J') /* VAR */

SYMBOL('K') /* LIT */

SYMBOL('A.J') /* VAR */

SYMBOL('552') /* LIT CONSTANT SYMBOL */

SAY SYMBOL('+') /* BAD NOT A VALID SYMBOL */

04/08/23 72

Conversion functionsConversion functions

Convert one type of data representation to another type of data representation

B2X Binary to hexadecimalC2D Character to DecimalC2X Character to HexadecimalD2C Decimal to Character

04/08/23 73

Conversion functionsConversion functions

D2X Decimal to HexadecimalX2B Hexadecimal to binaryX2C Hexadecimal to CharacterX2D Hexadecimal to Decimal

04/08/23 74

Conversion functionsConversion functions

M= B2X(0101) ; SAY M /* BINARY TO HEXADECIMAL 5 */

M= C2D(ABC); SAY M /* CHARACTER TO DECIMAL 12698307 */

M= C2X(ABC); SAY M /* CHARACTER TO HEXADECIMAL C1C2C3 */

M= D2C(123); SAY M /* DECIMAL TO CHARACTER # */

M= D2X(123); SAY M /* DECIMAL TO HEXADECIMAL 7B */

M = X2B(ABC); SAY M /* HEXADECIMAL TO BINARY 101010111100 */

M = X2C(ABC); SAY M /* HEXADECIMAL TO CHARACTER :: */

M = X2D(ABC); SAY M /* HEXADECIMAL TO DECIMAL 2748 */

04/08/23 75

Formatting functionsFormatting functionsCENTER/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

04/08/23 76

Formatting functionsFormatting functions

CENTER(ABC,5) /* ' ABC ' */

CENTER(ABC,10,'-') /* '---ABC----' */

CENTRE(ABC,9,'-') /* '---ABC---' */

COPIES(‘-’,6) ------

FORMAT('1.73',4,3) ' 1.730'

FORMAT('-.76',4,1) ' -0.8'

FORMAT('3.03',4) ' 3.03'

FORMAT(' - 12.73',,4) '-12.7300'

FORMAT(' - 12.73') '-12.73'

04/08/23 77

Formatting 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

04/08/23 78

Formatting 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

04/08/23 79

Formatting functionsFormatting functionsJUSTIFY('THE BLUE SKY',14) -> 'THE BLUE SKY'

JUSTIFY('THE BLUE SKY',8) -> 'THE BLUE'

JUSTIFY('THE BLUE SKY',9) -> 'THE BLUE'

JUSTIFY('THE BLUE SKY',9,'+') -> 'THE++BLUE'

LEFT('ABC D',8) -> 'ABC D '

LEFT('ABC D',8,'.') -> 'ABC D...'

LEFT('ABC DEF',7) -> 'ABC DE'

RIGHT('ABC D',8) -> ' ABC D'

RIGHT('ABC DEF',5) -> 'C DEF'

RIGHT('12',5,'0') -> '00012'

SPACE('ABC DEF ') -> 'ABC DEF'

SPACE(' ABC DEF',3) -> 'ABC DEF'

SPACE('ABC DEF ',1) -> 'ABC DEF'

SPACE('ABC DEF ',0) -> 'ABCDEF'

SPACE('ABC DEF ',2,'+') -> 'ABC++DEF'

04/08/23 80

String manipulating functionsString manipulating functionsABBREV 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

04/08/23 81

String manipulating functionsString manipulating functionsABBREV('PRINT','PRI',3) -> 1

ABBREV('PRINT','PRI') -> 1

ABBREV('PRINT','PRI',4) -> 0

ABBREV('PRINT','PRY') -> 0

ABBREV('PRINT','',1) -> 0

DELSTR('ABCD',3) -> 'AB'

DELSTR('ABCDE',3,2) -> 'ABE'

DELSTR('ABCDE',6) -> 'ABCDE'

DELWORD('NOW IS THE TIME',2,2) -> 'NOW TIME'

DELWORD('NOW IS THE TIME ',3) -> 'NOW IS '

DELWORD('NOW IS THE TIME',5) -> 'NOW IS THE TIME'

DELWORD('NOW IS THE TIME',3,1) -> 'NOW IS TIME'

04/08/23 82

String manipulating functionsString manipulating functionsFIND 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

04/08/23 83

String manipulating functionsString manipulating functions

FIND('NOW IS THE TIME','IS THE TIME') -> 2

FIND('NOW IS THE TIME',' THE') -> 3

FIND('NOW IS THE TIME',' HE') -> 0

INDEX('abcdef','cd') -> 3

INDEX('abcdef','xd') -> 0

INDEX('abcabc','bc',3) -> 5

INDEX('abcabc','bc',6) -> 0

INSERT(' ','abcdef',3) -> 'abc def'

INSERT('123','abc',5,6) -> 'abc 123 '

INSERT('123','abc',5,6,'+') -> 'abc++123+++'

INSERT('123','abc') -> '123abc'

INSERT('123','abc',,5,'-') -> '123--abc'

04/08/23 84

String manipulating functionsString manipulating functionsLASTPOS 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

04/08/23 85

String manipulating functionsString manipulating functionsLASTPOS(' ','abc def ghi') -> 8 LASTPOS(' ','abcdefghi') -> 0 LASTPOS('xy','efgxyz') -> 4 LASTPOS(' ','abc def ghi',7) -> 4 LENGTH('abcdefgh') -> 8 LENGTH('abc defg') -> 8 LENGTH('') -> 0

OVERLAY(' ','abcdef',3) -> 'ab def' OVERLAY('.','abcdef',3,2) -> 'ab. ef' OVERLAY('qq','abcd') -> 'qqcd' OVERLAY('qq','abcd',4) -> 'abcqq' OVERLAY('123','abc',5,6,'+') -> 'abc+123+++' M=OVERLAY('D',, OVERLAY('C',, OVERLAY('B','A',15),25),35)

04/08/23 86

String manipulating functionsString manipulating functionsPOS 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

04/08/23 87

String manipulating functionsString manipulating functionsPOS('day','Saturday') -> 6

POS('x','abc def ghi') -> 0

POS(' ','abc def ghi') -> 4

POS(' ','abc def ghi',5) -> 8

REVERSE('ABc.') -> '.cBA'

REVERSE('XYZ ') -> ' ZYX'

STRIP(' ab c ') -> 'ab c'

STRIP(' ab c ','L') -> 'ab c '

STRIP(' ab c ','t') -> ' ab c'

STRIP('12.7000',,0) -> '12.7'

STRIP('aabbca',,a) -> 'bbc'

04/08/23 88

String manipulating functionsString manipulating functionsSUBSTR 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

04/08/23 89

String manipulating functionsString manipulating functionsSUBSTR('abc',2) -> 'bc'

SUBSTR('abc',2,4) -> 'bc '

SUBSTR('abc',2,6,'.') -> 'bc....'

SUBWORD('Now is the time',2,2) -> 'is the'

SUBWORD('Now is the time',3) -> 'the time'

SUBWORD('Now is the time',5) -> ''

TRANSLATE('abbc','&','b') -> 'a&&c'

TRANSLATE('abcdef','12','ec') -> 'ab2d1f'

TRANSLATE('abcdef','12','abcd','.') -> '12..ef'

TRANSLATE('APQRV',,'PR') -> 'A Q V'

04/08/23 90

String manipulating functionsString manipulating functionsVERIFY

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

04/08/23 91

String manipulating functionsString manipulating functions VERIFY('123','1234567890') -> 0

VERIFY('1Z3','1234567890') -> 2

VERIFY('AB4T','1234567890') -> 1

VERIFY('AB4T','1234567890','M') -> 3 /*Match */

VERIFY('AB4T','1234567890','N') -> 1

VERIFY('1P3Q4','1234567890',,3) -> 4

VERIFY('123','',N,2) -> 2

VERIFY('ABCDE','',,3) -> 3

VERIFY('AB3CD5','1234567890','M',4) -> 6

WORD('a b c',2) -> 'b'

WORDINDEX('Now is the time',3) -> 8

WORDINDEX('Now is the time',6) -> 0

04/08/23 92

String manipulating functionsString manipulating functionsWORDLENGTH 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

04/08/23 93

String manipulating functionsString manipulating functionsWORDLENGTH('Now is the time',2) -> 2

WORDLENGTH('Now comes the time',2) -> 5

WORDLENGTH('Now is the time',6) -> 0

WORDPOS('the','now is the time') -> 3

WORDPOS('The','now is the time') -> 0

WORDPOS('is the','now is the time') -> 2

WORDPOS('is the','now is the time') -> 2

WORDS('Now is the time') -> 4

WORDS(' ') -> 0

04/08/23 94

Date 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

04/08/23 95

Date 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

04/08/23 96

Date formatsDate formatsCentury 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)

04/08/23 97

Date 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

04/08/23 98

Date 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

04/08/23 99

Time 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

04/08/23 100

Time formatsTime formatsCivil

– 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

04/08/23 101

Time 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

04/08/23 102

Time 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

04/08/23 103

Time 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

04/08/23 104

Time 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

04/08/23 105

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

04/08/23 106

Time 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

04/08/23 107

Time 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

04/08/23 108

SubroutinesSubroutines

04/08/23 109

SubroutinesSubroutines

Series of instructions that an exec invokes Performs a specific taskThe subroutine is invoked by the CALL

instructionWhen the subroutine ends, it returns control to

the instruction that directly follows the subroutine call

The instruction that returns control is the RETURN instruction

04/08/23 110

SubroutinesSubroutinesSubroutines 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

04/08/23 111

Using subroutinesUsing subroutines

Sharing information can be done by

– Passing variables

– Passing arguments

04/08/23 112

Passing 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

04/08/23 113

An exampleAn exampleNUMBER1 = 5

NUMBER2 = 10

CALL SUB1

SAY ANSWER (DISPLAYS 15)

EXIT

SUB1:

ANSWER = NUMBER1 + NUMBER2

RETURN

04/08/23 114

Shielding 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

04/08/23 115

An exampleAn example

NUMBER1 = 10

CALL SUB2

SAY NUMBER1 NUMBER2(DISPLAYS 10 NUMBER2)

EXIT SUB2: PROCEDURE

NUMBER1 = 7

NUMBER2 = 5

RETURN

04/08/23 116

Exposing 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

04/08/23 117

An exampleAn exampleNUMBER1 = 10

CALL SUB3

SAY NUMBER1 NUMBER2 (DISPLAYS 7 NUMBER2)

EXIT

SUB3: PROCEDURE EXPOSE NUMBER1

NUMBER1 = 7

NUMBER2 = 5

RETURN

04/08/23 118

Passing ArgumentsPassing ArgumentsPassed 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

04/08/23 119

An exampleAn exampleLENGTH = 10

WIDTH = 7

CALL SUB4 LENGTH, WIDTH

SAY ‘THE PERIMETER IS ‘ RESULT ‘METERS’

EXIT

SUB4:

ARG LEN, WID

PERIM = 2 * ( LEN + WID)

RETURN PERIM

04/08/23 120

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

04/08/23 121

Compound variables

PGM. = " "

PGM.. = " "

PGM...= " " /* Initializing the compound variables with null */

PGM....= " "

PGM..... = " "

PGM.1 = 'ABC'

PGM.1.1 = 'DEF' /* Assigning the compound variables */

PGM.1.1.1 = 'GHI'

PGM.1.1.1.1 = 'IJK'

PGM.1.1.1.1.1 = 'LMN'

PGM.J = 'ABC' /* J,K,L,M,N can be variables */

PGM.J.K = 'DEF'

PGM.J.K.L = 'GHI'

PGM.J.K.L.M = 'IJK'

PGM.J.K.L.M.L = 'LMN'

04/08/23 122

Using REXXUsing REXX

04/08/23 123

ConventionsConventions

Datasets are named as<high level qualifier>.REXX.EXEC

The last level .EXEC is optionalEach member must have the first line

as /* REXX */This makes the command processor (TSO)

invoke the REXX interpreter

04/08/23 124

ConcatenationsConcatenations

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

04/08/23 125

ExecutionExecution

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

04/08/23 126

Online Execution

From ISPF command line prompt

TSO EXEC ‘XXX.XXX.REXX(MYREXX)’ EXEC From ISPF Command Shell(Option 6 in primary

panel)

EXEC ‘XXX.XXX.REXX(MYREXX)’ EXEC VIEW XXX.XXX.REXX

Command ===>

Name Prompt

EXEC_____ MYREXX

_________ MYREX2

04/08/23 127

Batch Execution

//--------JOBCARD--------

//ISPF1 EXEC PGM=IKJEFT01

//SYSPRINT DD SYSOUT=*

//SYSTSPRT DD SYSOUT=*

//SYSOUT DD SYSOUT=*

//SYSTSIN DD *

EX ‘XXX.XXX.REXX(MYREXX)‘

//*

04/08/23 128

Data stackData stack

Place for storing variables temporarilyManipulated using PUSH and QUEUENo limits on the length and format of the data

itemsTheoretically no limit on the number of items to

be stacked - limited only by practical considerations

04/08/23 129

Data Stack

  Stack

Queue A1 Queue A2 Queue A3

A1A2A3

Push A4 Push A5 Push A6 A6

A5A4A1A2A3

Pull Stmt A6Pull Stmt A5Pull Stmt A4Pull Stmt A3Pull Stmt A2Pull Stmt A1

Instruction Result

04/08/23 130

Data 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 PULLQUEUED() gives the number of items put on a

stack in a single EXEC

04/08/23 131

Data Stack - example/*REXX*/ QUEUE AMD1 QUEUE AMD2 "NEWSTACK" QUEUE AMD3 /*FIFO*/ QUEUE AMD4 PUSH AMD5 /*LIFO*/ PULL A PULL A PULL A PULL A PULL A "DELSTACK" PULL A "DELSTACK" PULL A EXIT

04/08/23 132

Input/Output processingInput/Output processing

Operations with datasetsAll datasets with a defined record format

are allowed (except RECFM=U)

04/08/23 133

DISKRDISKR

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

04/08/23 134

DISKWDISKW

Options for DISKR also hold for DISKWWrites to dataset/memberCan be written from stem/stackNumerous other options available for

positioning, skipping, LIFO/FIFO etc.

04/08/23 135

ExampleExampleUse 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

04/08/23 136

Example:/*REXX*/ ARG DSNI DSNO /*DSNI="IMS5.CA7.OVER" DSNO="PXX.IMS5.CA7.OVER" */ CALL INIT_RTN CALL MAIN_RTN EXIT INIT_RTN: DROP INP. DROP MEM. PROCLIB=DSNI PROCLIB1="'"PROCLIB"'" ADDRESS TSO A=OUTTRAP("MEM.","*") "LISTDS "procLIB1" MEMBERS"

A=OUTTRAP("OFF") SAY MEM.0 RETURN

MAIN_RTN: DO J=7 TO MEM.0 XTEMP=STRIP(MEM.J) DSNAME=PROCLIB||"("||XTEMP||")" DNAME = "'" || DSNAME || "'" OSNAME=DSNO||"("||XTEMP||")" ONAME = "'" || OSNAME || "'" DROP INP. "ALLOC DDN(INPFL) DSN("DNAME") SHR REUSE"

"EXECIO * DISKR INPFL (STEM INP. FINIS)" "FREE DDN(INPFL)" "ALLOC DDN(ONPFL) DSN("ONAME") SHR

REUSE" "EXECIO * DISKW ONPFL (STEM INP. FINIS)" "FREE DDN(ONPFL)" DROP INP. END RETURN

04/08/23 137

Debugging 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 EXECEXECUTIL TS (Trace start) and TE (trace end)

can also be used to start and end the tracing of a REXX

04/08/23 138

Debugging REXX ExecsDebugging REXX Execs

RC Return code of the last instruction executed

SIGLSet to the line number from where the transfer occurred

These variables can also be used to trace the exec

04/08/23 139

TSO External functionsTSO External functions

All TSO commands can be issuedEnclose 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

04/08/23 140

LISTDS ‘XXX.XXX.REXX' STATUS

XXX.XXX.REXX

--RECFM-LRECL-BLKSIZE-DSORG--DDNAME---DISP

FB 80 27920 PO SYS00007

KEEP --VOLUMES--

TPT047

04/08/23 141

ISPF functionsISPF functions

04/08/23 142

PanelsPanels

Display panels, accept data and pass on data for processing

Syntax is– ADDRESS ISPEXEC– “Display panel(XXXXXX)”

04/08/23 143

PANEL – EXAMPLE

)ATTR @ TYPE(TEXT) INTENS(HIGH) COLOR(YELLOW) ~ TYPE(TEXT) INTENS(HIGH) COLOR(PINK) $ TYPE(TEXT) INTENS(HIGH) COLOR(RED) # TYPE(OUTPUT) INTENS(HIGH) COLOR(TURQ) ! TYPE(TEXT) INTENS(HIGH) COLOR(WHITE) * TYPE(TEXT) INTENS(LOW) COLOR(RED) HILITE(REVERSE) _ TYPE(INPUT) INTENS(LOW) COLOR(TURQ) + TYPE(TEXT) INTENS(LOW) % TYPE(TEXT) INTENS(HIGH) COLOR(WHITE) )BODY + +COMMAND ==>_PCMD + + ! USER:#UID + + * MAIN-PANEL * ! DATE:#DAT + + %------------------+ ! TIME:#TIM + + @OPTION ==>_O+ + ! 1.~ PTR SOURCE ANALYSIS + ! 2.~ PTR JOB ANALYSIS + )INIT .CURSOR='O' &PCMD='' &O='' )PROC VPUT (O) PROFILE VER(&O,NB,LIST,'1','2','3') )END

04/08/23 144

Panel example)ATTR @ TYPE(OUTPUT) INTENS(HIGH) # TYPE(OUTPUT) INTENS(LOW) COLOR(YELLOW) * TYPE(TEXT) INTENS(LOW) COLOR(GREEN) HILITE(REVERSE) TYPE(OUTPUT) INTENS(LOW) COLOR(TURQ) % TYPE(TEXT) INTENS(LOW) COLOR(TURQ) HILITE(USCORE) + TYPE(TEXT) INTENS(LOW) )BODY +-----------------* ARRAY OF VARIABLES +--------------------------+ +COMMAND ==>_ZCMD +SCROLL ==>_SAMT +

+ + +JOBNAME1 STEP1 PGM1 DDN1 DSN1 DISP1)MODEL @JOBNAME1 #STEP1 PGM1 @DDN1 #DSN1 DISP)INIT &SAMT=CSR &ZCMD='' )END

04/08/23 145

TablesTables

All table services like TBCREATE, TBADD, TBUPDATE, TBDELETE etc.

Syntax is– ADDRESS ISPEXEC– “TBADD tbl-name ....”– “TBDELETE tbl-name...” etc.

04/08/23 146

ISPF Tables - Syntax"ISPEXEC LIBDEF ISPTLIB DATASET ID(“XXX.XXX") "

"ISPEXEC LIBDEF ISPTABL DATASET ID(“XXX.XXX") "

COLUMNS = "A1 B1 C1 D1 E1 F1"

"ISPEXEC TBERASE "TEMP""

"ISPEXEC TBCREATE "TEMP" NAMES("COLUMNS") WRITE"

"ISPEXEC TBOPEN “TEMP" NOWRITE"

A1=AMD

"ISPEXEC TBSARG “TEMP" NEXT NAMECOND(A1,EQ)"

"ISPEXEC TBSCAN “TEMP""

"ISPEXEC TBADD "TEMP""

"ISPEXEC TBBOTTOM "TEMP""

"ISPEXEC TBCLOSE "TEMP""

"ISPEXEC TBOPEN "TEMP" NOWRITE"

"ISPEXEC TBDISPL "TEMP" PANEL(PANEL1)"

"ISPEXEC TBSKIP "TEMP"

"ISPEXEC TBCLOSE "TEMP""

04/08/23 147

SkeletonsSkeletons

ISPF Skeleton services like generating JCLs from skeletons

Syntax is– ADDRESS ISPEXEC– “FTOPEN”– “FTINCL SKELNAME”– “FTCLOSE TEMP”– ADDRESS TSO– “SUBMIT ZTEMPF”

04/08/23 148

File Tailoring Example:

/*REXX*/

"ISPEXEC LIBDEF ISPSLIB DATASET ID('PXX.XXX.SKEL') UNCOND"

PGM="IKEJFT01"

"ISPEXEC FTOPEN TEMP"

"ISPEXEC FTINCL PRAS"

"ISPEXEC FTCLOSE"

"ISPEXEC VGET (ZTEMPF)"

SAY ZTEMPF

"SUBMIT '"ZTEMPF"'"

EXIT

04/08/23 149

File Tailoring Example:

Skeleton PRAS :

//SKELJCL JOB ('245T01',53),'SKELJCL',CLASS=T,

// MSGCLASS=T,REGION=0M,NOTIFY=&SYSUID

//*

//ISPF1 EXEC PGM=&PGM

//SYSPRINT DD SYSOUT=*

//SYSTSPRT DD SYSOUT=*

//SYSOUT DD SYSOUT=*

//SYSTSIN DD *

EX ‘XXX.XXX.REXX(MYREXX)'

//*

04/08/23 150

ISREDIT Macros

Edit a dataset from program for required processing

Syntax is– ADDRESS ISPEXEC – "EDIT DATASET(‘XXX.XXX.XXX’)

MACRO(MYMACRO)"

04/08/23 151

Macro Example:

/*REXX*/

ARG DSNAME1

ADDRESS ISPEXEC "EDIT DATASET('"DSNAME1"') MACRO(MACRO1)"

<< INSTRUCTION >>

<< INSTRUCTION >>

<< INSTRUCTION >>

EXIT

04/08/23 152

Macro Example:

MACRO1/*REXX*/ ADDRESS ISPEXEC "ISREDIT MACRO" "ISREDIT FIND FIRST 'ENVIRONSYSTEM'" "ISREDIT X ALL ' ' 47 70 " "ISREDIT DEL ALL X" "ISREDIT C ALL ' ' 87 90 '****'" "ISREDIT SAVE" "ISREDIT END"

"ISREDIT MEND"

04/08/23 153

Messages:

Pop messages to the panel Syntax is

– "SETMSG MSG(MSGXXnn) COND"

04/08/23 154

Message Example

MYREXX:

MSG01:

"ISPEXEC LIBDEF ISPMLIB DATASET ID(“XXX.XXX.MESG") " If SYSDSN(PPP.PPP.PP) /= ‘OK’ THEN“ISPEXEC SETMSG MSG(MSG010A) “

MSG010A 'NO DATASET' .ALARM=YES ‘DATA SET IS NOT CATALOGUED ON THE DEVICE'

MSG010B 'NO MEMBER IN DATASET' .ALARM=YES ‘MEMBER NOT FOUND IN THE DATA SET ON THE DEVICE'

04/08/23 155

LM FunctionsLM Functions

Dataset listMember list

– Copy members– Delete members– manipulate statistics of members

04/08/23 156

LMDLIST - Example

/*REXX*/

LVL = USERID()

"ISPEXEC LMDINIT LISTID(ABC) LEVEL("LVL")"

"ISPEXEC LMDLIST LISTID("ABC") OPTION(SAVE) STATS(YES) GROUP(AMD)"

/* THE OUTPUT WILL BE IN HLQ.AMD.DATASETS*/

"ISPEXEC LMDFREE LISTID("ABC")"

EXIT

04/08/23 157

LMMLIST - Example

/*REXX*/

DSN="‘XXX.XXX.LIST'"

"ISPEXEC LMINIT DATAID(ABC) DATASET("DSN") "

"ISPEXEC LMOPEN DATAID("ABC")"

"ISPEXEC LMMLIST DATAID("ABC") OPTION(SAVE) STATS(YES) GROUP(AMD)"

/* THE OUTPUT WILL BE IN HLQ.AMD.MEMBERS */

"ISPEXEC LMFREE DATAID("ABC")"

EXIT

04/08/23 158

LMCOPY - Example

/*REXX*/ ARG DSNI DSNO ADDRESS TSO "ISPEXEC LMINIT DATASET('"DSNI"') DATAID(INP) ENQ(SHR)" "ISPEXEC LMINIT DATASET('"DSNO"') DATAID(OUT)

ENQ(EXCLU)" "ISPEXEC LMCOPY FROMID("INP") FROMMEM(MEM1) TODATAID("OUT") TOMEM(MEM2) REPLACE"

EXIT

04/08/23 159

ReferencesReferences

TSO/E Version 2 REXX/MVS User’s GuideTSO/E Version 2 REXX/MVS ReferenceBoth these books are available on our file server

(IBM Book Manager for Windows)Programming in REXX by Charles Daney,

J.Ranade IBM series

04/08/23 160

Thank You!

Thank You!

top related