Restructured Exented Executor: Nagaraju Domala
Restructured Exented Executor: Nagaraju Domala
Nagaraju Domala
Day I
• Introduction to REXX
• Features of REXX
• Basic Syntax
• Program Control Flow
• Program Execution
• Lab Exercise
• Quiz
Nagaraju Domala
Introduction
What is REXX ?
Nagaraju Domala
Usage of REXX
Automating repetitive tasks
- Increases productivity
- Ex : Allocation of datasets in bulk
- Ex : Deleting 7th char in all records of a file
Nagaraju Domala
Features of REXX
Readability
Free format
Nothing to Declare
Dynamic Scoping
Natural Data Typing
System independence
Nagaraju Domala
REXX Runs Everywhere
Nagaraju Domala
Free REXX Interpreters
Regina runs across a wide variety of operating systems.
Reginald is a standard Rexx specifically enhanced and extended for Windows.
Nagaraju Domala
Character Type of REXX
A REXX instruction can be in lower case, upper case, or mixed
case
Nagaraju Domala
Format
REXX uses a free format
Nagaraju Domala
Variables
Nagaraju Domala
Variables
Nagaraju Domala
Stem Variables
Eg: test. = 10 test.1 , test.2 , test.3 etc. all will have value
of ‘10’
Equivalent to an Array
Nagaraju Domala
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
Nagaraju Domala
Expressions
Comparison
Logical and
Concatenation
Nagaraju Domala
Arithmetic Operators
Work
on valid numeric constants or on variables that represent valid
numeric constants
+ Add
- Subtract
/ Divide
Nagaraju Domala
Arithmetic Operators - Priority
Nagaraju Domala
Comparison operators
Do not return a number value
Return either a true or false response
== Strictly Equal
= Equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
\== Not strictly equal
\= Not equal
>< Greater than or less than
\< Not less than
\> Not greater than
Nagaraju Domala
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
Nagaraju Domala
Logical Operators (Cont...)
& 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
Nagaraju Domala
Concatenation operators
Nagaraju Domala
Concatenation operators (Cont...)
Nagaraju Domala
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
Nagaraju Domala
Clauses & Instructions
NULL Clauses - Clause consists of blanks and/or comments is a
null Clause
Nagaraju Domala
Clauses & 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
Nagaraju Domala
SAY
To write a line of output to the TSO terminal
SAY {expression}
Expression can be of any size and REXX will split it up according to
line-width of the terminal
Expression can contain variables, literals and functions
Example
/*REXX*/
name=‘Roosevelt’
say ‘Welcome to TSO ‘ name
exit
Output Welcome to TSO Roosevelt
Nagaraju Domala
PULL
To read the input from the TSO terminal
Syntax : PULL var1 var2 var3…
Example :
/*REXX*/
pull name
exit
The output will be
Enter your name :
Tom
Nagaraju Domala
Program Control Flow
Nagaraju Domala
Conditional instructions
Instructions
which set up at least one condition in
the form of an expression
IF/THEN/ELSE, and
SELECT/WHEN/OTHERWISE
Nagaraju Domala
IF construct
Nagaraju Domala
IF construct (Cont...)
IF expression THEN
DO
instruction
instruction
END
ELSE
DO
instruction
instruction
END
Nagaraju Domala
IF construct (Cont...)
/*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
When the input is blank or other than AM/PM , the instruction that
gets executed is NOP. Also note that the ELSE clause is not
mandatory. When the ELSE clause is removed ,the functionality of
the program will still be the same
Nagaraju Domala
SELECT construct
Nagaraju Domala
SELECT construct
/*REXX*/
Say ‘Enter 1 for salad,2 for pizza :’
pull choice
select
when choice = 1 then say ‘Here is the salad’
when choice = 2 then say ‘Here is the pizza’
otherwise say ‘You have opted nothing’
End
Nagaraju Domala
Looping instructions
Nagaraju Domala
Repetitive loops
Repeat
a set of instructions a specified
number of times
e.g. DO i = 1 to 5
SAY “Hello !”
END
Thestep can also be controlled
e.g. DO i = 1 to 10 by 2
SAY “Hello !”
END
Nagaraju Domala
Conditional 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
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
Nagaraju Domala
Repetitive loops
Nagaraju Domala
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
Nagaraju Domala
DO with 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
Syntax : LEAVE {name}
/*REXX*/
Do forever
Say ‘Enter the code :’
Pull code
If code = ‘BYE’ then Leave;
end
Exit
Nagaraju Domala
Writing, Running & Debugging REXX
Nagaraju Domala
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 */
’,but not in all cases
A simple exec (In a PDS member, MYFIRST)
/*REXX*/
SAY ‘This is first REXX exec’
EXIT
REXX is case insensitive
Nagaraju Domala
Executing a REXX exec
Explicit execution from tso ready prompt
EXEC ‘MSAT.REXX.EXEC(MYFIRST)’ EXEC
Implicit execution requires the PDS library to be concatenated
to either SYSEXEC or the SYSPROC system DDNAME’s.
ALLOC DD(SYSEXEC) DSN(‘MSAT.REXX.EXEC’) SHR REUSE
READY
%MYFIRST
Once above allocation is done, execute it by issuing the
following command at command prompt
TSO MYFIRST
Type EX alongside of a PDS Member
Nagaraju Domala
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.
Nagaraju Domala
Executing REXX in Batch
//TSOBATCH EXEC PGM=IKJEFT01,DYNAMBR=30,REGION=4096K
//SYSEXEC DD DSN=MSAT.REXX.EXEC,DISP=SHR
//SYSTSPRT DD SYSOUT=A
//SYSTSIN DD *
% SETUP
/*
//
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
Nagaraju Domala
Executing REXX in Batch
SYSTSIN - Instream card wherein TSO commands or
invocation of REXX execs can be issued
The dataset MSAT.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 ‘MSAT.REXX.EXEC(SETUP)’ EXEC
>>>> Explicit
Any parameters to the exec can be passed as below
%SETUP ‘parm1’ ‘parm2’
Nagaraju Domala
Debugging REXX Execs
Trace ?N (Normal
Nothing is traced except commands are in error
Trace ?R (Results)
All clauses are traced before execution
Trace ?I (Intermediates)
Intermediate clauses are also traced
TRACE ?C
any command that follows is traced before it is executed
then it is executed, and the return code from the command
is displayed
TRACE ?E
any host command that results in a non-zero return code is
traced after it executes
the return code from the command is displayed Nagaraju Domala