Академический Документы
Профессиональный Документы
Культура Документы
Saravanan Desingh
REXX
An abbreviation of IBMs Restructured EXtended eXecutor (REXX) Language, which allows system command to be used or combined in a routine.
Topics
1. REXX ENVIRONMENT
1.1
1.2
1.3
Free-Formatted Language
; Separate 2 Instructions
, Continue an Instruction
Explicit Command
TSO Environment exec DSN exec Implicit Command SYSPROC or SYSEXEC TSO member-name
Using Dynamic Typing Assigning simple variable Using Character String Expressions and Operations Using Arithmetic Expressions and Operations Using Logical Expression and Operations
Defined Dynamically
Variable Characteristics:
Length 1 to 255 characters
All Constants & Variables referred as Alphanumeric Character Strings. Character Strings - and
Concatenation - ||
=
> <
== (Identical to)
& | \ (Not)
Using string manipulation function Formatting numbers Using Arithmetic Functions Using Miscellaneous functions
LENGTH(string)
No.of characters in the string LEFT(string,no.of chars)
POS(lookfor,seach)
INDEX(search,lookfor)
searches one string (search) to see if another string (lookfor) is contained in it
FORMAT(nn,ninteger,ndecimal)
nn - Number or numeric expression to format ninterger-Number of digits or blanks to the left of the decimal point. ndecimal-Number of places to the right of the decimal point Ex: A=123.44 FORMAT(A,3,1)=123.4
TRUNC(number,numberofplaces)
Ex:
TRUNC(56.7777,1)=56.7
DATATYPE(variable) NUM
CHAR
Additional Function:
ABS(n) MAX(n1, n2, n3...)
DATE()
DATE(J) DATE(U)
2.2
2.3
2.4
Parsing Data
arr.2=Steeple-Reach Building
Initialize array:
array.=0 arr.=
single.var matrix.row.col
emprec.empno=5508
emprec.sex=M Record like structure.
Using Conditional Constructs and Compound Statements Using Looping Constructs Bypassing and Terminating Loops Branching on errors
Conditional group:
IF-THEN-ELSE Format:
IF expression THEN
statement ELSE
statement
ELSE optional
DO-END
Ex: DO
Statement1 Statement2
END
SELECT-WHEN-THEN-OTHERWISE
* OTHERWISE optional
DO-WHILE
DO-UNTIL
Format:
DO WHILE condition Stmts
END
Executes when condition is True.
Format:
DO UNTIL condition stmts
END
Executes when condition is False.
BY Clause:
Additional variations.
Ex:
DO I=1 T0 99 BY 2 SUM=SUM+I
END
I will have the values 1,3,5,99
FOR Clause:
Controls Maximum no. of Execution.
Ex:
Nested Looping:
DO
DO . END END
PULL STR
IF STR == X THEN LEAVE ELSE SAY STR END
ITERATE:
Ex: DO count = 1 TO 10 IF count = 8 THEN ITERATE ELSE SAY 'Number' count END Bypass instructions.
SIGNAL:
Ex: IF RC\=0 THEN
SIGNAL handle-error
. handle-error: .
In REXX, use a
Subroutine for a simple branch and return within a program. All main program variables are available to a subroutine.
In REXX, use a
Procedures the same way as you use a subroutine, but use it when you need a routine with its own local variables hidden from the main program.
In REXX, use a
Functions to return data to use in the main program. REXX allows functions to either access main program variables or local variables.
Main pgm,
..
CALL subrtn
EXIT
subrtn:
..
RETURN
Main pgm,
..
CALL subrtn ...
EXIT
subrtn: PROCEDURE ..
RETURN
Output is 4.
say avg
calc: PROCEDURE EXPOSE n1 n2 avg avg=(n1+n2)/2 RETURN
The ARG, PARSE UPPER ARG and PARSE ARG instruction as the first line in the PROCEDURE.
RETURN
User-defined Functions:
Like Built-in function. Substitutes Expressions.
FunctionName()
Ex:
n1=1 n2=2
ARG n1 n2
RETURN (n1+n2)/2
Format:
PULL var
or
PARSE UPPER PULL var
or
PARSE UPPER ARG var1 var2 .. Without converting to uppercase, PARSE ARG var1 var2
Ex:
PARSE VALUE hello || world, WITH var1 var2 Var1=hello Var2=world
Var2= Everybody
3.1
3.2
3.3
Access is Sequential.
PUSH:
PUSH expression
PULL:
As long as the stack contains data lines, PULL accesses the stack. When the stack is empty, PULL accesses the keyboard. PULL var QUEUE:
QUEUED():
n=QUEUED()
ALLOC allocation
Read data into a stack or an array using EXECIO with the DISKR option.
EXECIO * DISKR file(FINIS using stack EXECIO * DISKR file(STEM arr. FINIS using array
* - all lines.
FINIS- close dataset after processing
stack:
EXECIO * DISKR file(LIFO FINIS -PUSH command
- Default is FIFO.
DISKW in EXECIO
Stack:
EXECIO will continue to pull from the stack until it locates a null line.
DISKRU:
Disk read for updating.
Ex:
EXECIO 1 DISKRU file(LIFO
TRACE:
Initiate trace from REXX
TRACE C Commands
TRACE R - Results TRACE E - Errors TRACE N - Normal
Interactive Tracing:
TRACE ?option
option- C,R or E.
Whenever control transfers within a REXX program (usually due to CALL, SIGNAL, or a Function call), SIGL is set to the line number where the branch occurred.
Ex:
000003 000004 000005 000006 subrtn: 000007 000008 say This is call from line SIGL RETURN CALL subrtn EXIT
O/p:
RC (Return Code):
Ex:
EXECIO * DISKR f1(FINIS readcode=RC
SIGNAL ON ERROR:
SIGNAL ON ERROR:
Ex:
SIGNAL ON ERROR
..
ERROR:
4.1
4.2
To change the command Host Environment for all subsequent commands, use the format,
ADDRESS environment
Environments: MVS, TSO, ISPEXEC, ISREDIT, LINK, ATTACH, or NETVIEW. Ex: address MVS
Verify Environment:
Format:
SUBCOM environment
Sets RC to zero if the environment is present, else set to one.
4.2.1
TSO Commands
4.2.2
DELETE
DSAT EXEC LISTDS
Traps the output of the subsequent commands and places the trapped lines into an array
Format:
OUTTRAP(stem.,Maxnoof lines)
command Ex:
OUTTRAP(output.,5)
THE END