REXX Basics, Macros & Panels - Training
REXX Basics, Macros & Panels - Training
By
Karthik Shyam Manoharan
OUTLINE
REXX Basics
Introduction to REXX
Language Basics
Control Structures
Arrays
File Handling & I/O
Functions, String Manipulation
SELECT
WHEN <condition> THEN <instructions>
WHEN <condition> THEN <instructions>
OTHERWISE
<instructions>
END
REXX - Control Structures
Looping Statements
DO <variable> = <start> TO <end> [STEP] <value>
<instructions>
END
DO WHILE <condition>
<instructions>
END
DO UNTIL <condition>
<instructions>
END
DO FOREVER
<instructions>
END
REXX - Control Structures
Unconditional Control Transfer Statements
ITERATE
Transfers control to the top of the loop
LEAVE
Breaks the loop and transfers control to the next statement outside the loop
EXIT <RC>
Exits the program to the calling environment with the return code specified
CALL / RETURN
For calling subroutines within program
CALL <LABEL>
<LABEL> :
<instructions>
<instructions>
RETURN
SIGNAL <LABEL>
Transfers control to the specified label
REXX - Arrays
REXX Arrays – STEM fields
STEM basics
Length of the array is contained in <STEMNAME>.0
1 DIMENSIONAL: <STEMNAME>.<SUBSCRIPT>
2 DIMENSIONAL: <STEMNAME>.<SUBSCRIPT1>. <SUBSCRIPT2>
Example: MYARR.1 = 2, MYARR.2 = E, MYARR.3=“C”, MYARR.0 = 3
SYSUSID=USERID()
SYSDATE = DATE()
SAY “Name Please : ”
PULL NAME
DO I = 1 TO 3
SAY “Hi!!! ” || NAME || “, your id is “ || SYSUSID
END
SAY “Today’s date is: “ SYSUSID
EXIT
OUTTRAP
OUTTRAP(‘<STEM.>’)
“TSO command”
OUTTRAP(‘OFF’)
In General any TSO command can be invoked in a REXX and its results
can be captured in the program
EG: LISTD ‘<MY.PDS(MEMNAME)>’ MEMBERS
The command needs to be given inside quotes in the REXX program and its result
can be trapped using OUTTRAP
“LISTD ‘DEB6028.REXX.EXEC’ MEMBERS”
REXX – Some Commonly Used
TSO Functions
MSG(‘ON’) or MSG(‘OFF’)
LISTDSI
x = LISTDSI(work.exec)
SAY 'Function code from LISTDSI is: 'x
SAY 'The data set name is: ' sysdsname
SAY 'The device unit on which the volume resides is:' sysunit
SAY 'The record format is: ' sysrecfm
SAY 'The logical record length is: ' syslrecl
SAY 'The block size is: ' sysblksize
SAY 'The allocation in space units is: ' sysalloc
SAY 'Type of RACF protection is: ' sysracfa
REXX –File I/O Sample Program
A REXX program to read a sequential dataset
change all occurrences of strings
“XYZ” to “ABC”
“X1Y1Z1” to “A1B1C1”
“X2Y2Z2” to “A2B2C2”
ADDRESS ISPEXEC
To communicate with panel services
ADDRESS ISREDIT “<ISPF COMMAND>”
Eg: ADDRESS ISPEXEC "CONTROL ERRORS RETURN"
“ISPEXEC SETMSG MSG(ISRZ001)"
ADDRESS TSO
To communicate with TSO – By default this is set as the program is invoked from TSO
Eg: File allocation commands
““ALLOCATE DD(SYSPROC) DA(‘DEB6028.REXX.EXEC’) SHR”
REXX – Sample REXX Macro
REXX program to find the string in the current cursor position
/* REXX */
ADDRESS ISREDIT "MACRO PROCESS"
ADDRESS ISPEXEC "CONTROL ERRORS RETURN"
MSG_STATUS=MSG('OFF')
"ISREDIT RES "
"ISREDIT (CROW,CCOL) = CURSOR"
"ISREDIT (CURRLINE) = LINE .ZCSR"
PARTSTR = SUBSTR(CURRLINE,CCOL)
BLNKPOS = INDEX(PARTSTR,' ')
FINSTR = SUBSTR(PARTSTR,1,BLNKPOS)
"ISREDIT F NEXT '"FINSTR"' "
REXX – Try it again using ISREDIT
Macro
A REXX program to read a sequential dataset
change all occurrences of strings
“XYZ” to “ABC”
“X1Y1Z1” to “A1B1C1”
“X2Y2Z2” to “A2B2C2”
CODIN.TXT
Examples
)ATTR
# TYPE(TEXT) INTENS(LOW) SKIP(ON) CAPS(ON)
_ TYPE(INPUT) INTENS(LOW) COLOR(WHITE) HILITE(USCORE)
! TYPE(TEXT) INTENS(LOW) COLOR(RED)
$ TYPE(TEXT) INTENS(HI) COLOR(PINK)
REXX – BODY Section
BODY – It defines the skeleton of the panel
The special character says whether the line (or part of the line) is an output
text line or an input line
Example:
ZEDSMSG = "NO IF FILES IS INVALID"
ZEDLMSG = "NUMBER OF I/P OR O/P FILES INVALID"
ADDRESS ISPEXEC
"SETMSG MSG(ISRZ000)“
REXX – Questions?
Thank You