REXX Language Coding Techniques 20150303
REXX Language Coding Techniques 20150303
1
IBM Software
Agenda
REXX products
External environments and interfaces
Key functions and instructions – power tools
REXX data stack vs. compound variables
EXECIO and Stream I/O
Troubleshooting
Programming style and techniques
REXX Enhancements (z/OS)
Hands-on Lab Exercises (BYOC)
– Session 16474: Introduction to REXX Workshop (Part 1)
• Tuesday at10:00am
– Session 16475: Introduction to REXX Workshop (Part 2)
• Wednesday at 11:15am
REXX Libraries
The Interpreter executes (interprets) REXX code “line by line”
– Included in all z/OS and z/VM releases
A REXX library is required to execute compiled programs
– Compiled REXX is not an LE language
Two REXX library choices:
– (Runtime) Library – a priced IBM product
– Alternate library – a free IBM download
• Uses the native system’s REXX interpreter
At execution, compiled REXX will use whichever library is
available:
– (Runtime) Library
– Alternate Library
External Environments
ADDRESS TSO
– MVS
• Use to run a subset of TSO/E commands like EXECIO and MAKEBUF
• The default environment in a non-TSO/E address space
• TSO/E REXX Reference (SA22-7790)
• Example:
Address MVS “EXECIO * DISKR MYINDD (FINIS STEM MYVAR”
– ISREDIT
• Used to invoke ISPF edit macro commands like FIND and DELETE
• Only available to REXX running in an ISPF edit session
• ISPF Edit and Edit Macros (SC19-3621, SC28-1312)
• Example:
Address ISREDIT “DELETE .ZFIRST .ZLAST”
Result:
IEE114I 04.50.01 2011.173 ACTIVITY 602
JOBS M/S TS USERS SYSAS INITS ACTIVE/MAX VTAM OAS
00002 00014 00002 00032 00005 00001/00020 00010
Result:
…
bin
dev
etc
…
• Example:
rc=isfcalls(“ON”)
Address SDSF “ISFEXEC ST”
do ix = 1 to JNAME.0
if pos(“MYREXX”,JNAME.ix) = 1 then do
say “Cancelling job ID” JOBID.ix “for MYREXX”
Address SDSF “ISFACT ST TOKEN(‘”TOKEN.ix”’) PARM(NP P)”
end
end
rc=isfcalls(“OFF”)
exit
• Example:
RXSUBCOM(‘ADD’,’DSNREXX’,’DSNREXX’)
SubSys = ‘DB2PRD’
Address DSNREXX “CONNECT” SubSys
Owner = ‘PRODTBL’
RecordKey = ‘ROW2DEL’
SQL_stmt = “DELETE * FROM” owner”.MYTABLE” ,
"WHERE TBLKEY = ‘”RecordKey”’”
Address DSNREXX “EXECSQL EXECUTE IMMEDIATE” SQL_stmt
Address DSNREXX “DISCONNECT”
– RACVAR function
• Provides information from the ACEE about the running user
• Arguments: USERID, GROUPID, SECLABEL, ACEESTAT
if racvar(‘ACEESTAT’) <> ‘NO ACEE’ then
say “You are connected to group “ racvar(‘GROUPID’)”.”
– Security Server RACF Macros and Interfaces (SA22-7682)
ARG
– Retrieves the argument strings provided to a program or internal routine
• Assigns them to variables
– Short form for PARSE UPPER ARG
PULL
– Reads a string from the head of the external data queue
– Short form for PARSE UPPER PULL
Good practice to use full commands vs short forms
PARSE Templates
Simple template
– Divides the source string into blank-delimited words and assigns them to
the variables named in the template
• The last variable gets the rest of the string exactly as entered
PARSE Templates
Simple template
– A period is a placeholder in a template
• A “dummy” variable used to collect unwanted data
• Often used at the end of PARSE statement to take “the rest of the data”
• Causes the last variable to get the last word without leading and trailing blanks
PARSE Templates . . .
String pattern template
– A literal or variable string pattern indicating where the source string
should be split
string = ‘ Write the blank-delimited string ’
Literal:
parse var string var1 ‘-’ var2 .
Variable:
dlm = ‘-’
parse var string var1 (dlm) var2 .
Result (the same in both cases):
var1 -> ‘ Write the blank’
var2 -> ‘delimited’
PARSE Templates . . .
Positional pattern template
– Use numeric values to identify the character positions at which to split data in the source
string
– An absolute positional pattern is a number or a number preceded by an equal sign
----+----1----+----2----+----3----+----4----+
string = ‘Cowlishaw Mike UK ’
parse var string =1 surname =20 chrname =35 country =46 .
surname -> ‘Cowlishaw ’
chrname -> ‘Mike ’
country -> ‘UK ’
PARSE Templates . . .
Positional pattern template – removing blanks
– Specify an absolute positional pattern
– Insert periods to strip blanks
----+----1----+----2----+----3----+----4----+
string = ‘Cowlishaw Mike UK ’
parse var string =1 surname . =20 chrname . =35 country .
surname -> ‘Cowlishaw’
chrname -> ‘Mike’
country -> ‘UK’
– Warning – won’t work if any of the data has more than one “word”
– ----+----1----+----2----+----3----+----4----+
string = ‘Cowlishaw, Jr. Mike UK ’
parse var string =1 surname . =20 chrname . =35 country .
surname -> ‘Cowlishaw,’
chrname -> ‘Mike’
country -> ‘UK’
LIFO FIFO
Stack Stack
(Queue)
– Result:
elem3 ‘new top element’
1 REXX function
– QUEUED() - returns the number of elements in the stack
num_elems = QUEUED()
Notes
– When an element is removed from an empty buffer, the buffer disappears.
– To remove a buffer
• Issue DROPBUF, or
• Remove an element (via PARSE PULL) when the buffer is already empty
– The next request to remove an element will move to the next buffer (if there is one)
Data Stack
– Advantages
• Protects data in the original stack
– Never defaults back to the “previous” stack in the chain
– Must specifically delete current stack to move to previous stack
– Can easily request terminal input if also have items in the stack
> Just create a new stack with nothing on it and issue “Pull”
– Disadvantages
• Only available on z/OS
– z/VM must issue “Parse External” to request terminal input if data
is in the stack
Buffers
– Advantages
• Create a stack on top of the existing stack for new list of
items
• Use “QElem” to keep track of how many items in this buffer
– Disadvantages
• No guaranteed protection of previous stack in the chain
– If current stack is empty, will proceed to next one automatically
Stems can be used with I/O functions to read data from and write data to a
file on z/VM or data set on z/OS
– Stream I/O
– EXECIO
– PIPE
Stems can also be used with the external function OUTTRAP (z/OS) or PIPE
(z/VM) to capture output from commands
Data Stack
– Advantages
• Can be used to pass data to external routines
• Able to specify commands to be run when the EXEC ends
• Can provide response(s) to an interactive command that runs
when the EXEC ends
– Disadvantages
• Program logic required for stack management
• Processing needs 2 steps
– Take data from input source and store in stack
– Read from stack into variables
• Stack attributes and commands are OS dependent
Conclusion
– Try to use compound variables whenever appropriate
• They are simpler
Condition types:
– ERROR - error upon return (positive return code)
– FAILURE - failure upon return (negative return code)
– HALT - an external attempt was made to interrupt and end execution
– NOVALUE - attempt was made to use an uninitialized variable
– SYNTAX - language processing error found during execution
– NOTREADY - z/VM only. Error during input or output operation
– SIGL variable – line number of the clause that caused the condition
Result:
6 *-* If (A > B) | (C < 2 * D)
>V> "1"
>V> "2"
>O> "0"
>V> "3"
>L> "2"
>V> "4"
>O> "8"
>O> "1"
>O> "1"
*-* Then
7 *-* Say 'At least one expression was true.‘
>L> "At least one expression was true."
At least one expression was true.
Literals
– Important to use literals where appropriate
• For example: external commands
– Lazy programming can lead to unfortunate results
• For uninitialized variables: value=name
control errors cancel
• This usually works
– Breaks if any of the 3 words is a variable with value already assigned
• Also a performance cost for unnecessary variable lookups
(20%+ more CPU)
• Instead enclose literals in quotation marks
“CONTROL ERRORS CANCEL”
External commands
– Best practices
• Enclose in quotation marks
• Use uppercase
• Fully spell out the command
– Don’t assume any abbreviations that may not be present if the EXEC
is moved to another system
– Preface with the external environment as needed
More Details
Related Programs
Hindi
Korean
Traditional Chinese
Gracias
Russian Spanish
Thank Obrigado
English
Brazilian Portuguese
Grazie Merci
Italian
Simplified Chinese French
Tamil
Japanese Thai