0% found this document useful (0 votes)
135 views50 pages

Restructured Exented Executor: Nagaraju Domala

The document provides a training schedule for REXX that includes an introduction to REXX, features of REXX, basic syntax, program control flow, program execution, and a lab exercise and quiz. The schedule covers these topics over 3 days, with Day I focusing on an introduction and basic concepts, Day II covering functions and syntax, and Day III including a hands-on lab and quiz.

Uploaded by

Nagface
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views50 pages

Restructured Exented Executor: Nagaraju Domala

The document provides a training schedule for REXX that includes an introduction to REXX, features of REXX, basic syntax, program control flow, program execution, and a lab exercise and quiz. The schedule covers these topics over 3 days, with Day I focusing on an introduction and basic concepts, Day II covering functions and syntax, and Day III including a hands-on lab and quiz.

Uploaded by

Nagface
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

REXX

Restructured EXented eXecutor


NAGARAJU DOMALA
Training Schedule
Day Day
I
Da
II
I y
n
F
t u III
r n F
o c i
d t
u l
i
c
o e
t
i n
o s H
n S
F a
u
e
b n
a
t r d
u o l
r u
e i
t
s
i n
S
y n g
n e P
t s
a C
a
x
o r
E
x m s
e m i
c a
u n
n
t
d g
i
o s L
n L a
L a
a b
b
b
Q Q
Q
u u u
i i i
z z
z

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 ?

 Restructured EXtended eXecutor

 Invented by Michael Cowlishaw

 REXX is a Scripting Language

 Interpreted command language

 Very useful for linking TSO, ISPF services

 Useful for developing custom-made utilities

 Powerful Parsing & Text Processing


Nagaraju Domala
Scripting Vs. Traditional Languages

 High level  Lower level


 Interpretive  Compiled
 More productive  More detail-oriented
 Varying degrees of Automatic  Minimal variable management &
variable management pre-declared variables
 Shifts burden to the machine  More programmer effort
 Acceptable execution speed  Optimize execution speed
Rexx, PHP,Perl, Python, Tcl/Tk, Ruby etc C/C++, COBOL,Java, Pascal etc

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

 Interacting with TSO/ISPF dialog manager


- to create and display custom-made panels
- can store and retrieve variables
 Creating new commands
- Like TIME command, DATE can be created

 For personal programming tasks


- to send a message to other MVS users every time you logon

Nagaraju Domala
Features of REXX

 Readability
 Free format
 Nothing to Declare
 Dynamic Scoping
 Natural Data Typing
 System independence

Nagaraju Domala
REXX Runs Everywhere

Linux all versions


Unix all versions
BSD all versions
Windows all versions
Mac OS all versions
DOS all versions
Handhelds Windows CE, Palm OS, Symbian
Embedded Embedded Linux, DOS, Windows variants
Mainframes MVS, VM, VSE , zOS, OS/400 (all versions)

Many others Amiga OS, AROS, OpenVMS, BeOS,

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.

 r4 is another standard Rexx specifically extended for Windows.


 BRexx is the fastest Rexx interpreter. It has a tiny footprint and runs on
Windows CE, as well as Windows, Unix, Linux, Mac OS X, DOS, AmigaOS, and
other systems.
 Rexx/imc is an interpreter for the Linux, Unix, and BSD platforms. It features
Unix-friendly extensions and has a track record for support spanning back a
decade.
 Rexx for Palm OS brings Rexx programming to the Palm operating system.
 Open Object Rexx is a fully object-oriented superset of classic procedural
Rexx that runs under Linux, Unix, and Windows.
 NetRexx is a �Rexx-like� language that runs in the Java environment.
NetRexx scripts use Java classes and can be used to develop applets,
applications, servlets, beans, and classes.
Nagaraju Domala
Variables and expressions

Nagaraju Domala
Character Type of REXX
A REXX instruction can be in lower case, upper case, or mixed
case

 Alphabetic characters are changed to uppercase, unless


enclosed in single or double quotation marks

 The two types of quotation marks cannot be mixed

 Ifany word in the statement is a variable, REXX substitutes the


value

Nagaraju Domala
Format
 REXX uses a free format

A 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

Nagaraju Domala
Variables

 Character or group of characters that represents a


value e.g. count = 1000

 Variable names can consist of:


A....Z / a - Zalphabetic
0....9 numbers
@ # $ ¢ ? ! . _ special characters

 If not initialized, variable has value variable name


itself

Nagaraju Domala
Variables

 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

Nagaraju Domala
Stem Variables

 A Variable that can hold multiple values

 Defined as Variable name ending with a Period eg: Var.

 Value assigned are stored in all variable instances

Eg: test. = 10 test.1 , test.2 , test.3 etc. all will have value
of ‘10’

 Highly useful in reading / writing data from / to files

 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

 Something that needs to be calculated/evaluated

 Consists of numbers, variables, or strings, and one or more operators

 Evaluated from Left to Right with usual precedence rules

 Four types of operators:


 Arithmetic

 Comparison

 Logical and
 Concatenation

Nagaraju Domala
Arithmetic 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


Nagaraju Domala
Arithmetic Operators
* Multiply

** Raise a number to a whole number power

/ Divide

% Divide and return a whole number


without a remainder

// Divide and return the remainder only

Nagaraju Domala
Arithmetic Operators - Priority

 Priority from maximum to minimum


+- Prefix

** Power (exponential)

* / % //Multiplication and division

+ - Addition and subtraction

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

 Used in complex conditional instructions

 Can act as checkpoints to screen unwanted conditions

Nagaraju Domala
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 NOT


Returns the opposite response

Nagaraju Domala
Concatenation operators

 Combine two terms into one

 Terms can be strings, variables, expressions, or constants

 Concatenation can be significant in formatting output

Nagaraju Domala
Concatenation operators (Cont...)

 blank concatenate terms, one blank in between


e.g. TRUE BLUE result is TRUE BLUE
 || concatenate terms, no blanks in between
e.g. “a”||”.b” result is a.b
 abuttal concatenate terms, no blanks in between
e.g. per_cent‘%’ if per_cent = 50, result is 50%

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

 Labels- Clause that consist of a symbol followed by a colon is a


label. Labels are used for CALL, SIGNAL instructions

 AssignmentInstructions – Clause with the form symbol=expression


are assignments

 KeywordInstructions – One or more clauses that identifies a


machine instruction

 Commands – single clauses just consists an expression

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

say ‘Enter your name :’

pull name

say ‘Good morning ‘ name

exit


The output will be
Enter your name :

Tom

Good morning 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

 Can direct the execution of an exec to one of


two choices
 IF expression
THEN instruction
ELSE instruction
 formore than one instruction for a condition,
begin the set of instructions with a DO and
end them with an END

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

 Can direct the execution to one of many choices.


 SELECT
WHEN expression THEN instruction
WHEN expression THEN instruction
:
OTHERWISE
instruction(s)
END
 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

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

 Tell the language processor to repeat a set of


instructions
A loop can repeat a specified number of times or
 Can use a condition to control repeating
 Two types of loops
Repetitive- repeat instructions a certain
number of times
Conditional - use a condition to control
repeating

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

 DOFOREVER/END - Infinite loops


EXIT when a condition is reached

 LEAVE instruction - leaves the loop


e.g. DO FOREVER
IF X = 0 THEN LEAVE

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

You might also like