rexx training

106
REXX Training

Upload: shyam-sekhar

Post on 04-Apr-2015

619 views

Category:

Documents


44 download

TRANSCRIPT

Page 1: REXX Training

REXX Training

Page 2: REXX Training

What is REXX ?

Restructured EXtended eXecutor language

Programming language Free format language Issues commands to different host

environments Suitable for beginners as well computer

professionals

Page 3: REXX Training

USAGE of REXX

• Automating repetitive tasks

- Increases productivity

Eg : Allocation of datasets for a release

Eg : Deleting 7th char in all records of a file• Interacting with TSO/ISPF dialog manager

- To create and display custom-made panels

- Can store and retrieve variables • etc.

Page 4: REXX Training

Writing a simple REXX exec• An exec is nothing but a group of REXX statements in a sequential dataset or a PDS member

• The first statement of an exec should be ‘ /* REXX */ ’

• REXX is not case sensitive

• A simple exec (In a PDS member,MYFIRST)

/*REXX*/

SAY ‘This is first REXX exec’

EXIT

Page 5: REXX Training

Executing a REXX exec• Explicit execution from tso ready prompt

READY

EXEC ‘TATA.REXX.EXEC(MYFIRST)’ EXEC

READY

• Implicit execution requires the PDS library to be concatenated to either SYSEXEC or the SYSPROC system DDNAME’s.

READY

ALLOC DD(SYSEXEC) DSN(‘HCL.REXX.EXEC’) SHR

READY

%MYFIRST

•From ISPF,one can execute it by issuing the following command at command prompt

TSO MYFIRST

Page 6: REXX Training

REXX Symbols

•A REXX symbol can consist of

A...Z uppercase alphabetica...z lowercase alphabetic0...9 numbers @ # $ ¢ ? ! . _ special characters

•Rules for valid REXX symbols 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 and RESULT

Page 7: REXX Training

REXX - Arithmetic operators+ Add - Subtract * Multiply / Divide % Divide and return a whole number without a remainder // Divide and return the remainder only ** Raise a number to a whole number power -number Negate the number +number Add the number to 0

Page 8: REXX Training

REXX - Logical operators& AND (4 > 2) & (a = a) /* true, so result is 1 */ (2 > 4) & (a = a) /* false, so result is 0 */

| Inclusive OR(4 > 2) | (5 = 3) /* at least one is true, so result is 1 *(2 > 4) | (5 = 3) /* neither one is true, so result is 0 */

&& Exclusive OR(4 > 2) && (5 = 3) /* only one is true, so result is 1 */(4 > 2) && (5 = 5) /* both are true, so result is 0 */

Prefix \ Logical NOT\ 0 /* opposite of 0, so result is 1 */ \ (4 > 2) /* opposite of true, so result is 0 */

Page 9: REXX Training

REXX - comparison operators = Equal \ = Not equal > Greater than < Less than > < Greater than or less than (same as not equal) > = Greater than or equal to

\ < Not less than < = Less than or equal to \ > Not greater than

Note: The not character, "¬", is synonymous with the backslash ("\").

Page 10: REXX Training

REXX Special Variables

RC: RC stands for return code and is set every time a command is issued.

SIGL: When the language processor transfers control to another routine or another part of the exec, it sets the SIGL special variable to the line number from which the transfer occurred.

RESULT : When an exec calls a subroutine ,the calling exec receives the value returned by the subroutine in the REXX special variable RESULT

Page 11: REXX Training

REXX Instructions

Page 12: REXX Training

REXX Instructions• A line contains usually one instruction

• Comma(‘,’) is the continuation character

• Semi-colon(‘;’) is the instruction delimiter

• Example :

say ‘The quick fox jumps over’,

‘the lazy brown dog’; say ‘over’

Output :The quick fox jumps over the lazy brown dog over

• Note that the comma operator adds a space

Page 13: REXX Training

REXX Instructions - SAY

• To write a line of output to the TSO terminal• Expression can contain variables, literals and functions

/*REXX*/name=‘Roosevelt’say ‘Welcome to TSO ‘ nameexit

• Output Welcome to TSO Roosevelt

Page 14: REXX Training

REXX instruction - PULL• To read the input from the TSO terminal (when REXX

data stack is empty)• Syntax : pull var1 var2 var3…

/*REXX*/

say ‘Enter your name :’

pull name

say ‘Good morning ‘ name

exit

• The output will beEnter your name :

Lincoln

Good morning LINCOLN

• pull automatically converts the input into uppercase

Page 15: REXX Training

REXX Instruction - IF

• Used to conditionally execute a single stmt or a group of statements

• Syntax : if expression then

stmt;

else

stmt;

• A group of statements can be grouped together by using do…end

• Nested IF’s are allowed

Page 16: REXX Training

REXX Instructions - NOP

• nop stands for No-operation

• Causes REXX to create No-operation condition

• Only useful as a target of THEN or ELSE clause

Page 17: REXX Training

REXX Instructions - IF

/*REXX*/ say ’Enter AM/PM :' pull ampm if ampm = 'AM' then say 'Good morning!!!' else if ampm = 'PM' then say 'Good evening!!!' else NOP exit

Page 18: REXX Training

REXX Instructions - DO

• Used to execute a group of statements under the control of an expression

• Has several formats

• The repetitive DO construct

do 5 /* do x=5 is the same */

say ‘hi there!!!’

end

• The statements within do..end will be executed five times

Contd...

Page 19: REXX Training

REXX Instructions - DO

• The do with loop counter

/*REXX*/

do ix = 1 to 7 by 2 /* 2 is the step value */

say ix

end

• The output will be

1

3

5

7

Contd...

Page 20: REXX Training

REXX Instructions - DO• The do…while construct

/*REXX*/

i=1

do while i < 3

say i

i = i + 1

end

• The output

1

2

Contd...

Page 21: REXX Training

REXX Instructions - DO• The do..until construct

/*REXX*/

i=1

do until i > 3

say i

i= i+ 1

end

• The output will be

1

2

3

Contd...

Page 22: REXX Training

REXX Instructions - DO

• The do..forever special construct

/*REXX*/

do forever

say ‘infinite loop’

end

• The above exec results into an infinite loop

• Enough care should be taken to check the exit criteria of the loop, before executing the exec

• The leave instruction can be used to exit from the loop

Page 23: REXX Training

REXX Instructions - LEAVE• Causes REXX to stop executing the current do…end loop and control passes to the next statement after the end of the do…end pair

/*REXX*/do forever

say ‘Enter the code :’pull code

if code = ‘BYE’ then do leave;

endEndsay ‘Statement after do…end’ exit

Page 24: REXX Training

REXX Instructions - ITERATE• Used to restart execution in a do loop

ITERATE {name}• If name is not specified, ITERATE will step the

innermost active loop• If name is specified, that particular loop is stepped

/*REXX*/do i = 1 to 3 by 1if i = 2 then iterate i say ‘i = ‘ i

end

• Outputi = 1i = 3

Page 25: REXX Training

REXX Instructions - SELECT

• Causes REXX to execute one of several different instructions

• Most used when one of the several paths must be followed

/*REXX*/say ‘Enter 1 for salad,2 for pizza :’pull choiceselect when choice = 1 then do say ‘Here is the salad’ end when choice = 2 then say ‘Here is the pizza’ otherwise say ‘You have opted nothing’end

Page 26: REXX Training

REXX Instruction - UPPER• To translate the contents of a single or several variables to

uppercase

• Syntax : upper var1 var2 var3 …/*REXX*/

name =‘Kennedy’

say ‘Name is ‘ name

upper name

say ‘Now name is ‘ name

exit

• OutputName is Kennedy

Now name is KENNEDY

Page 27: REXX Training

REXX Instruction - EXIT

• Used to unconditionally leave a program

• Can optionally pass back a string to the caller

• Syntax : EXIT {expression}

• Example named PROG2

/*REXX*/

a=10

exit a*10 /*return 100 to the caller */

• When prog2 is called in an exec as x=prog2(),then x will have the value 100

Page 28: REXX Training

REXX Instructions - INTERPRET

• Used to execute instructions that are built dynamically

• Syntax : INTERPRET expression • Example :

/*REXX*/ out='say hi there!!!' interpret out stmts='do 3; say 'loop'; end' interpret stmts exit

• Output will be

hi there!!!looplooploop

Page 29: REXX Training

REXX Instructions - PARSE• Tells REXX how to assign data to one or more variables

• PARSE PULL makes REXX get the string from the

REXX data stack. If the stack is empty, REXX will get

the string from the terminal

• PARSE VALUE parses a string under the control of the

template

PARSE VALUE expression WITH template

• PARSE VAR indicates that the string to be parsed is not a

literal but a variable

• PARSE VERSION returns REXX interpreter level and

the date released

Page 30: REXX Training

REXX Instructions - PARSE

• parse value ‘Napolean the great’ with w1 w2 w3

w1 = Napolean w2 = the w3 = great

• parse value ‘Napolean the great’ with w1 9 w2

w1 = ‘Napolean ‘ w2 = ‘the great’

• parse value 'salt+water=brine' with w1 '+' w2 '=' w3

w1 = salt w2 = water w3 = brine

• parse version vervar

say vervar

REXX370 3.48 01 May 1992 Contd…

Page 31: REXX Training

REXX Instructions - DROP

• Used to return one or more REXX variables to their initial

or uninitialised state

• Syntax : DROP name1 name2 name3….;

• Same variable can be dropped more than once

• Examples

drop a

drop z.5

drop d.

Page 32: REXX Training

REXX Instructions - ADDRESS

• To indicate the destination of non-rexx commands• Syntax ADDRESS destination• The destination could be any one of these

TSO - Routes commands to TSO

ISPEXEC - Routes commands to ISPF/PDF

ISREDIT - Routes commands to the ISPF Edit macro processor Address tso ‘lista st’ Address tso ‘listds(‘hclt.rexx.exec’) members’

Address ispexec /* Dest. Changed and set */

Page 33: REXX Training

REXX Instructions - Procedure

• Used to protect the variables in existence when the function

or subroutine is called

• Syntax : PROCEDURE { EXPOSE name1 {name2}…}

name1, name2 are not protected from the subroutine.

That is they are exposed to the subroutine

Page 34: REXX Training

REXX Instructions - Procedure

Example

/*REXX */ lines=2 pages=3 call showlines say 'The line count is' lines ',the page count is' pages /* 'say' above displays 10 for lines and 3 for pages */ exit

showlines: procedure expose lines lines=10 pages=1 return

Page 35: REXX Training

REXX Instructions - ARG

• To parse out the arguments passed to a program or internal subroutine and store the arguments in variables• Eg:

/*REXX*/

arg a,b

c = a+ b

say ‘The sum is ‘ c

exit

• REXX does not prompt for any missing arguments• ARG converts the parameters passed to uppercase

Page 36: REXX Training

REXX Instructions - RETURN• Used to pass control back to the caller of a subroutine or

function.An optional value can also be passed

• Syntax : RETURN {expression }

• If invoked as a function, the value in the return

instruction is substituted for the function call

• If invoked as a subroutine , the value in the RETURN

instruction is stored in the REXX special variable

RESULT

• If the RETURN instruction doesn’t have any expression ,

then a null string is passed to the caller

Page 37: REXX Training

REXX Instructions - CALL

• Used to invoke an internal or external subroutine and built-in-functions

• The called routine usually uses the ARG function to extract the parameters passed by the call

• Eg. arg x /* parse 'x' */ call factorial x /* go get factorial of 'x' */ say x'! =' result /* write result out */ exit

factorial: procedure /* factorial subroutine */ arg n /* parse 'x' */ if n=0 then return 1 /* quit when done */ call factorial n-1 /* call myself with x minus 1 */ return result * n /* build up answer in 'result'*/

Page 38: REXX Training

REXX Instructions - SIGNAL• It is an equivalent command for GOTO command in other

languages

• Syntax : SIGNAL label

• Example/*REXX*/ say ‘Before signal’ /* displayed */ signal bye say ‘After signal’ /* never gets executed */exitbye: say ‘In signal’ /* displayed */ exit

• Note that the say instruction after signal will never get

executed

Page 39: REXX Training

REXX Instruction - PUSH

• Used to place a new element on a REXX data stack

• Syntax : PUSH {expression}

• Places the element on the top of the REXX data stack

• A null string of length zero is stacked if the expression is

omitted

• Stacks strings LIFO sequence

Page 40: REXX Training

REXX Instruction - QUEUE

• Used to place a new element on the bottom of a REXX data stack

• Syntax : QUEUE { expression }

• Stacks strings in FIFO sequence

• A null length string is stacked if expression is omitted

• The PULL instruction is used extract an element from the top

of the REXX data stack

Page 41: REXX Training

Executing REXX in Batch

Page 42: REXX Training

Executing REXX in batch

Need arises when the REXX exec takes longer time to complete the execution.So time-consuming and low priority execs can be run in background

Main advantage - Batch mode does not interfere with persons use of the terminal

Only those execs which do not require any sort of terminal interaction can be run in batch mode.

Page 43: REXX Training

Executing REXX in Batch - JCL

//TSOBATCH EXEC PGM=IKJEFT01,DYNAMBR=30,REGION=4096K

//SYSEXEC DD DSN=HCLT.REXX.EXEC,DISP=SHR

//SYSTSPRT DD SYSOUT=A

//SYSTSIN DD *

% SETUP

/*

//

The following points are to be noted :

• IKJEFT01 - TSO command processor program

• SYSEXEC - System DD card to which REXX libraries are concatenated

• SYSTSPRT - Destination of the REXX output,as well the TSO command processor

Contd.….

Page 44: REXX Training

Executing REXX in Batch - JCL

• SYSTSIN - Instream card wherein TSO commands or invocation of REXX execs can be issued

• The dataset HCLT.REXX.EXEC is a PDS and has a member of the name SETUP.

• The Instream data can be used to invoke an REXX exec either implicitly or explicitly as indicated below

%SETUP >>>> Implicit

EXEC ‘HCLT.REXX.EXEC(SETUP)’ EXEC >>>> Explicit

• Any parameters to the exec can be passed as below

%SETUP ‘parm1’ ‘parm2’

Page 45: REXX Training

Executing REXX in Batch – Example to pass parm

Pass parameters form JCL to a Rexx Program

//systsin dd *

%name parm1 +

parm2

Page 46: REXX Training

Executing REXX in Batch – Invoking REXX procedure

//Exasbajb JOB ‘dddddd’,class = d,Notify=&sysuid

//REXXJCL EXEC PGM=IRXJCL,PARM=‘P0002’

//SYSPRINT DD SYSOUT=*

//STEPLIB DD DISP=SHR,DSN=XXXX.XXXX

//SYSEXEC DD DISP=SHR,DSN=XXXX.XXXX

Page 47: REXX Training

REXX-TSO Interface Samples

Page 48: REXX Training

TSO Samples - Read Routine

read_routine:

address TSO “alloc da(‘”dsnanme”’) F(indd) shr reuse”

if rc = 0 then

do

address TSO “execio * diskr indd (finis stem rec_stm.”

end

else

do

say ‘Error in allocating the file ‘dsnanme

end

Page 49: REXX Training

TSO Samples - Write Routine

write_routine:

address TSO “alloc da(‘”dsnanme”’) F(indd) shr reuse”

if rc = 0 then

do

address TSO “execio * diskw indd (finis stem rec_stm.”

end

else

do

say ‘Error in allocating the file ‘dsnanme

end

Page 50: REXX Training

TSO Samples – Validate Dataset

Validate_routine:

if sysdsn(“’”dsnname”’”) = ‘ok’ then

do

say “ present”

end

Page 51: REXX Training

TSO Samples – File Creation

Create_routine:

address tso “alloc da(‘”psfile”’) new “,

“ Lrecl(80) recfm(f b) “,

“ dsorg(ps) space(1,1) tracks”

Page 52: REXX Training

TSO Samples – File Deletion

Delete_routine:

if sysdsn(“’”psfile”’”) = ‘ok’ then

do

“delete ‘”psfile”’ “

end

Page 53: REXX Training

TSO Sample – Read PDS members

Read_pds_routine:

trap_var = outtrap(pds_stm.)

Address TSO “listds ‘”pds_name”’ mem”

if rc /= 0 then

do

say ‘listds error’

end

trap_var = outtrap(off)

do index1 = 7 to pds_stm.0

member_name = strip(pds_stm.index1)

end

Page 54: REXX Training

TSO Sample – Output

Output for listds in first six lines

EXAKRY.MCP.PILOT.JCLLIB

--RECFM-LRECL-BLKSIZE-DSORG

FB 80 27920 PO

--VOLUMES--

USR009

--MEMBERS–

PGPYD058

PGPYD059

PGPYD060

….

Page 55: REXX Training

REXX Functions

Page 56: REXX Training

REXX Functions

A function is a sequence of instructions that can receive data, process that data, and return a value. • Built-in functions

• User-written functions - Internal and External

Page 57: REXX Training

REXX Functions - ABS

• Returns the absolute value of a number

ABS(’56.7') returns the number 56.7

ABS(' -0.125') returns the number 0.125

Page 58: REXX Training

REXX Functions - ADDRESS

• Returns the current setting to which the non-REXX commands in an REXX exec is addressed to

Example

/*REXX*/

say address() /* returns TSO */

address ispexec

say address() /* returns ISPEXEC */

address isredit /* returns ISREDIT */

say address()

exit

Page 59: REXX Training

REXX Functions - CENTER

• Used to center one string within a certain length area and

pad on the left and right of the centered string with an

optional padding character

• Syntax : CENTER(string, length{,pad})

• The default padding character is spaces

Examples :

say center(‘uswest’,10,’*’)

Output:

**uswest**

Page 60: REXX Training

REXX Functions - COMPARE• Used to compare two strings and return a zero if the strings are the same ,or a non-zero number if they are not

• Non-zero number is the position of the first mismatching character found

• Syntax : COMPARE(string1,string2{,pad})

• If the optional padding character is specified,then the shorter string is padded and compared

• Examples :COMPARE('123','123') returns a 0 (exact match) COMPARE('FO?? ','FO','?') returns a 5 (1st mismatch after padding) COMPARE('abc','ak') returns a 2 (first mismatching char) COMPARE('ZZ ','ZZ','x') returns a 3 (1st mismatch found 3 chars in)COMPARE('xy ','xy',' ') returns a 0 (exact match with padding)

Page 61: REXX Training

REXX Functions - COPIES

• Used to concatenate or append a string to itself a certain

number of times

• Syntax : COPIES(string,n)

• Examples :

COPIES('Hello',4) returns 'HelloHelloHelloHello'

COPIES('Say what?',0) returns '' (null string)

Page 62: REXX Training

REXX Functions - DATATYPE• Used to determine the data type of the string passed• Syntax : DATATYPE(string{,type})

• If type is omitted,NUM is returned if the string is a valid number and CHAR is returned in all other cases• If type is specified,either TRUE(1) or FALSE(0) is returned• The valid types are as follows

A - AlphanumericN - NumericW - Whole numberL - LowercaseU - UppercaseM - Mixed case

• ExamplesDATATYPE(' 44 ') returns NUM (numeric) DATATYPE('*1**') returns CHAR (caharcter string) DATATYPE('Wally','M') returns a 1 (mixed case) DATATYPE('75.54','W') returns a 0 (not a whole number)

Page 63: REXX Training

REXX Functions - DATE• Returns the current date

• An optional character can be passed to obtain date in specific formats

• Syntax : DATE({option})

• Some of the chars that can be passed are

U returns date in USA format, 'mm/dd/yy’

J returns a Julian date in the form 'yyddd’

W returns the day of the week (e.g. 'Tuesday', 'Sunday', etc.)

• Examplessay date() /* returns 17 Dec 1999 */say date('U') /* returns 12/17/99 */say date('J') /* returns 99351 */ say date('W') /* returns Friday */

Page 64: REXX Training

REXX Functions - DELSTR• Used to delete or remove one string from within another string

• Syntax : DELSTR(string,n{,length})

• 'string' is the string from which a portion is to be deleted starting with character number 'n', where 'n' is a positive integer

• The length of the portion to be deleted is given by the optional length parameter

• When ‘n’ is greater than the length of the string no action is performed

• ExamplesDELSTR('abcde',3,2) deletes 'cd', leaving 'abe' DELSTR('zyxw',3) leaves 'zy', deleting 'xw' DELSTR('12345',6) no change, since 6 is greater than string length

Page 65: REXX Training

REXX Functions - INDEX

• Used to find the position of one character string within another character string

• Syntax : INDEX(string,substring{,start})

• 'start' is an optional starting character position for the search within ‘string’

• Examples INDEX('hello','ll') returns a 3 INDEX('say what','w ') returns a 5 INDEX('zyxwvu','vu',6) returns a 0 INDEX('zyxwvu','vu',2) returns a 5

Page 66: REXX Training

REXX Functions - LEFT

• Used to extract the leftmost characters of the string

• Syntax : LENGTH(string,length{,pad})

• If string is shorter than length,the string returned is padded with ‘pad’ char in the function call if available or with the default pad character blank.

• Examples :LEFT('Wallawalla',4) returns 'Wall' LEFT('Republicans',20,'-') returns 'Republicans---------'LEFT('Motley Crue ',8) returns 'Motley C'

Page 67: REXX Training

REXX Functions - LENGTH

• Used to return the length of the string passed to the function

• Syntax : LENGTH(string)

• Examples : LENGTH('LIFO') returns 4 LENGTH('Rubber baby buggy bumpers') returns 25 LENGTH('') returns 0 (null string)

Page 68: REXX Training

REXX Functions - MAX• Returns the maximum numeric value from a list of numeric values

• Syntax : MAX(number{,number}...)• Up to 20 numbers may be specified as arguments to MAX. • Calls to MAX can be nested if more are needed• Examples :MAX(21,22,81,67) returns 81

MAX(27.32,0.45,102.3) returns 102.3• The MIN function is similar to MAX except that it returns the

minimum value

Page 69: REXX Training

REXX Functions - POS

• Returns the position, relative to 1, of one string within another.

• Syntax : POS(substring,string{,startloc})

• A zero is returned if substring is not found within ‘string’

• Examples

POS('M','ABCDEFGHIJKLMNOPQRSTUVWXYZ') returns 13 POS('Smith','Merrill, Lynch, Pierce, Fenner, and Smith') returns 37 POS('hart','MVS is breaking my heart...',4) returns 0 (not found)

Page 70: REXX Training

REXX Functions - QUEUED• Returns the no of elements that remain on the REXX data stack

• No arguments

• If queued() returns zero,that indicates the REXX data stack is empty and the next PULL instruction will obtain input from the TSO terminal

/*REXX*/newstackpush apush bsay queued() /* returns 2 */delstackexit

Page 71: REXX Training

REXX Functions - REVERSE

• This function reverses the order of all characters in a string

• Syntax : REVERSE( string)

• Example

say reverse(‘XYZ’)

returns ‘ZYX’

Page 72: REXX Training

REXX Functions - SIGN• Used to determine the sign of a number

• Syntax : SIGN(number)

• Returns -1 if the number is negative

• Returns 0, if the nuber is zero

• Returns +1,if the number is positive

• The number is rounded to meet the current setting for NUMERIC DIGITS before the test.

• Examples : SIGN('-22.811') returns -1 SIGN(0.0) returns 0

Page 73: REXX Training

REXX Functions - STRIP• Used to remove the leading and/or trailing characters from a character string

• Syntax : STRIP(string{,{option}{,char}})

• The default char for ‘char’ is blank

• The ‘option’ can take either L or T or B and the default option is B

• Examples :

STRIP(' February 11, 1989 ') returns 'February 11, 1989'STRIP('7642.7600',T,0) returns '7642.76' STRIP('$$$$52.4',Leading,$) returns '52.4'

Page 74: REXX Training

REXX Function - SUBSTR

• Used to extract a portion of a string

• Syntax : SUBSTR(string,n{,{length}{,pad}})

• ‘length’ is the length of extracted substring

• If ‘length’ is omitted,the remainder of the string from char number ‘n’ is extracted

• The extract string is padded on the right with ‘pad’ char, if there are not enough characters in the extracted substring to reach ‘length’

• Examples :SUBSTR('Hi there',4) returns 'there' SUBSTR('MVS',1,5) returns 'MVS ' SUBSTR('December 7, 1941',6,15,'-') + 'ber 7, 1941----'

Page 75: REXX Training

REXX Function - SYMBOL• Used to determine whether a symbol is valid REXX symbol

• Syntax : SYMBOL(name)

• Returns “BAD” if the ‘name’ is not a valid REXX symbol

• If ‘name’ is name of the variable with a value assigned to it,’VAR’ is returned

• In other cases, ‘LIT’ is returned j='TSO/E Version 2.1' /* assign value to variable J */ Symbol('J') /* returns VAR since assigned */ Drop j Symbol('J') /* returns LIT after Drop */ Symbol('.variable') /* returns BAD since 1st character is a '.' */

Page 76: REXX Training

REXX Function - TIME• Returns the current time of day in a variety of different formats and can also be used to perform elapsed time calculations

• Syntax : TIME({option}) ‘L’ - hh:mm:ss:uuuuuu

Examples :TIME() returns 09:18:04 TIME('L') returns 11:00:32.672567

Page 77: REXX Training

REXX Function - USERID

• Returns the current TSO user id

• Format : USERID()

• Example

say userid() /* returns the current user id */

Page 78: REXX Training

REXX Function - WORD

• Used to extract a specific word from within a string of words

• Syntax : WORD(string,n)

• The words in the string must be separated by blanks

• ‘n’ indicates that the nth word in the string is to be extracted

• Examples :WORD(’Arise Awake and Stop not',4) /* returns ’Stop' */ test = '1 2 3 4 5 6 7 8 9' WORD(test,1) /* returns '1' */ WORD('Carolina moon, what are you doing over Gismo Beach?',10) /* returns null string */

Page 79: REXX Training

REXX Function - WORDS

• Used to determine the number of words contained within a string of words

• Syntax : WORDS(string)

• Examples :

WORDS(‘Arise, Awake and Stop not till the goal is reached’)

/* returns 10 */

WORDS('1234567890abcdefghikjlmnopqrstuvwxyz $@#!')

/* returns 2 */

Page 80: REXX Training

LISTDSI - External Function

• Returns in variables the dataset attributes of a specified dataset

•Example

/*REXX*/

X=LISTDSI(“’HCLT.PDS.COBOL’”)

IF X=0 THEN DO

SAY ‘SYSDSORG ‘ SYSDSORG

SAY ‘SYSLRECL ‘ SYSLRECL

END ELSE SAY ‘CALL UNSUCCESSFUL’

EXIT

Page 81: REXX Training

LISTDSI - External function

The following points are note-worthy

• Note two sets of quotes in the call to LISTDSI

“ - to indicate the parm is literal to REXX

‘ - to indicate the dsname is fully qualified

• The return code should always be checked after the call

• The output of the above REXX could be

SYSDSORG PO - PO- Partitioned Dataset

SYSLRECL 80 - Record length

• Totally there are 33 variables that are set as a result of the call to LISTDSI external function

Page 82: REXX Training

OUTTRAP - External Function

• Traps TSO/E command output into a stem variable

• The function call returns the name of the variable specified

• Trapping is capturing the lines of data which otherwise would have been displayed at the terminal

/*REXX*/ x=outtrap("a.") /* turns trap on. x=a. */"listds 'rhkrish.rexx.exec' members" x=outtrap("off") /* turns trap off. x=off */say 'No of lines trapped ' a.0 EXIT

Page 83: REXX Training

OUTTRAP - External function

Contd..

• The output of the exec could be this

No of lines trapped 57

• Note that the no of lines trapped is stored in A.0

• All the trapped lines from A.1 to A.n can be used

• The outtrap function can be used to trap only a certain no of lines.

OUTTRAP(“A.”,10)

Only 10 lines trapped.

Page 84: REXX Training

SYSDSN - External Function• Returns OK if the specified dataset exists; Otherwise returns appropriate error messages

• Example call

available = SYSDSN(“’HCLT.rexx.exec’”) /* available could be set to "OK" */

• The other possible error messages are as followsMEMBER SPECIFIED, BUT DATASET IS NOT PARTITIONEDMEMBER NOT FOUND DATASET NOT FOUND ERROR PROCESSING REQUESTED DATASET PROTECTED DATASET VOLUME NOT ON SYSTEM UNAVAILABLE DATASET INVALID DATASET NAME, data-set-name MISSING DATASET NAME

Page 85: REXX Training

SYSVAR - External Function• Uses specific argument values to return information about the user, terminal, language, system, exec and console session

• Example

say sysvar(sysuid)

displays the user id.

• The arguments corresponding to user information are

SYSPREF - Prefix as defined in user profile

SYSPROC - Logon procedure of current session

SYSUID - User id of current session

Page 86: REXX Training

SYSVAR - External Function• Terminal information

SYSLTERM - No of lines available on screen

SYSWTERM - Width of screen

• Exec information

SYSENV - Whether exec is running in fore or background

SYSISPF - whether ISPF is active or not

• System information

SYSRACF - Whether RACF is available

SYSNODE - Network node name

SYSTSOE - Level to TSO/E installed

Note : Only some of the variables are covered

Page 87: REXX Training

REXX TSO/E Commands

Page 88: REXX Training

REXX Command - EXECIO

• Used to perform read and write operations against a sequential dataset or a pds member

• The data is either read from the data set and placed on the data stack or into a list of variables, or written from the data stack or a list of variables into the data set

• Syntax for read operations :

EXECIO {lines ¦ *} DISKR ddname {linenum} { ( {{FINIS}} ¦ { STEM var {FINIS} } {)} }

• Syntax for write operations :

EXECIO {lines ¦ *} DISKW ddname { ( {STEM var} {FINIS} {)} }

Page 89: REXX Training

REXX Command - EXECIO• Example

/* read all lines in data set and display them */Address TSO /* pass unknowns to TSO */ Parse Arg dsn /* get data set name */ "ALLOC DD(TEMP) DA("dsn") SHR" /* allocate file */ end_of_data = 0 /* negate end of file */ Do While end_of_data = 0 'EXECIO 1 DISKR TEMP ( FINIS' /* read a record onto stack */ If RC = 2 then end_of_data = 1 Else Nop /* set end-of-file? */ Pull line /* get line off stack */ Say line /* display line */ End

Note : This example uses the original REXX data stack.

Page 90: REXX Training

REXX Command - EXECIO

/* Example 2 - copy a file into another */ Address TSO "ALLOC F(IN) DA('SYS1.PROCBLIB(ASMHCL)') SHR" "ALLOC F(OUT) DA(‘TATA001.DELETE.ME’) SHR" 'EXECIO * DISKR IN (STEM DATA. FINIS' /* copy file into stem*/ Queue /* add null line to stack */ 'EXECIO * DISKW OUT (STEM DATA. FINIS' /* copy using stem*/ "FREE F(IN,OUT)" SAY ‘No of lines in input : ‘ data.0 EXIT

Note : This example uses stem variable data to read the contents of input file.The Number of lines read will be stored in data.0.

Page 91: REXX Training

REXX Command - NEWSTACK• used to create a new data stack in the REXX environment• When this command is executed, the current data stack is saved and a new stack is created and made the current stack• When the stack is empty,the subsequent pull instruction obtains input from the TSO terminal• When the stack has data elements,the pull instruction gets the input from the top of the stack

• Example"NEWSTACK" /* creates new stack */Push tcs /* puts ‘tcs’ in top of stack */Push uswest /* puts ‘uswest’ over ‘tcs’ */ pull data /* pulls data from the top of stack */say ‘from the stack ‘ data /* displays ‘uswest’ */pull data /* pulls data from top of stack */say ‘from the stack ‘ data /* displays ‘tcs’ */pull data /* obtains input from tso terminal */"DELSTACK" /* delete stack */

Page 92: REXX Training

REXX Command - DELSTACK• used to delete the data stack that was created last in the REXX environment

• When this command is executed the most recently created stack is deleted and all elements on it are purged

• If there is any previous data stack,that is made available

• Example :“NEWSTACK” /* new stack is created */push a /* ‘a’ is stored on top */ queue b /* ‘b’ is stored at the bottom */“NEWSTACK” /* new stack is created */push c /* ‘c’ is stored on top */say queued() /* displays 1 */ “DELSTACK” /* deletes the current stack */say queued() /* displays 2 */“DELSTACK” /* deletes the stack */

Page 93: REXX Training

FILE TAILORING

Page 94: REXX Training

File Tailoring - Skeletons• Skeletons are members of a PDS that have variables and fixed text.

• The skeleton files can contain variable-length records,with a maximum record length of 255.

• Skeleton libraries are to be allocated to the application library ddname ISPSLIB

•Allocation can be done temporarily using ISPF service

address ispexec, "LIBDEF ISPSLIB DATASET ID('USAKRB.DMT.PHASE2.ISPSLIB') "

Page 95: REXX Training

File Tailoring - FTOPEN

• Allows skeleton files to be accessed from the skeleton library specified by ddname ISPSLIB

• If the output is to be saved in a PS or PDS , the particular library has to allocated to the ddname ISPFILE

ISPEXEC FTOPEN [TEMP]

•TEMP specifies whether the output is to be placed in temporary file or not

•The name of the temporary file will be stored in the profile variable ZTEMPF

Page 96: REXX Training

File Tailoring - FTINCL

• Specifies the skeleton that is to be used to produce the file tailoring output

• Command invocation format

ISPEXEC FTINCL skel-name [NOFT]

• NOFT specifies that no file tailoring is to be performed on the skeleton.So the entire skeleton will be copied to the output file exactly as is with no variable substitution or interpretation of control records

• NOFT can be used when there are no variables in the skeleton to be included

Page 97: REXX Training

File Tailoring - FTCLOSE• Used to terminate the file tailoring process and to indicate the final disposition of file tailoring output

• Command invocation format

ISPEXEC FTCLOSE [NAME(member-name)] [LIBRARY(library)] [NOREPL] • NOREPL specifies that FTCLOSE is not to overlay an existing member in the output library

• NAME specifies the name of the member in the output library that is to contain the file tailoring output

• LIBRARY specifies the name of a DD statement of the output library in which the member-name exists.

Page 98: REXX Training

File Tailoring - Example• Assume skeleton library as TATA.UTIL.SKELS

• Skeleton member JOBSTMT//&JOBNAME JOB (BILL01E0),’TATA',NOTIFY=&&SYSUID,// MSGCLASS=T,MSGLEVEL=(1,1)

• Skeleton member SYNCSORT//STEP01 EXEC PGM=SYNCSORT,REGION=400K//SORTIN DD DISP=SHR,DSN=&OLDSRC //SORTOUT DD DISP=SHR,DSN=&NEWSRC //SYSPRINT DD SYSOUT=*//SYSIN DD * SORT FIELDS=(1,10,CH,A)/*

• These are the two skeletons we will be using in the REXX exec to build the sort jcl

Page 99: REXX Training

File Tailoring - Example

/*REXX*/ "ispexec libdef ispslib dataset id(’tata.util.skels')"say 'enter the jobname :' pull jobname say 'enter old source dsn :' pull oldsrc say 'enter new source dsn :' pull newsrc "ispexec ftopen temp" "ispexec ftincl jobstmt " "ispexec ftincl syncsort " "ispexec ftclose " "ispexec vget (ztempf)" "ispexec edit dataset('"ztempf"')" exit

Page 100: REXX Training

File Tailoring - Example

• If you respond to the prompts for jobname,old dsname and new dsname with jobsort,tata.old.file and tata.new.file respectively,the tailored output will look like

//JOBSORT JOB (BILL01E0),’TATA',NOTIFY=&SYSUID,// MSGCLASS=T,MSGLEVEL=(1,1) //STEP01 EXEC PGM=SYNCSORT,REGION=400K//SORTIN DD DISP=SHR,DSN=TATA.OLD.FILE//SORTOUT DD DISP=SHR,DSN=TATA.NEW.FILE//SYSPRINT DD SYSOUT=*//SYSIN DD * SORT FIELDS=(1,10,CH,A)/*

• Note that all three variables have been substituted with appropriate values• Note the single ampersand in the NOTIFY parameter

Page 101: REXX Training

File Tailoring – Sample Skeleton //ASM EXEC PGM=IFOX00,REGION=128K, // PARM=(&ASMPARMS) //SYSIN DD DSN=&ASMIN(&MEMBER),DISP=SHR //SYSLIB DD DSN=SYS1.MACLIB,DISP=SHR )SEL &ASMMAC1 ¬= &Z // DD DSN=&ASMMAC1,DISP=SHR )SEL &ASMMAC2 ¬= &Z // DD DSN=&ASMMAC2,DISP=SHR )ENDSEL )ENDSEL //SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(5,2)) //SYSUT2 DD UNIT=SYSDA,SPACE=(CYL,(2,1)) //SYSUT3 DD UNIT=SYSDA,SPACE=(CYL,(2,1)) //SYSPRINT DD SYSOUT=(&ASMPRT) )CM IF USER SPECIFIED "GO," WRITE OUTPUT IN TEMP DATA SET )CM THEN IMBED "LINK AND GO" SKELETON )SEL &GOSTEP = YES //SYSGO DD DSN=&&&&OBJSET,UNIT=SYSDA,SPACE=(CYL,(2,1)), // DISP=(MOD,PASS) )IM LINKGO )ENDSEL )CM ELSE (NOGO), WRITE OUTPUT TO USER DATA SET )SEL &GOSTEP = NO //SYSGO DD DSN=&ASMOUT(&MEMBER),DISP=OLD )ENDSEL //*

Page 102: REXX Training

ISPF Services

Page 103: REXX Training

LMINIT – ISPF Service

• Generate data id for a dataset

• Example

Address ISPEXEC “LMINIT DATAID(DDVAR) DATASET(‘HCL.REXX.TEXT') ENQ(SHR)”

Page 104: REXX Training

LMMOVE – ISPF Service

• Used for moving member(s) from one dataset to another dataset

• Example

Address ISPEXEC “LMMOVE FROMID(from-data-id) [FROMMEM(from-member-name)] TODATAID(to-data-id) [TOMEM(to-member-name)] [REPLACE]“

Page 105: REXX Training

LMCOPY – ISPF Service

• The LMCOPY service copies members of a partitioned data set, or copies an entire sequential data set.

• Example

Address ISPEXEC “LMCOPY FROMID(from-data-id) [FROMMEM(from-member-name)] TODATAID(to-data-id) [TOMEM(to-member-name)] [REPLACE]“

Page 106: REXX Training

LMCMP – ISPF Service

• Used for compressing a dataset

• Example

Address ISPEXEC “LMCOMP DATAID(data-id)“