You are on page 1of 123

REXX

Saravanan Desingh Sathia Kumar G

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

1 Creating a REXX program

Beginning a REXX Program and using comments Structuring a REXX Program Using Basic Terminal I/O Running a REXX Program

a) Beginning a REXX program and using comments


 Start

with Keyword REXX /* and */

 Comments

b) Structuring a REXX program

Free-Formatted Language A Space to separate the arguments Not Case-Sensitive

b) Structuring a REXX program

; Separate 2 Instructions
, Continue an Instruction

c) Basic terminal input and output instruction




SAY
Display Text on Screen

PULL
Retrieves User Input

d) How to Run a REXX program?




Explicit Command
TSO Environment
exec DSN exec

Implicit Command
SYSPROC or SYSEXEC
TSO member-name

2 Coding Simple variables and Expressions

Using Dynamic Typing Assigning simple variable Using Character String Expressions and Operations Using Arithmetic Expressions and Operations Using Logical Expression and Operations

a) Using Dynamic Typing


Implicit Defining of Variables Defined Dynamically

b) Assigning simple variables




Variable Characteristics:
Length 1 to 255 characters A-Z, a-z, 0-9 !,@,#,$,?,_ Should not begin with Digits

c) Using Character String Expressions and Operations




All Constants & Variables referred as Alphanumeric Character Strings. Character Strings - and Concatenation - |

d) Using Arithmetic Expressions and Operations




Denoted with or without Quotes


12,12.0,12.00

Arithmetic Operators
+,-,*,/

e) Using Logical Expressions and Operations


= > < == (Identical to) & | \ (Not)

3 Using Built-in functions

Using string manipulation function Formatting numbers Using Arithmetic Functions Using Miscellaneous functions

a) Using String Manipulation Functions




LENGTH(string)
No.of characters in the string

LEFT(string,no.of chars)
Isolate a string within a string

 

SUBSTR(string,startpos,no.of chars) RIGHT(string,no.of chars)

a) Using String Manipulation Functions




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

c) Using Arithmetic Functions


DATATYPE(variable)
NUM CHAR

c) Using Arithmetic Functions




Additional Function:
ABS(n) MAX(n1, n2, n3...) MIN(n1, n2, n3.) RANDOM(low, high) SIGN(n) -1, 0 , 1

d) Using Miscellaneous Function


USERID() TIME() DATE() DATE(J) DATE(U)

Format hh:mm:ss Format dd mmm yyyy Format yyddd Format mm/dd/yy

II CODING PROGRAM & DATA INSTRUCTIONS

1 Using Compound variables 2 Coding Conditional and Looping Constructs 3 Modifying instructions Dynamically 4 Implementing Subroutines, Procedures, and Functions 5 Parsing Data

1 Using Compound variables

Implementing Arrays and Records

  

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.=

Single and Multi dimension array.


Ex: single.var matrix.row.col

Compound Variables can be used as Data Structures. Ex:


emprec.empname=Bharath emprec.empno=5508 emprec.sex=M

Record like structure.

2 Coding Conditional and Looping Constructs

Using Conditional Constructs and Compound Statements Using Looping Constructs Bypassing and Terminating Loops Branching on errors

a)Using Conditional constructs and Compound statements




Conditional group:
IF-THEN-ELSE

Format:
IF expression THEN statement ELSE statement

ELSE optional

a)Using Conditional constructs and Compound statements




Grouping the statements:


DO-END Ex:
DO Statement1 Statement2 END

a)Using Conditional constructs and Compound statements




Selecting several conditions:


SELECT-WHEN-THEN-OTHERWISE

* OTHERWISE optional

b)Using Looping Constructs


 

Repeating a sequence of instructions. Conditional Looping.


DO-WHILE DO-UNTIL

b)Using Looping Constructs




Format:
DO WHILE condition Stmts END

Executes when condition is True.

b)Using Looping Constructs




Format:
DO UNTIL condition stmts END

Executes when condition is False.

b)Using Looping Constructs




Numerically Controlled Repetitive Loop:


Format:
DO nooftimes stmts END

Ex:
DO 5 say Hello END

b)Using Looping Constructs




Numerically Controlled Repetitive Loop:(Infinite Looping)


Format:
DO FOREVER stmts END

Ex:
DO FOREVER say Hello END

b)Using Looping Constructs




Numerically Controlled Repetitive Loop:


Format:
DO var = initial t0 final stmts END

Ex:
DO I=1 to 10 s=s+I END

b)Using Looping Constructs




BY Clause:
Additional variations. Ex:
DO I=1 T0 99 BY 2 SUM=SUM+I END

b)Using Looping Constructs




FOR Clause:
Controls Maximum no. of Execution. Ex:
DO I=0 BY 5 FOR 20
SAY I

END

b)Using Looping Constructs




Nested Looping: DO DO . END END

c)Bypassing and Terminating Loops




LEAVE:
Terminating explicitly.

Ex:
DO I=1 TO 100 SUM=SUM+I LEAVE END

c)Bypassing and Terminating Loops




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: .

3 Modifying instructions Dynamically

Using INTERPRET

Codes can be modified during program execution. Format:


INTERPRET statement

Statement may be any constant, variable or expression.

Ex:
VAR= SAY 5*4 INTERPRET VAR

4 Implementing Subroutines, Procedures, and Functions

Defining Subroutines, Procedures and Functions Using Subroutines Using Procedures Using Functions

a) Defining Subroutines, Procedures, and Functions




In REXX, use a Subroutine for a simple branch and return within a program. All main program variables are available to a subroutine.

a) Defining Subroutines, Procedures, and Functions




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.

a) Defining Subroutines, Procedures, and Functions




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

Argument variables can be constants, expressions or variables

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


To pass value, code


A CALL with up to 20 Arguments.

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

Ex: RETURN 10 - 10 is assigned to RESULT.

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

a) Parsing from terminal input




Format: PULL var or PARSE UPPER PULL var

a) Parsing from terminal input


PULL var1 var2 PARSE UPPER PULL var1 var2.. PARSE PULL var1 var2..

a) Parsing from passed values


 

Receiving data from the another routine Format:


ARG var1 var2.. or PARSE UPPER ARG var1 var2 ..

Without converting to uppercase, PARSE ARG var1 var2

b) Using additional Parsing Instructions




PARSE VAR varname var1 var2

PARSE VALUE expression WITH var1


var2..

b) Using additional Parsing Instructions


Ex: PARSE VALUE hello || world, WITH var1 var2 Var1=hello Var2=world

To Trap and disregard dummy words


PARSE VALUE This is a REXX program WITH var1 . . var2 . Var1=This Var2=REXX

PARSE VALUE Hi , Everybody WITH var1 , var2 Var1=Hi Var2=Everybody

III DEBUGGING & STORAGE FACILITIES

1 Processing Data on a Stack 2 Manipulating Data sets 3 Debugging with REXX Facilities

1 Processing Data on a Stack

Defining the stack

Implementing LIFO and FIFO lists with the stack

a) Defining the stack


Storage Facility in Memory for lists of Data.

Access is Sequential.

b) Implementing LIFO and FIFO lists with the stack




LIFO- Last In First Out FIFO- First In First Out Default is LIFO

b) Implementing LIFO and FIFO lists with the stack


PUSH: To implement a LIFO list on the stack, PUSH expression

b) Implementing LIFO and FIFO lists with the stack




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: To implement a FIFO list on the stack, QUEUE expression

b) Implementing LIFO and FIFO lists with the stack


QUEUED(): Built-in function used to determine the no. of items in the stack. n=QUEUED()

2 Manipulating Data sets

Reading information from Data sets Writing information to Datasets Updating Data sets

ALLOC allocation EXECIO input/output operations

a) Reading information from data sets


y

Allocate dataset to a file.


ALLOC F(file) DA(DSN) SHR REUSE file -> Logical File DSN-> Physical File

a) Reading information from data sets


y

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. y FINIS- close dataset after processing

a) Reading information from data sets


EXECIO nooflines DISKR file startlineno (FINIS
nooflines no. of lines to read. Startlineno - starting line to read.

Ex: EXECIO 10 DISKR file 100(FINIS

a) Reading information from data sets


stack: EXECIO * DISKR file(LIFO FINIS -PUSH command EXECIO * DISKR file(FIFO FINIS -QUEUE command - Default is FIFO.

b) Writing information to data sets


DISKW in EXECIO Stack: EXECIO will continue to pull from the stack until it locates a null line.

c) Updating a data sets




DISKRU:
Disk read for updating.

Ex:
EXECIO 1 DISKRU file(LIFO FINIS

3 Debugging with REXX Facilities

Tracing Program Flow

Using Special Variables

a) Tracing Program Flow


TRACE: Initiate trace from REXX
TRACE C Commands TRACE R - Results TRACE E - Errors TRACE N - Normal

a) Tracing Program Flow


Interactive Tracing:
TRACE ?option

option- C,R or E.

a) Tracing Program Flow


EXECUTIL:
Initiate trace from TSO/E EXECUTIL HI - Halt Interpretation EXECUTIL TS - Trace Start EXECUTIL TE - Trace End

b) Using Special Variables


SIGL (Signal Line):
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.

b) Using Special Variables


Ex:
000003 CALL subrtn 000004 EXIT 000005 000006 subrtn: 000007 say This is call from line SIGL 000008 RETURN O/p: This is call from line 3

b) Using Special Variables


RC (Return Code): Retains the return code of the REXX command executed last. Ex: EXECIO * DISKR f1(FINIS readcode=RC

b) Using Special Variables




SIGNAL ON ERROR:

Any subsequent nonzero RC cause control to pass to a subroutine named ERROR.

b) Using Special Variables


SIGNAL ON ERROR: Ex:
SIGNAL ON ERROR .. ERROR: Say Error no. RC occurred at line SIGL EXIT

IV REXX AS A COMMAND LANGUAGE

1 Interacting with the Command Host Environment 2 Interacting with TSO/E 3 Interacting with ISPF

1 Interacting with the Command Host Environment

Directing Commands to the Command Host Environment

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.

2 Interacting with TSO/E

TSO Commands

Using OUTTRAP to Pass Data

Commonly used TSO Commands


ALLOCATE DELETE DSAT EXEC LISTDS

How to get help from TSO Environment?. By Giving,

TSO HELP command

Using OUTTRAP to pass Data


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)

3 Interacting with ISPF

Commonly used ISPF Commands


EDIT VPUT VGET LIBDEF DISPLAY

END

You might also like