Professional Documents
Culture Documents
REXX
An abbreviation of IBMs Restructured EXtended eXecutor (REXX) Language, which allows system command to be used or combined in a routine.
Topics
I REXX ENVIRONMENT II CODING PROGRAM & DATA INSTRUCTIONS III DEBUGGING & STORAGE FACILITIES IV REXX AS A COMMAND LANGUAGE
I REXX ENVIRONMENT
1 Creating a REXX program. 2 Coding Simple variables and Expressions 3 Using Built-in functions
Beginning a REXX Program and using comments Structuring a REXX Program Using Basic Terminal I/O Running a REXX Program
Comments
; Separate 2 Instructions
, Continue an Instruction
SAY
Display Text on Screen
PULL
Retrieves User Input
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
Variable Characteristics:
Length 1 to 255 characters A-Z, a-z, 0-9 !,@,#,$,?,_ Should not begin with Digits
All Constants & Variables referred as Alphanumeric Character Strings. Character Strings - and Concatenation - |
Arithmetic Operators
+,-,*,/
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)
Isolate a string within a string
POS(lookfor,seach) INDEX(search,lookfor)
searches one string (search) to see if another string (lookfor) is contained in it
b) Formatting Numbers
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
b) Formatting Numbers
FORMAT(nn,ninteger,ndecimal) Ex:
A=123.44 FORMAT(A,3,1)=123.4
b) Formatting Numbers
TRUNC(number,numberofplaces) Ex:
TRUNC(56.7777,1)=56.7
Additional Function:
ABS(n) MAX(n1, n2, n3...) MIN(n1, n2, n3.) RANDOM(low, high) SIGN(n) -1, 0 , 1
1 Using Compound variables 2 Coding Conditional and Looping Constructs 3 Modifying instructions Dynamically 4 Implementing Subroutines, Procedures, and Functions 5 Parsing Data
Stem No. of Elements Maximum Variable Name Length - 250 Characters Mixed types and Lengths Ex:
arr.1=25 arr.2=Steeple-Reach Building
Initialize array:
array.=0 arr.=
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
* OTHERWISE optional
Format:
DO WHILE condition Stmts END
Format:
DO UNTIL condition stmts END
Ex:
DO 5 say Hello END
Ex:
DO FOREVER say Hello END
Ex:
DO I=1 to 10 s=s+I END
BY Clause:
Additional variations. Ex:
DO I=1 T0 99 BY 2 SUM=SUM+I END
FOR Clause:
Controls Maximum no. of Execution. Ex:
DO I=0 BY 5 FOR 20
SAY I
END
LEAVE:
Terminating explicitly.
Ex:
DO I=1 TO 100 SUM=SUM+I LEAVE END
ITERATE:
Bypass instructions.
Ex:
DO I=1 TO 100 IF I>66 THEN ITERATE TOTAL=TOTAL+I END
d) Branching on Errors
SIGNAL: Ex:
IF RC\=0 THEN SIGNAL handle-error . handle-error: .
Using INTERPRET
Ex:
VAR= SAY 5*4 INTERPRET VAR
Defining Subroutines, Procedures and Functions Using Subroutines Using Procedures Using Functions
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.
b) Using Subroutines
Main pgm, .. CALL subrtn EXIT subrtn: .. RETURN
c) Using Procedures
Main pgm, .. CALL subrtn ... EXIT subrtn: PROCEDURE .. RETURN
c) Using Procedures
Ex:
i=4 call num say i num: PROCEDURE i=3 RETURN
Output is 4.
c) Using Procedures
EXPOSE:
To expose caller Variables.
Format:
ProcName: PROCEDURE EXPOSE arg1 arg2
c) Using Procedures
Ex:
n1=5 n2=4 avg=0 call calc say avg calc: PROCEDURE EXPOSE n1 n2 avg avg=(n1+n2)/2 RETURN
c) Using Procedures
The ARG, PARSE UPPER ARG and PARSE ARG instruction as the first line in the PROCEDURE.
c) Using Procedures
Ex:
CALL exproc name1 ecode1 exproc: PROCEDURE ARG name2 ecode2 say name2 say ecode2 RETURN
c) Using Procedures
RESULT:
Last value returned from the Procedure or Subroutine
d) Using Functions
User-defined Functions:
Like Built-in function. Substitutes Expressions. Subroutines or Procedures returns a value can be used as function
Format:
FunctionName()
d) Using Functions
Ex:
n1=1 n2=2 say average(n1 n2) average:PROCEDURE ARG n1 n2 RETURN (n1+n2)/2
5 Parsing Data
Parsing from Terminal Input and Passed Values Using Additional Parsing Instructions
1 Processing Data on a Stack 2 Manipulating Data sets 3 Debugging with REXX Facilities
Access is Sequential.
LIFO- Last In First Out FIFO- First In First Out Default is LIFO
PULL:
As long as the stack contains data lines, PULL accesses the stack. When the stack is empty, PULL accesses the keyboard. PULL var
Reading information from Data sets Writing information to Datasets Updating Data sets
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
DISKRU:
Disk read for updating.
Ex:
EXECIO 1 DISKRU file(LIFO FINIS
option- C,R or E.
SIGNAL ON ERROR:
1 Interacting with the Command Host Environment 2 Interacting with TSO/E 3 Interacting with ISPF
To change the command Host Environment for all subsequent commands, use the format,
ADDRESS environment
Environments:
MVS, TSO, ISPEXEC, ISREDIT, LINK, ATTACH, or NETVIEW.
Verify Environment: Format: SUBCOM environment Sets RC to zero if the environment is present, else set to one.
TSO Commands
Ex: OUTTRAP(output.,5)
END