0% found this document useful (0 votes)
226 views248 pages

REXX Chi PDF

Uploaded by

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

REXX Chi PDF

Uploaded by

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

第9章 系统脚本语言(REXX)

Script Language

高珍
g
gaozhen2005@gmail.com
@g
章节内容
 9.1 系统脚本语言概述  9.3 高级REXX
 9.1.1 CLIST语言简介  9.3.1 执行宿主命令
 9.1.2 REXX语言简介  9.3.2 执行JCL作业
 9.1.3 USS的SHELL简介  9.3.3 /
与ISPF/ISPF编辑器的交互接口
 9.2 REXX详解  9.3.4 与MVS控制台的交互处理
 9.2.1 REXX特性  9.3.5 与TCP/IP的交互处理
 9.2.2 REXX调用  9.3.6 与USS交互处理
 9.2.3 REXX基本语法  9.3.7 对ISPF会话的使用
 9.2.4 函数和子过程  9.3.8 对ISPF编辑宏的使用
 925
9.2.5 REXX数据解析  939
9.3.9 与其他的IBM产品
 9.2.6 程序调试  9.4 总结
参考资料

 IBM红皮书
皮书
 z/OS TSO/E REXX Reference (SA22-7790-
05)
 z/OS TSO/E REXX User’s
User s Guide (SA22
(SA22-
7791-01)
 ISPF Services Guide (SC34-4819-03)
( )
 ISPF Edit and Edit Macros (SC34-4820-03)
第一节 系统脚本语言REXX概述
本节目标

 After completing this unit, you should be able to:


 Describe where REXX came from
 Understand some of the common uses of REXX
 List the platforms on which REXX is supported
 Discuss the features and basic concepts of REXX
 Understand the methodology of this course
REXX的历史
的历史

 Designed
g by
y Mike Cowlishaw
 1979-1982, IBM Hursley Labs, UK
 Using feedback from over 300 users on VNET
 Designed to make the act of programming easier
 Intended uses:
 Personal programming
 Tailoring user commands
 Macros
 Prototyping
 Applications
 Now runs on many vendors platforms
运行平台
 All of IBM's platforms:
 VM - where REXX first appeared (1983)
 OS/2
 AIX
 VSE
 OS/390 TSO (1988)
 z/OS TSO ISPF
 Chosen as SAA Procedural Language in 1987
 Also available on many non-IBM platforms:
 Tandem,VAX,
Tandem VAX Amiga
 Several UNIX versions (including Linux)
 Windows (Object REXX from IBM)
 NetRexx
N tR
REXX特点
特点

 Easyy to learn and use


 Essentially free syntactical format
 Either interpreted or compiled
 Rich set of built-in
built in functions
 Typeless variables
 Very strong parsing
 Good debugging tools
 Interfaces with other languages
 Extendable
Uses
Us s for
o REXX on
o z/OS
/O

 Command procedures
 Personal programming
 Application initiation
 Application prototyping
 Application programming
 Common macro language for varied applications
 ISPF Edit macros, ISPF Dialogs, NetView
 CICS, DB2, QMF
 Other vendor products
Interpreted
p d versus
sus Compiled
o p d

 Interpreter:
 Translates and executes each program statement as it
runs
 Compiler:
 Translates the entire program once into machine
language
 Then could be link
link-edited
edited into load module
 Then the user runs the program
学习
学习REXX

 Lectures
L t
 Checkpoint exercises
 Labs - write programs and ask questions
 Public domain program REXXTRY
 Samples and interactive exercises
 Manuals
Concepts
o p soof REXX

 Readability
 Natural data typing
 Emphasis on symbolic manipulation
 Dealing
D li with
ith reality
lit
 Nothing
g to declare
 System independence
一个简单的REXX程序
个简单的 程序

/* REXX exec to introduce REXX */


Say "Hello! My name is REXX. What's yours?"
Parse Pull name
If name = '' Then
Say "You're not friendly"
Else
Say name "is a nice name."
Exit 0
本节总结

 Having completed this unit, you should be able to:


 Describe where REXX came from
 Understand some of the common uses of REXX
 List the platforms on which REXX is supported
 Discuss the features and basic concepts of REXX
 Understand the methodology of this course
第二节 REXX基本语法
本节目标
 After completing this unit, you should be able to:
 Execute REXX execs under TSO
 Discuss REXX variables and constants
 Understand how REXX p performs arithmetic
 Describe the REXX concatenation operators
 Use basic REXX instructions
 Learn basic REXX data parsing techniques
REXX u
under
d TSO
O
 REXX exec can be a sequential data set or a PDS member
 TSO EXEC command to invoke a REXX or CLIST program
 Three ways to use the EXEC command:
 Explicit execution:
EXEC d
dataset
t t parameters
t
 Implicit execution:
membername parameters
 Extended implicit execution:
%membername parameters
 Search includes:
 //
//SYSEXEC DD concatenation
 then//SYSPROC DD concatenation
 for the membername on the command line
注释语句

 Comments begin with /* and end with */


 Comments may appear by themselves or on a line with another
instruction
 Comments may appear inside other comments (nested)
 Examples:

1. /* REXX execs should


1 h ld bbegin
i with
ith a comment
t */
2. Say "Hello!" /* comment may follow instruction */
3. /* comment may precede instruction */ Say "Hello!"
4 /* A comment may be long
4. long, up to 250 characters
characters,
and it may span multiple lines */
5. /* Comments may /* Comments may be nested */ be
nested */
续行和缩进
 Short instructions may be separated with a semicolon (;):

a = 'Cat';b = 'Dog';c = 17

 Long instructions may be continued onto multiple lines by using a comma (,) as a
continuation character:

sentence = "The quick brown fox jumps over",


"the lazy dog."

 Indentation is supported for readability. REXX does not care about indentation:

If a = b Then
Say "a
a and b are equal.
equal "
Else
Say "a and b are not equal."
变量
 A symbol which represents some value within a program. The
value is substituted in place of the variable when the program
executes.
 A variable's value may be different each time the program runs.
The value may be changed during program execution.
 In REXX, variable names:
 May be up to 250 characters long.
 May consist of letters, numbers, and some implementation
specific
ifi special
i l characters
h t (i TSO
(in TSO: @ # $ ! ? _ . c )).
 May not begin with a number or a period.
 Are not case sensitive.
 Examples:

input
p _pparms tel@num
var1 name.a
a value$
line.1 zdate
变量
 The size of the variable value is platform dependent, often
li it d only
limited l bby th
the amountt off available
il bl memory.

 Variables do not have to be declared. REXX variables are


typeless All data is character data in REXX.
typeless. REXX

 A variable that has not been assigned a value is called an


uninitialized variable. It's value is the variable's own name
in upper case.

 Variables can be assigned in several ways:


 Parse
P iinstruction
t ti
 Value() built-in function
 Program written in another language
 Variable assignment statement
variablename = value
Literal Strings
gs

 A symbol whose value does not change


change.
 Literals are enclosed within quotation marks
 Single (') or double (") quotation marks are equivalent to REXX.
This does not mean they are the same character, though.
 Literal strings may be up to 250 characters long
 Examples:

var1 = 'This is a literal string.'


Say "Hello, World!"
Address
dd TSO
SO '
'LISTCAT'
S C '
where = Pos('B',input)
Say "Don't do that."
Sa 'Don''t do that
Say that.'
'
Hexadecimal and Binary Literals

 Hexadecimal literals consist of hex digits enclosed within


quotation
t ti marks
k ((single
i l or ddouble)
bl ) and
d ffollowed
ll dbby X ((upper or
lower case):

"28
28 f4 Ab 1C094710
1C094710"X
X
'C13487FFA3D'x

 Binary literals consist of binary digits enclosed within quotation


marks (single or double) and followed by B (upper or lower
case):

'10010010110111'b
"1100 0001 0111 1011"B

 Spaces may be added for readability.


readability They must appear on a
byte boundary in hex literals, and on a byte or nibble boundary
in binary literals.
算术运算

 REXX can do decimal arithmetic,, using


g the following
g
symbols:
** exponentiation
* multiplication
/ division
% integer division
// remainder division
+ addition
- subtraction

 REXX can do arithmetic to arbitrary precision


 Controlled
C t ll d bby th
the N
Numeric
i iinstruction
t ti
算术运算优先级规则

 REXX follows the usual rules of precedence:


p
() Parentheses
+,- Prefix operator
** Exponentiation
*,/,%,// Multiplication and division
+,- Addition and subtraction

 Examples:
Say 7 * 3 + 4 Say 2 ** 3 ** 2
Say 7 + 3 * 4 Say 2 ** (3 ** 2)
Say 7 - 3 + 4 Say -5 + 6
Say 7 + 3 - 4 Say -5 + 6 * 2
Say 3 ** 2 Say -(5 + 6) * 2
S
SAY指令
指令
 Syntax:
Say expression
where expression is any combination of REXX literals,
variables, functions, or arithmetic.
 Each Say instruction displays on a separate line
line.
 Examples:

Say "Hello, world."


Say 25 * (9 / 3)
Say "The answer is:" num1 + num2
Say
Say ''
字符串连接表达式

 REXX has very advanced string handling capabilities


 Three string concatenation operators:
' ' (blank)
|| ((double vertical bars) )
(no operator character -- abuttal)
 Also many functions can concatenate strings (later)
 Examples:

Say "Join" "these" "words"


Say "Join“
Join "these"
these "words"
words
tvar = "these"
Say "Join" tvar "words"
Say
y "Join" || tvar || "words"
Say "Join"tvar"words"
Parse指令
a se指令
 To resolve into component parts
 Syntax:
Parse source variabletemplate
where source is the input source of the data to be parsed,
and variabletemplate are the rules for parsing that data,
data
and the variables to which the data parts will be assigned.
Trace指令
ace指令

 Syntax:
y
Trace option
where option is the trace option to put into effect.

 Useful options:
 N Normal (default)
 O Off
 R Results
 I Intermediates
REXXTRY程序
程序

/* interactive REXX instruction execution */


Say "EXEC REXXTRY allows you to interactively execute"
Say "REXX instructions. Each instruction string is"
Say "executed
executed when you press ENTER
ENTER."
Say "To end, type EXIT."
Do Forever /* the EXIT instruction will terminate loop */
Say "REXXTRY:"
REXXTRY: //* prompt for the next instruction *//
Parse External @line@
Interpret @line@
End /
/* Do Forever */
/
本节总结

 Having
g completed
p this unit,, you
y should be able to:
 Execute REXX execs under TSO
 Discuss REXX variables and constants
 Understand how REXX performs arithmetic
 Describe the REXX concatenation operators
 Use basic REXX instructions
 Learn basic REXX data parsing techniques
第三节 REXX程序逻辑
本节目标

 After completing this unit, you should be able to:


 Describe the components of a REXX exec
 Understand the following features of REXX:
 Comparisons
 Logical
g expressions
p
 If-Then-Else
 Select-When-Then-Otherwise
 Looping structures
REXX术语
术语

 REXX execs consist of instructions or statements


 Each instructions is made up of zero or more clauses
 Clauses are made up of tokens
 Tokens can be:
 Symbols
 Literals
 Comments
 Numbers
 Special characters
 Operator characters
指令优先级别

 The REXX interpreter scans each instruction and


d
determines
i the
h iinstruction
i type b
based
d upon the
h ffollowing
ll i
order:
 1. Null clause
 2.
2 Label
L b l
 3. Assignment instruction
 4. REXX keyword instruction
 5. Command to host environment
比较运算

 Comparisons in REXX are sometimes called Binary Conditional


Expressions because they always have only two possible results
 In human terms we call these results True and False
 In REXX, a True condition is represented by the value 1 and a
False condition is represented by the value 0
 There are two types of comparisons in REXX:
 String comparisons
 Numeric comparisons
字符串比较运算
 Always case sensitive
 Two types of string comparisons:
 Normal: ignore leading/trailing blanks
 Strict: each character must match exactly y
 Typically string comparisons are of equality or
inequality
p
 Examples:

answer = " YES " /


/* assign variable */
/
Say answer = "YES" /* normal comparison */
Say answer = "yes" /* comparisons are */
/*
/ case sensitive */
/
Strict Comparisons
o p so s

 Doubling
g an operator
p character forces strict comparison
p
 Always character comparisons, never numeric
 Just match the bytes, one by one
 Leading/trailing blanks are included
 Example:

answer = " YES " /* assign variable */


Say
y answer == "YES" /* strict comparison
p */
Say 5 == 5.0 /* strict comparison */
数字比较运算

 A
Automatically
t ti ll performed
f d if b
both
th tterms can b
be
recognized as numbers
 Within Numeric Fuzz value (default is 0)
 Examples:

num1 = 31; num2 = 30 /* assign variables */


Say num1 = num2 /* equal? */
Say num1 \= num2 /* not equal? */
Say num1 > num2 /* greater than? */
Say num1 < num2 /* less than? */
比较运算符
 REXX supports the following comparison operator
characters:
h
= equal
\= not equal
┐= not equal
<> not equal (less than or greater than)
>< not equal (greater than or less than)
<= less than or equal to
\> less than or equal to (not greater than)
┐> less than or equal
q to (
(not g
greater than)
)
>= greater than or equal to
\< greater than or equal to (not less than)
┐< greater than or equal to (not less than)
< less than
> greater than
If-Then-Else
e se 指令
 Allows exec to take different execution paths based upon
comparison
i results
lt
 Syntax:
If comparison Then instruction1
Else instruction2
 Else is optional
 Only one instruction is allowed following Then or Else
 Example:

If var1 = var2 Then


y "The values are equal."
Say q
Else
Say "The values are not equal."
The Do-End
o dGGroup
oup

 To code more than one instruction following a Then or Else,


Else
bracket them between the Do and End instructions:
If var1 = var2 Then
Do
instruction1
instruction2
etc....
End
 The Do and End are sometimes called bracketing keywords
逻辑运算符
 Comparison results (0 for false, 1 for true) may be combined
t
together
th with
ith th
these operators
t
 These operators act upon true or false conditions to produce
final true or false results
 The operators are:
& means And
| means Or
&& means Exclusive Or
\ means Not (prefix operator)
 Examples:

var1 = 1;var2 = 0 /* assign variables */


Say var1 & var2 /* Both true? */
Say var1 | var2 /* Either one true? */
Say var1 && var2 /* Only one true? */
逻辑判断表达式
 Consist of combinations of comparisons and boolean logic
 Always have a final resulting value of 1 (true) or 0 (false)
 Used to control the flow of a program
 Examples:

var1 = 41; var2 = 1; var3 = 0


Say var1 > var2 & var3 > var2
Say var1 > var2 | var3 > var2
Say var1 > var2 && var3 < var2
Say var1 > (var2 | var3) > var2
e se (
嵌套If-Then-Else
嵌套 (1 o
of 2)
)
 There is no restriction on what instruction may follow Then or
Else
 If-Then-Else structures can be embedded
 Example:
If token1 = "CONCAT" Then
Do
..instructions..
End
Else
If token1 = "BLK" | token1= "BLOCK" Then
Do
..instructions..
End
Else
If token1 = "DATASET"
DATASET Then
Do
..instructions..
End
e se (
嵌套If-Then-Else
嵌套 (2 o
of 2)
)

 Nested Ifs can sometimes be confusing:


g
If answer = "YES" Then
If name = "FRED" Then Say "Okay, Fred."
Else Say "Okay
"Okay."
"
Else Say "Why not?"
 Use Do-End groups and indentation for clarity:
If answer = "YES" Then
If name = "FRED" Then
Say
y "Okay,
y, Fred."
Else
Say "Okay."
Else
Say "Why not?"
Select
Se ect 结构
Select-When-Then-Otherwise
Select When Then Otherwise 指令

 It is common to have multiple nested If-Then-Else statements


 Th S
The Select
l t structure
t t can replace
l multiple
lti l II-T-Es
T E
 This is the example from three pages ago, using Select:
Select
When token1 = "CONCAT" Then
Do
..instructions..
End
When token1 = "BLK" | token1= "BLOCK" Then
Do
..instructions..
End
When token1 = "DATASET" Then
Do
..instructions..
End
Otherwise
Say "Error - unrecognized token:" token1
End /* of Select */
循环
 Do instruction followed by nothing indicates a Do-End group
 Do instruction followed by other subkeywords indicates a loop
 There are five kinds of loops:
 Loop while a logical expression remains true
 Loop
L until
til a llogical
i l expression
i b
becomes ttrue
 Controlled repetitive loop (with control variable)
 Loop a specific number of times
 Loop forever (there are ways out)
Do
o While
e 循环

 Syntax:
Do While logical
expression
p
..loop instructions..
End

 Example:
var1 = 12
Do While var1 > 6
Say var1
var1 = var1 - 1
End /* Do While */
Do
o Until
U t 循环

 Syntax:
Do Until logical expression
..loop instructions..
End

 Example:
E l
var1 = 1
Do Until var1 > 6
Say var1
var1 = var1 + 1
End /* Do Until */
Controlled
o o d Repetitive
p Loop
oop
 Syntax:
Do cntlvar = init To final By incr For maxloops
where:
cntlvar is the loop control variable name
init is
i th
the iinitial
iti l value
l assigned
i d tto th
the control
t l variable
i bl
final is the final value the control variable will accept
incr is the amount by which the control variable is
incremented
maxloops is the absolute maximum number of times the loop
will execute.
 Example:
p
Do i = 1 To 100
/* these instructions will execute while
the value of the variable i changes
f
from 1 to 2 to 3 to 4 ... to 100 */
End
其他循环结构
 Loop a specific number of times:
Do 5
..instructions..
End //* Do 5 */ /
 Loop forever:
Do Forever
..instructions..
instructions
End /* Forever */
避免 GO TO
O 语句

 REXX has been designed to remove the need for a GO TO


 instruction by supplying the following keyword instructions:
 Leave
 Iterate
 Return
 Exit
 Signal
 Return and Exit will both cause immediate cessation of the
currently executing routine. Control is returned to the calling
environment.
Leave and
d Iterate
 The Leave instruction will cause REXX to terminate the
currently
tl active
ti lloop:

 The Iterate instruction will cause REXX to bypass the remaining


loop instructions and pass control to the End instruction:
嵌套循环

 Loops may be nested


 The loop control variable can be used as the name of the
loop on the End, Leave, and Iterate instructions
 Example:
本节总结
 Having completed this unit, you should be able to:
 Describe the components of a REXX exec
 Understand the following features of REXX:
 Comparisons
 Logical expressions
 If-Then-Else
 Select When Then Otherwise
Select-When-Then-Otherwise
 Looping structures
第四节 REXX函数和子过程
本节目标

 After completing
p g this unit,, you
y should be able to:
 Understand the differences between functions and
subroutines
 Discuss REXX built-in
built in functions
 Understand the differences between internal and
external routines
 Code internal
inte nal and e external
te nal functions
f nctions
 Code internal and external subroutines
函数的概念
 A program or routine that returns a value to the calling
program
 The returned value is a single string
 The returned value replaces the function call, so functions
almost never stand alone
 Syntax:
functionname(argument1,argument2,...)
 Example:
parm = "This is the parameter."
n = Words(parm)
函数的种类
 Internal
 Built-in
 External
 TSO/E / external
 Your own REXX code
 Programs in other languages
 Search order:
 Internal
 REXX Built-in
 TSO/E External
 Function Packages
 Programs in other languages
 External
E t lE
Execs and
d CLISTS
内置函数

 Probably the simplest and most useful


 Several types:
 String
g manipulation
p
 Comparison
 Formatting
 Conversion
 Binary
 Arithmetic
 Information
 Program
P di
diagnostic
ti
字符串处理
 About 30 string manipulation functions
 Defaults exist where defaults make sense
 Pad character often optional (typically defaults to blank)
 Count characters, truncate strings
 S
Searchh strings,
t i edit
dit strings
t i
 Translate strings
 Word oriented and character oriented
 Word = blank delimited text
 Parsing also does string manipulation
字符串处理函数

 These functions extract pportions of strings:


g
Substr(), Strip(), Left(), Right(), Delstr()
 These functions add to strings:
Insert() Center()
Insert(), Center(), Justify()
Justify(), Overlay()
 These functions "find" within strings:
Pos(), Lastpos(), Verify(), Abbrev()
 These functions manipulate in "words":
Word(), Wordindex(), Wordlength(), Wordpos()
Words() Delword()
Words(), Delword(), Subword()
 To get the length of a string -- Length()
 To translate a string -- Translate()
 To reverse the characters in a string -- Reverse()
Substr()
u s ()

 The Substr() function breaks an input string into parts and


returns one of the parts

 Syntax:

 input is the input string to be divided


 n is the character position where the division is to occur
 length is the number of characters to be returned
 pad is used as a fill character, if needed

 Example:
x = Substr('abcdefg',3)
x = Substr('abcdefg',3,4)
x = Substr('abcdefg',3,7,'!')
比较函数

 To test the type of data:


Datatype()
 To compare one string with another:
C
Compare()
()
格式化函数

 Center() / Centre()
 Copies()
 Format()
 Justify()
 L ft()
Left()
 Right()
 Space()
 Strip()
转换函数

 Convert data between Character,, Hex,, Decimal


 In any combination using
 C2X(), C2D(), D2C(), D2X(), X2C(), X2D()
 Convert binary - hexadecimal
 B2X(), X2B()
其他的函数

 Binary logic functions


 Bitand()
 Bitor()
 Bitxor()
 Numeric functions
 Abs(), Min(), Max(), Sign(), Trunc(), Format()
 Random()
 Digits(), Form(), Fuzz()
Informational
o at o a 函数
 General Informational functions:
 Date(), Time(), Userid()
 Sysprog information functions:
 SYSVAR(),
(), MVSVAR(),
(), SYSCPUS()
()
 Program diagnostic functions:
 Sourceline(), Errortext(), Condition()
 Terminal width:
 Linesize()
子过程
 Minor differences from functions:
 Function must return a value, subroutine may or may not
 Value returned from function replaces function call, value
returned from subroutine passed to REXX special variable
result
'result'
 Function invoked with function call -- funcname(args)
 Subroutine invoked with the Call instruction
 Call instruction syntax:
 CALL subrtn arguments
 All functions can be called as subroutines
为什么需要函数和子过程
为什么需要函数和子过程?

 Necessary for structured programming


 Avoid spaghetti-code
 Break the program up into modules
 Reuse code wherever possible
 Execute
E t th
the same code
d ffrom severall llocations
ti iin
program
 Functions and subroutines can be either internal or
external
内部子过程

 Rexx looks for internal functions or subroutines first


 Internal routine is marked by a label:
 Name followed by colon:
 Code is executed until Return keyword instruction
 Remember to isolate internal routines with a preceding
Return or Exit instruction
内部子过程举例
外部子过程

 Easy:
y place
p as members of a PDS concatenated to
//SYSEXEC or //SYSPROC
 Routine name limited to PDS member naming rules
 Return keyword instruction same as Exit
 External routines maintain separate variable pools
 Internal routines can protect variables with Procedure
keyword instruction
子过程的返回值

 Value returned from function replaces


p function call
 Value returned from subroutine stored in REXX special
variable called result
给子过程传递参数

 Up to 20 argument strings are passed to the subprocedure:


x = myrtn(argstr1,argstr2,...,argstr20)
Call myrtn argstr1,argstr2,...,argstr20

 Argument strings are received at the subprocedure with the Parse


Arg instruction:
Parse Arg g template1,
p , template2,...,template20
p , , p

 Can also use Arg() function

 Only one argument string can be passed when calling an exec as a


command
本节总结
 Having completed this unit, you should be able to:
 Understand the differences between functions and
subroutines
 Discuss REXX built-in functions
 Understand the differences between internal and
external routines
 Code internal and external functions
 Code external and external subroutines
第五节 REXX程序调试和错误处理
本节目标

 After completing this unit, you should be able to:


 Discuss program design and coding style
 Use the Trace instruction
 Use the Signal instruction
 Understand other debugging aids
 Write error-handling routines
Professionalism
o ss o s Aims
s

 Your program should:


 Be reliable, that is, it does what it is supposed to do
 Be able to cope with the unexpected
 Issue meaningful error messages to users
 Set a non
non-zero
zero return code on failure
 Be easy to maintain
Ease
s oof Maintenance
 Always include good comments
 Most execs follow a common layout:
 Documentation including change history
 Mainline routine
 Subprocedures
 Error recovery routines
 Use sensible variable names -- long(?) and descriptive
 Try to adopt a consistent design methodology
 Develop a coding style!
Signal
S g a 指令

 Causes unusual transfer of control


 Used to trap error conditions
 Destroys control structures
 Do - End,
End If If, Select
 Five signal traps:
 Error
 Failure
 Halt
 Novalue
 Syntax
Signal
g O
On Novalue
o u

 Undefined variable default value


 Huge source of errors
 Causes logic errors, incorrect program flow
 Al
Almostt every exec should
h ld iinclude
l d
Signal On Novalue
 At or near the beginning of the program
宿主命令的返回码
 Always check the return code from host commands.
 The command is useless if it fails, and by default, the
REXX exec will continue executing.
 Special (reserved) variable name,
name rc,rc contains return
code from last host command.
 Signal On Error helps as it does the check
automatically.
automatically
返回码的约定
 0 = complete,
p unambiguous
g success
 4 = very likely successful, but warning
 8 = probable failure, but the system is still working
 12 = certain failure
 16 = worse than 12
 20 = fundamental system environment error
可恢复性和完整性

 You must consider the intended user of the exec:


 Yourself
 Others in your team
 Other programmers
 End users
诊断函数
 Sourceline()
 Returns number of lines of code, or actual line of
source code
 Condition()
 Returns information depending on one of four
arguments
 Errortext()
 Returns text of REXX error message associated
with argument number
 REXX special variable sigl
 Assigned with line number where condition trap
error occurred
错误恢复处理
/* Unitialized variable used */
Novalue:
Trace N
Say "Exec VMCAT: Uninitialized variable used,",
"source line =" sigl
Say "rc =" rc
Say
y "Name of uninitialized variable:" Condition('D')
Say Sourceline(sigl)
Exit 20
Error: /* non-zero return code from the host environment */
Signal Off Error
Signal Off Novalue
Trace N
Do While Queued() \= 0
Parse Pull
End /* must clear the stack */
Say "Exec VMCAT: Host command (TSO/ISPF) failed or data format error,",
"source line =" sigl
Say "rc =" rc
Say Sourceline(sigl)
Say "ISPF
ISPF error message text (zerrlm):
(zerrlm):"
Say zerrlm
zispfrc = 20
Address ISPEXEC 'VPUT (ZISPFRC) SHARED'
Exit 20
测试
 Amount of testing depends on intended end user scale
 Start testing with less data
 Test all parts of the code
 Test recoveryy from error situations
 Force the error
 Use REXX aids to confirm the program flow
 Trace instruction
Trace
ace 指令
 REXX Trace instruction - useful options
 Trace R - "Results" - most useful
 Trace N - "Normal" - traces negative return codes
 Trace O - "Off" - turns tracing off
 Trace I - Intermediates - most information
 Other trace options:
 A, C, E, F, L, S, ?, !, +n, -n
 Trace without modifying the code:
 TSO command EXECUTIL TS - before running exec
 REXX Trace() function
 trace_actions_in_effect
trace actions in effect = Trace()
交互式调试

 Trace ?
 Pauses at each instruction:
 Press enter to continue
 type
t " " to
"=" t re-execute
t llastt clause
l
 type anything else - Like REXXTRY -
process line immediately
 Trace n - skip n pauses (n is a whole number)
Other Debug
O ug Aids
ds

 Attention mode ((PA1)) immediate commands


 HE - halt execution
 HI - halt interpretation
 TS - trace start
 TE - trace end
 HT - halt typing
 RT - resume typing
本节总结

 Having
g completed
p this unit,, you
y should be able to:
 Discuss program design and coding style
 Use the Trace instruction
 Use the Signal instruction
 Understand other debugging aids
 Write error-handling routines
第六节 高级REXX I

6.1 执行宿主命令
6.2 复合变量和数据栈
6.3 高级数据分析
本节目标

 After completing this unit


unit, you should be able to:
 Issue host commands from a REXX program
 Use advanced data manipulation instructions
 Understand parsing
执行宿主命令

 Host command
 Host command environment
 Expression
 F ilit tto switch
Facility it h environments
i t
宿主命令环境
 TSO
 ISPEXEC
 ISREDIT
 CONSOLE
 MVS
 LINK/ATTACH
 APPCMVS
 Can come with a product
 Can write your own
TSO命令环境

 TSO commands
 From TSO Reference manual
 From REXX/MVS Reference manual
 IDCAMS commands
 RACF commands
 RMM (sub)commands
 HSM commands
 IPCS (sub)commands
 TCP/IP commands
 Start ISPF command
 Other products commands
 User written tools and programs
 CLISTs and REXX execs
How to Create TSO Commands

 REXX execs in //SYSEXEC DD concatenation


 TSO CLISTs in //SYSPROC DD
 TSO programs loaded by MVS
 Buy a product
环境的转换

 ADDRESS keyword instruction


 ADDRESS env command
 ADDRESS env
 ADDRESS() function to query environment
执行宿主命令

 Code your command as a REXX expression


"alloc dd(ddname) dsn(dataset.name) shr“

 REXX expressions can contain variables


"alloc dd("ddname") dsn("dsn") shr“

 For example:
If ddname = "SYSUT1" and dsn = "INPUT.DATA" and running
under userid DEES525 then:
"alloc dd("ddname") dsn(" userid() || "." ||dsn ") shr"
will produce
alloc dd(SYSUT1) dsn( DEES525.input.data ) shr
Note the imbedded blanks that are allowed by TSO
检查返回码

 **** Check RC of Host Commands ****


REXX中的数据处理
中的数据处理

 Compound
p variables
 Arrays
 OUTTRAP
 Data stack
 Reading and writing datasets
复合变量
 Compound variable = stem.tail
 Where
 stem. corresponds to the array name
 tail corresponds to the index
 It is the p
period ... that matters
 numeric tail > an array
 stem. = default initial value for all
 Variable substitution on the tail
 Can have multiple tails
/* simple example of compound variables */
month. = "no such month" /* initialize month array */
month.1 = "January"
month.2 = "February"
month.3 = "March"
say month.1 January
say month.2 February
say month.99 no such month
say month.march no such month
循环语句中的复合变量

 Tail will be the loop control variable


 do i = 1 to 5
 say leadin.i
 end i
 Note how tail "i" gets value substituted
 You do not predefine the size of the array, the limit is
your virtual address space
y p
 Negative values and zero are allowed
复合变量的使用

 Arrays
 do i = 1 to 999
 say array_row.i
 end i
 Access information by key (tail)
 Output from
 Subroutine
 OUTTRAP
 EXECIO
 SYMBOL("stem.tail")
SYMBOL( stem.tail ) tells you if exists
Tails
s as
s Indexes
d s
 Tail does not have to be numeric
 Lik the
Like th index
i d off a VSAM KSDS
 Clever ways to store and access data
 Potential for imaginative programming
 Example:
 population.Germany = 81000000
 population.France = 58000000
 population.Italy = 58000000
 locale.Germany
l l = "De_DE.IBM-1047"
1047
 localemodule.France = "EDC$FFEY"
 if symbol("localemodule."country) \= "VAR" then
 Say
y locale for this country
y not available
SYMBOL()
S O () 函数

 state
t t = SYMBOL(
SYMBOL(name))
 Pass to SYMBOL() the name of what might be a
variable(compound or not)
 Returns:
 BAD Name is not a valid symbol
 LIT Literal, or unassigned variable
 VAR Variable has value assigned
 Remember that REXX does variable substitution on the
pa amete
parameter
OU
OUTTRAP

 Trap
p TSO command outputp > compound
p variables
 You choose the stem: for example, using LINE. (below)
 Usually regarded as a function
 CALL OUTTRAP "LINE
"LINE.""
 "TSO command"
 CALL OUTTRAP "OFF"
OU
OUTTRAP的使用
的使用
 Turn trapping on, issue command, turn off
 Then you have the following variables:
 line.0 - "zero"th variable = number of elements/variables
in the
 array
 line.1 - contains the first line
 line.2 - contains the second line ............
 Example:
 call outtrap "line."
 "lista status" /* TSO command to list allocations
*/
 call outtrap "off"
 do i=1 to line.0; say line.i; end i
OU
OUTTRAP什么时候起作用?
什么时候起作用

 Almost all the time


time, but not quite:
 TSO command must be coded correctly
 PUTLINE, not TPUT or WTO
 W k
Works:
 LISTALC, LISTCAT (& all IDCAMS)
 RACF, RMM
 REXX SAY instruction in another exec (tso/call)
 Does not work:
 HSM,, OUTPUT
 REXX messages, REXX TRACE, SAY (thisexec)
ata Stac
数据栈(Data
数据栈( Stack)

使用数据栈

 Three basic instructions


 PUSH - put one item of data on top of stack
 QUEUE - put item on bottom of stack
 PULL - remove item from top of stack
数据栈为空的情况
What If You Want to Request Information from
Your User while Using the Data Stack?
What If You Exit Your Exec with Elements in
the Data Stack?
数据栈的使用

 Communication with other programs


 EXECIO
 As an alternative to parameters
 Subcommands of TSO commands
 FTP
 DSN
 Responses to commands
 RECEIVE
 Remote COPY TSO Commands
 Data storage
 Executing commands after exec ends
高级栈命令

 Create buffer - MAKEBUF


 Drop buffer - DROPBUF
 Protecting the stack - NEWSTACK
 Deleting
D l ti th
the stack
t k - DELSTACK
Stack Extensions
so s
 These functions are not part of OS/390 TSO REXX, but
come with
i h other
h products
d
 PUBSTACK()
 PULL()
 PUSH()
 QUEUE()
 QUEUES()
Q ()
 SHOVE()
 SORT()
 STACKINF()
 SWAPSTAK()
 TUG()
 WAIT()
 YANK()
EXECIO
O((1 o
of 2)
)
 Dataset (DD name) input/output
 Sequential dataset
 Usually read/write the whole dataset
 Can also do one record or any
y number of records
 Can append records to the end of a dataset
 Can update a record
 Compound variables/data stack
EXECIO
O((2 o
of 2)
)

 "EXECIO
EXECIO * DISKR SYSUT1
SYSUT1"
 "EXECIO * DISKR" ddname "(STEM LINE."
 'EXECIO 1 DISKW FOGGY ((STEM record.'
 'EXECIO 0 DISKW FOGGY (FINIS'
 'EXECIO 0 DISKW FOGGY (OPEN FINIS'
Other Features
O u so of EXECIO
O

 Read in reverse order


 Skip over records
 Start at the end, then add records
 FINALLY - remember to check the return code
Parsing
s g

 What is parsing?
 Sources of data
 Structure of the templates
Parsing
s g

 Separate data into variables


 According to rules in a template
 ARG keyword instruction
 PULL k
keyword
d instruction
i t ti
 PARSE keyword
y instruction
模版
模版

 Model specifying how to split string


 List of variable names - blank delimited
 PARSE VAR LIST A B C D
 String pattern - match splits the data
 Positional pattern - data split by column
Parsing模版
a s g模版

 One or many variables


 Period (.) used to discard data
placeholder
 Literal pattern to align with data
 Numbers to fix positions in data
 + - number for relative position in data
 Patterns
Patte ns can be in variables
a iables
Parsing举例
a s g举例

 Parse upper arg parm1 parm2 parm3 .


 Parse var fulllist item "," fulllist
 Parse upper arg command "("
parameters
Parsing
a s g 举例
 例1
 Foods = "avocado broccoli caviar duck egg filo"
 Parse var foods a b c d e f
 Parse var foods a b c
 Parse var foods a b c .
 Parse var foods a b c "ccoli" d e f
 Parse var foods a b 10 c d "k" e
 例2
 Command = "vsamio 5 diskr csi (key=14"
 Parse var command parms "(" options
 Parse var options optionname "=" optvalue
 Parse var command parms "(" optionname "="
optvalue
 Parse value date("E")
( ) with day
y '/'
/ month '/'
/ y
year
Parsing Column Dependent Data

 Parsing
g templates
p work well with data in
columns
 Data from COBOL programs
 IDCAMS DCOLLECT output
 RACF database unload utility output
 Parse pull 5 dcurctyp +1 . //* record type */,
/,
 13 dcutime +4 /* smf time */,
 17 dcudate +4 . /* smf date */,
 25 dcddsnam +44 . /* dataset name */
本节总结

 Having
g completed
p this unit,, you
y should be able to:
 Issue host commands from a REXX program
 Use advanced data manipulation instructions
 Understand parsing
第七节 高级REXX II

7.1 REXX与ISPF及ISPF编辑器的接口
7.2 REXX与MVS控制台的交互处理
73
7.3 REXX与MVS宿主命令环境
7.4 REXX与其他主机产品的交互
本节目标

 After completing this unit, you should be able


to examine:
 The non-TSO REXX host environments
 Which IBM OS/390 products work with
REXX
其他的宿主命令环境

 ISPEXEC
 ISREDIT
 CONSOLE
 LU62,
LU62 CPICOMM
CPICOMM, APPCMVS
 MVS,, LINK,, ATTACH (7)
( )
ISPEXEC
S C 宿主命令环境
 Application Programming Interface (API) to the services of
ISPF
 Approximately 100 services to:
 Display panels, pop-ups
 Manipulate datasets and member lists
 Similar to ISPF options 3.4, 3.3 and 3.2
 Table services
 Variables
 File tailoring
ISREDIT宿主命令环境
S 宿主命令环境
 API to the services of the ISPF Editor
 Approximately 100 services to do everything the ISPF Editor
can do
 Find, change
 Insert data
 Move lines
 Shift data
 Sort data
 Submit it jobs
CO SO 宿主命令环境
CONSOLE宿主命令环境
 Provides the ability to issue MVS operator (console)
commands,
d and d gett bbackk the
th commandd responses
 MVS commands including:
 DISPLAY commands, for example, D A,L
 CANCEL
 FORCE
 MODIFY
 SET,
SET VARY
 START, STOP
MVS宿主命令环境

 Subset of TSO host command environment


 Available in all MVS address spaces
 Do not need PGM=IKJEFT01
正在运行程序的宿主命令环境

 LINK - three varieties


 LINK, LINKMVS, LINKPGM
 ATTACH - three varieties
 ATTACH, , ATTCHMVS, , ATTCHPGM
 Six host command environments
 All run programs (command = program name, loaded
y standard MVS search order))
by
 ATTACH - creates new task control block (TCB)
 Parameter list
LINK,, ATTACH参数
C 参数

 R0 points to REXX environment block


 Three different ways to specify parameters
 LINK / ATTACH:
 String copied from command to parameter area
 Nonstandard parameter list format
 LINKMVS / ATTCHMVS
 Parms are REXX variables, can be updated
 Standard MVS parameter list: as in JCL EXEC
PARM
 LINKPGM / ATTCHPGM
 Parms are REXX variables, can be updated
 Nonstandard parameter list format
LINKMVS

 Conclusion: LINKMVS is very useful


 Allows you to convert:
//STEP1 EXEC
PGM=DFSORT PARM='SKIPREC=20'
PGM=DFSORT,PARM='SKIPREC=20'
 Beware of converting JCL to REXX
REXX 和其他的IBM产品

 NetView
 CICS
 IMS
 DB2
 QMF
Q
 REXX compiler
 Pipes
REXX和NetView的交互
和 et e 的交互

 NetView CLISTs replace


p with REXX
 Many specific features:
 NETVIEW host command environment
 Message processing
 Global variables
 Dataset access
 Operator commands and responses
 User commands to control PULL
REXX 和 CICS 事务服务器的交互

 SH21-0482 REXX for CICS/ESA


/ Guide and Reference
 EXEC CICS commands
 DB2 commands, SQL statements
 CEDA and CEMT utilities
CICS Addressing Environments

 REXXCICS Default
 CICS CICS commands (for example: SEND, RECEIVE)
 EXECDB2 DB2 commands (DISPLAY)
 EXECSQL SQL statements (SELECT) to the CICS/DB2
interface
 EDITSVR Edit session
 FLSTSVR y
Commands for the File List Utility
 RFS Commands for the REXX File System
 RLS Commands for the REXX List System.
CICS Features
u s

 Native CICS text editor for REXX programs


 CEDA and CEMT command output placed into a REXX variable
 Integrated client/server support
 Command support
REXX和IMS
和 S

 Complements
C l t th
the IMS utility
tilit
 Similar function to COBOL programs
 PSB defined as Assembler or COBOL
 The following example puts the segment into the variable
called Part_Segment:
 PartNum = "250239"
250239
 DB = "DBPCB01"
 SSA = 'PARTROOT(PARTKEY =
'||L ft('02'||P tN
'||Left('02'||PartNum,17)||')'
17)||')'
 Address REXXTDLI "GU DB Part_Segment SSA"
REXX Interface Support
uppo

 The following
g functions are pprovided:
 Call tracing of DL/I calls, status, and
parameters
 Inquiry of last DL/I call
 Extensive data mapping
 PCB specification by name or offset
 Obtaining and releasing storage
 Messaging through WTO, WTP, WTL, and
WTOR
REXX 环境

 Current environments:
 MVS
 Not available:
 TSO
 ISPEXEC
 ISREDIT
 New environments:
 REXXTDLI
 REXXIMS
REXX 编译器
 Compiler for SAA REXX/370, 5695-013
 Library for SAA REXX/370, 5695-014
 CEXEC or load modules
 Improved
p p
performance and reliability
y
 Syntax check of all source
 Code hidden from users
 SH19-8160
SH19 8160 IBM Compiler and Library for SAA REXX/370
User's Guide and Reference
编译器的输出

 Options for code output


 CEXEC - compiled, but kept with the source
 OBJECT - object modules for linking
 DLINK - to complete the load modules
 Listing
 Cross Reference listing
XREF Listing
Can You Spot the Errors?

|...+....1....+....2....+....3....+....4....+....5....+....6
----- Simple Variables -----
DELIBERATENOVALUE SIMP VAR 66
DIGITS SIMP VAR 7(s) 11 11(s) 15 21 30
ERROR SIMP VAR 66
FACTORIAL SIMP VAR 34(s) 38(s) 38 41 42
FIRST SIMP VAR 7(s) 8 8(s) 12 16 16(s) 16 18 39
HERE SIMP VAR 66
I SIMP VAR 37(s) 38 39 41 48
LAST SIMP VAR 7(s) 9 9(s) 13 16 19 37
LINE SIMP VAR 44(s) 45
OVER_LINES SIMP VAR 43(s) 46
PARM_WITH_PROBLEM SIMP VAR 62(s) 63 64 65
PARSENUMERIC SIMP VAR 31(s) 32
PARSESOURCE SIMP VAR 28(s) 29
PARSEVERSION SIMP VAR 22(s) 23 27
REQUESTED SIMP VAR 66
编译方法

 Online by command: REXXC


 ISPF panels
 Batch job
Control
o o Directives
s

 %COPYRIGHT
 %INCLUDE
 %PAGE
 Placed inside comments
解释和编译的区别
 Hardly any problems
 SOURCELINE() - use option SLINE
 TRACE - use option TRACE
 "PARSE VERSION" can be used to detect compiled/interpreted
 P f
Performance testing:
t ti
 SYSVAR("SYSCPU")
 SYSVAR("SYSSRV")
SmartBatch

 IBM SmartBatch for OS/390


/ ((5655-A17)) Version 1.2
 IBM BatchPipes/MVS (5655-065)
 BatchPipes - dramatically shorten elapsed time of jobs
Pipelines
p s

 Pipes developed in UNIX


 CMS Pipelines developed by John Hartmann
 OS/390: BatchPipeWorks of SmartBatch
BatchPipeWorks
p o s
 BatchPipeWorks - over 100 commands, called stage
commandsd
 Conceptual extension to REXX coding
BatchPipeWorks Stage Commands

 Select records based on certain criteria


 Reformat, combine, or change the contents of records
 Change the data flow within a job
 Make multiple copies of records
 Create reusable REXX programs that alter the contents
of records
 Retrieve/write data from/to locations such as datasets,
REXX variables, or terminal.
BatchPipeWorks
p o s

 Stage
g commands are combined into a ppipeline
p
 Pipelines usually included in REXX
 New stage commands can be written using
REXX
BatchPipeWorks Stage Commands总结

 The followinggp
pages
g contain a summary y of
BatchPipeWorks Stage Commands
 A complete description and advice on use, can be found
in the reference manual and user's guide.
g
本节总结

 Having completed this unit,


unit you should be able
to examine:
 The non-TSO
non TSO REXX host environments
en i onments
 Which IBM OS/390 products work with REXX
第八节 高级REXX III

8.1 REXX执行JCL作业
8.2 REXX程序与其他语言程序的交互
8 3 REXX与TCP/IP的交互处理
8.3
8.4 REXX与USS交互处理
本节目标
 After completing this unit, you should be able to:
 Customize the logon process and ISPF for REXX
 Interface REXX programs with programs written in
other languages
 Use REXX with TCP/IP
 REXX and UNIX Services
More
o about
ou Rexx under
u d TSO
O

 Customizing the logon process


 Launching ISPF applications
 RACF
 IPCS
 IDCAMS
 DCOLLECT
 HSM
 Compared to CLIST
 JCL
客户化登陆过程

 Exec executed at logon:


g
 PGM=IKJEFT01,PARM=%initexec (TSO
procedure JCL)
 "COMMAND" data entry field on logon
panel
 Tailor allocations
 Initialize environment
 Start ISPF
 Build
B ild ISPF initial
i iti l profile
fil if necessary
常用的 SO命令
常用的TSO命令

 ALLOCATE,, FREE,
, LISTALC
 PROFILE WTPMSG MSGID PREFIX
 TIME, SEND, TRANSMIT, RENAME
 CALL, TSOLIB
 EXEC
 EXECUTIL
 PRINTDS, SMCOPY
 Reference manual for these commands
 TSO/E Command Reference
 HELP command for online information
启动 S
启动ISPF 应用程序

 Selection panel exec to launch application


 Or
 ISPF command to launch application
 Major use of REXX
 LIBDEF and ALTLIB provided to help
 Need to learn more about ISPF, and so forth
ISPF Allocations
o o s

 ISPF applications
pp may
y require
q the following
g allocations:
 Profile ISPPROF
 Panels ISPPLIB
 Messages ISPMLIB
 Tables, input ISPTLIB
 Tables, output ISPTABL
 Skeletons ISPSLIB
 File tailoring output ISPFILE
 User link libraries ISPLLIB
 Images ISPILIB
 REXX Execs SYSEXEC
 CLISTs SYSPROC
SYSEXEC & SYSPROC

DDLIST to see the ISPF Allocations

Z5RES1 SHR,KEEP > SYSEXEC ISP.SISPEXEC


Z5RES2 SHR,KEEP > EUV.SEUVEXEC
Z5RES1 SHR,KEEP > SYS1.SBPXEXEC
Z5RES1 SHR,KEEP > CSQ531.SCSQEXEC
Z5RES2 SHR,KEEP > IOE.SIOEEXEC
Z5RES2 SHR,KEEP > ASU.SASUEXEC
Z5DB21 SHR,KEEP > QMF710.SDSQEXCE
Z5RES2 SHR,KEEP > FAN140.SEAGCMD
Z5RES2 SHR,KEEP > EOY.SEOYCLIB
ISPF
S LIBDEF 服务
 Dynamic definition of ISPF libraries
 Address ispexec
 "LIBDEF ISPPLIB DATASET ID(dataset.name)
STACK"
 Similar for ISPSLIB, ISPMLIB, ISPTLIB, ISPTABL,
ISPFILE, ISPLLIB
 Not DD names, but keywords
 Have to remove it after the application ends:
 "LIBDEF ISPPLIB"
 "LIBDEF ISPMLIB" /* one for each */
 Only for ISPF libraries -- not REXX execs
TSO
SO ALTLIB 命令

 Before starting the application


 "ALTLIB ACTIVATE APPLICATION(EXEC)
 DATASET('dataset.name')"
 After it ends:
 "ALTLIB DEACTIVATE APPLICATION(EXEC)"
如何启动ISPF程序?

 ISPF SELECT service

 Address ispexec
 "SELECT CMD(rexxexec parms) NEWAPPL(appl)
PASSLIB"
使用REXX e
使用 exec启动ISPF程序
ec启动 S 程序
 ALTLIB for the REXX exec library
 LIBDEF for each ISPF library (as necessary)
 Select service
 Remove LIBDEFs
 Remove ALTLIB
 EXIT
 Error recovery labels and code
ALTLIB DISPLAY和ISPLIBD

 Commands you enter on ISPF command line:


 TSO ALTLIB DISPLAY
 ISPLIBD
REXX和RACF
和 C
 RACF commands are all TSO commands, and OUTTRAP works
 Construct the commands with REXX
 Trap and analyse the output
REXX和IPCS
和 CS

 IPCS has support


pp for REXX
 **** could expand to a whole lecture, using the article
by Tom Bryant, with acknowledgement and permission.
CBT file 184,, plus
p manyy examples.
p
REXX和IDCAMS
和 C S
 IDCAMS commands are TSO commands
 Construct the commands with Rexx
 Trap the output with OUTTRAP
 Reformat and display
p y the output,
p , or perform
p further
processing
 Construct commands in JCL and submit job
 Process output
p of commands using: g
 EXECIO
 Parsing, string handling
 Compound variables, ISPF tables
REXX和IDCAMS DCOLLECT

 DCOLLECT produces formatted data about the IO


configuration:
fi i
 Dataset lists
 Volume lists
 SMS statistics
REXX和DFSMShsm
和 S S s

 C
Can construct
t t th
the commands
d
 Cannot trap the output: OUTTRAP does not work on HSM
commands
 Can process HSM reports with Rexx
 DCOLLECT provides HSM data
REXX和DFSMSrmm
和 S S
 Full support
 Construct commands
 Do not need to trap the output: results come back in
variables
 SYSAUTH EDGDATE = "E"
SYSAUTH.EDGDATE E
 /* tell RMM to use variables */
REXX和CLIST的对比
和C S 的对比

 CLIST predated REXX


 REXX does everything that CLISTs do
 Compatibility requires continued support
 IBM does not recommend conversion
 But you might want to get rid of them
 REXX is much more reliable and easier to read and maintain
 REXX
 All MVS address spaces
 Variable pool for each program
 I/O - any characters
 Cross platform and consistent syntax
 CLIST
 Only y TSO address space
p
 Multiple variable pools, some shared
 I/O - only text
 Unique and clumsy syntax
But
u CLIST do
does
s Have

 WRITENR
 Darsing and verification of parameters
 Global variables
REXX提交JCL作业
提交JC 作业
 TSO SUBMIT command
 Editor SUBMIT command
 EXECIO to internal reader
 FTP to another system
 C
Console
l command d tto submit
b it via
i start
t t
 Other products have submit feature
 Pass your constructed job to the ISPF Editor and let the user
submit it
it.
REXX创建JCL作业
创建JC 作业

 Obvious method:
 Construct JCL lines on data stack, or in REXX
variables
 EXECIO to temporary dataset or internal
reader (INTRDR)
 TSO SUBMIT command on temp dataset
 Better method:
 Use ISPF File Tailoring Services
REXX替换JCL作业
替换JC 作业

 Possible, but not recommended


 ADDRESS LINKMVS "pgmname parmvariable"
 Problems:
 Allocations, especially recovery
 Operations support
 Change control
REXX in Batch
 REXX in batch is just TSO in background
//TSO EXEC PGM=IKJEFT1A,
// DYNAMNBR=20,PARM=execname
//SYSEXEC DD DISP=SHR,DSN=userid.REXX.EXEC
// ,
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSTSIN DD *
execname
REXX 和其他编程语言

 External functions and subroutines


 Function packages
 Variable access
 Your own host command environment
 Invoke REXX from program
 Access to the data stack
 TSO programs
 Coexistence with TSO CLISTs
外部函数和子过程

 Can use:
 Assembler, COBOL, PL/1, C, FORTRAN
 Must support 31-bit addressing
 Load
L d module
d l in
i standard
t d d MVS searchh order
d
 Interfacing with REXX execs:
 On entry:
 Environment Block
 External Function Parameter List
 Before exit your program must:
 R15 = 0
 Result put in Evaluation Block
 Many Assembler samples on the Web
函数包

 Performance feature for loadingg of frequently


q y
used functions
 Function Package directories are searched
before other load libraries
 Mechanism for grouping related functions
 For example,
p those of a product
p
变量的访问
 Programs in other languages can access the REXX
variable
i bl pool(s)
l( )
 IRXEXCOM - variable access routine
 IKJCT441 - for REXX and CLIST variables
 Sample program REXXDUMP
 Dumps all of the variables from a current running
exec
 Sample COBOL program
宿主命令环境

 IRXSUBCM - update the Host Command


Environment Table
 Add, , delete,, q
query y or update
p
 Install your own (or a third-party product's)
host command environment dynamically
从其他程序中调用
从其他程序中调用REXX

 Program
g in another language
g g can invoke REXX
 Gives access to parsing from other
language
 Exec can be declared in the program
 Tighter change control
 IRXEXEC - Exec processing routine
 IRXRLT - get result routine
数据栈的访问

 Other languages can access REXX data stack


 Use data stack to pass data between languages
 IRXSTK - data stack routine
TSO
SO 编程

 How to write TSO command processor


 Whole range of services available
 Process parameter lists
 Communicate with terminal
SO C
和TSO
和 CLISTs并存
S s并存

 Applications
pp can have a mixture of REXX execs and
TSO CLISTs, even in the same PDS
 Assist with conversion from CLIST to REXX
 If CLISTs are performing the required function,
function there
is no need to convert
REXX和TCP/IP
和 C /

 Netstat
 FTP
 Socket programming
NETSTAT

 TSO command for administration of TCP/IP on


OS/390
 Parameter "STACK" causes outputp to ggo to REXX
data stack
 Headings not included - better than OUTTRAP
 Sample program ZNETSTAT
FTP
 File Transfer Protocol
 Datasets, HFS files, batch jobs, spool, DB2
 REXX can construct TSO FTP command
 FTP commands are "subcommands"
 Alt
Alternatives:
ti
 //INPUT DD - dataset input of commands
 Use data stack as command input to FTP
Socket
Soc et 编程

 BSD UNIX
 Server
 Client
 Socket
S k t API
 REXX can participate!
p p
SOCKET()
O ()

 result = SOCKET(function, other parms)


 Rexx rc not relevant
 Result is a string containing:
 Real return code
 Data or error message
Socket
o API

 Process socket sets


 Initialize, change, and close sockets
 Exchange data for sockets
 Resolve names for sockets
 Manage configurations, options, and modes for sockets
Connection-Oriented Sockets
Client and Server Communication
Sample
p Program
og

 TCPCLT - client sample program


 TCPSRV - server sample program
 TCPSRVJ - batch job for the server
 S
Server waits
it ffor client
li t tto send
d one
message, then the server terminates.
 //TCPDATA DD allocation
Socket Calls Used in the Sample

 Client and Server


 Initialize
 Socket
 Client
 gethostbyname
th tb
 Connect
 Send
 Server
 Bind
 Listen
 Accept
 gethostbyaddr
 Read
 Both: close
close, terminate
REXX和UNIX System Services

 REXX and UNIX System Services


 OS/390 UNIX System Services was previously known as
OpenEdition
REXX对UNIX服务的支持
REXX和UNIX System Services

 Four ways
y to invoke REXX under UNIX System
y
Services
 TSO/E
 Native batch
 Shell
 From a program
Shell
S e 或 Program
og a

 Default environment = SH
 SYSCALL automatically available
 TSO is not available
 Runs as a UNIX process
 In HFS file
TSO
SO 或 Native
at e Batch
atc

 Default environment = TSO


 Function SYSCALLS("ON") to establish
 SH is not available
 Use SPAWN to run shell command
 Member of PDS
SYSCALL Environment
o

 About 120 commands


 Correspond to the 220 commands of Assembler Callable
Services
 SC28
SC28-1905
1905 OS/390 Using REXX and UNIX System
Services
 SC28-1899 OS/390 UNIX System Services
Programming: Assembler Callable Services Reference
本节总结

 Having
H i completed
l d this
hi unit,
i you should
h ld bbe able
bl to:
 Customize the logon process and ISPF for REXX
 Interface REXX programs with programs written in
other languages
/
 Use REXX with TCP/IP
 REXX and UNIX Services
第九节 高级REXX IV

9.1 REXX对ISPF会话的使用
9 2 REXX对ISPF编辑宏的使用
9.2
本节目标

 After completing this unit, you should be able to:


 Understand how REXX drives the ISPF environment
 Understand how to write ISPF edit macros in REXX
ISPF 宿主命令环境

 What is ISPF?
 IBM courses
 Dialog
g elements
 Starting a dialog
 ISPF services
 Models
 Return codes
 Diagnostics
 Batch
ISPF介绍
S 介绍

 What is a Dialog?
 Dialog elements
 Dialog functions
 Can
C b
be written
itt iin REXX
 Not all ISPF applications
pp use p
panels
Dialog
og Elements
s of
o Interest
s

 Functions - can use REXX


 Variables - automatically available to REXX
 Panel definitions - provides I/O to user
 Fil
File-tailoring
il i skeletons
k l - very useful
f l
 Tables - to store data
 ISPF course for:
 Command tables
 Message definitions
 How to define panelsp
个对话/ ISPF应用
启动一个对话/
启动 S 应用

 Services ((HCE)) only


y available when ISPF running
g
 From TSO:
 ISPSTART CMD(rexxexec parms)
 Within ISPF: SELECT service
 Coded in a panel
 In dialog (REXX)
 Exec can test ISPF availability
ISPF
S 服务

 Panel display services


 Variable services
 PDF services
 Table
T bl services
i
 File tailoring
g services
 Miscellaneous services
面板显示服务

 DISPLAY
DISPLAY, ADDPOP
ADDPOP, REMPOP
REMPOP, TBDISPL
 For example: using REXXTRY
 ADDRESS ISPEXEC
 "DISPLAY PANEL(ISRUTIL)"
 You may terminate this display with
 Enter rc=0

 PF3 rc=8
变量的支持
PDF 服务

 Invoke BROWSE or EDIT directly y


 ADDRESS ISPEXEC
 "EDIT DATASET(REXX.EXEC(MATH))"
 LM* services
i
 Dataset lists
 Member lists (with filters)
 Copy/delete/move/rename/print members
/
 Read/write members
 Read/set ISPF statistics for members

 ISPF tables like a spreadsheet or database


 C l
Columns h
have names: variables
i bl
 Rows are numbered
 Extension variables set when row accessed
 //ISPTABL DD - output **** flag this with a
graphic****
 //ISPTLIB DD - input - first to be ISPTABL
表服务
 TB* - 22 services starting
g with letters TB
 TBCREATE - create a table
 TBOPEN - open existing table
 TBADD - add row to table
 TBPUT - update row in table
 TBGET - read row in table
 TBSAVE - save table to disk
 TBCLOSE - close table
 TBSTATS - query statistics on table
 TBQUERY - table information
 TBSORT - sort a table
文件处理服务

 FTOPEN
 FTINCL
 FTCLOSE
 FTERASE
其他服务

 "CONTROL ERRORS RETURN"


 LIST, LOG
 FILEXFER
 SELECT,
SELECT LIBDEF
Models for Syntax, Examples, Return Codes

 Documentation: alternative to the manual


 Model is an Editor function
 ISPF service models provide:
 Syntax
y
 Parameter descriptions
 Example
 Return codes
MODEL
O 举例
000100 'DISPLAY PANEL ('panelnam') MSG('msg-id') CURSOR('fieldnam'),
000200 CSRPOS('pos#')
CSRPOS( pos# ) COMMAND('commands')
COMMAND( commands ),
000300 RETBUFFR('buf-name') RETLGTH('lng-name') MSGLOC('msgfield')'
=NOTE=
=NOTE= panelnam - Optional, name of the panel to be displayed.
=NOTE= msg
msg-id
id - Optional,
Optional identifier of a message to be
=NOTE= displayed on the panel.
------------ many lines of parameters omitted ------------
=NOTE= EXAMPLE: ADDRESS ISPEXEC
=NOTE= 'DISPLAY
DISPLAY PANEL(PANEL1) MSG(MSG101) CURSOR(FLD1)
CURSOR(FLD1),
=NOTE= COMMAND('commands') RETBUFFR('buffer')'
=NOTE=
000400 If rc = 0 Then /* Return codes */
000500 Do /* 4 - Command not found */
/ /
000600 End /* 8 - End or return command entered */
000700 Else /* - Panel was generated from tags and */
000800 /* EXIT command entered */
000900 /* 12 - Panel,
/ Panel message
message, or cursor */
/
001000 /* field could not be found */
001100 /* 16 - Data truncation or translation error*/
001200 /* 20 - Severe error */
ISPF服务的返回码

 "CONTROL ERRORS RETURN"


 Must check the return code (rc) from every ISPF service
 SIGNAL ON ERROR not helpful, as often rc=4 is valid!
 IF RC>4 THEN SIGNAL ERROR /* helpful comment */
 ERROR:
 SAY ZERRLM
 Edit models for documentation
How to Give ISPF Your Return Code

 EXIT nnn is ignored by ISPF


 To communicate your return code to ISPF
 ZISPFRC = 20
 ADDRESS ISPEXEC "VPUT
VPUT (ZISPFRC) SHARED"
SHARED
 EXIT 20
ISPF
S 系统

 Many variables defined by ISPF in various pools


 Provide system information
 D
Date,
t time,
ti userid,
id software
ft llevels,
l screen sizes,
i
error information
 Set by exec: Titles,
Titles help panels
ISPF Diagnostic
g os Features
u s
 //ISPLOG DD - ISPF log
 TRACE parm will cause each service invocation to be traced to
the log
 Variable: ZERRLM - "ISPF error long message"
 REXX TRACE is still the most useful
ISPF Op
Option
o 7 Dialog
og Test
s
Menu Utilities Compilers Options Status Help

ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
ISPF Primary Option Menu
Option ===>

0 Settings Terminal and user parameters User ID . : TE02


1 View Display source data or listings Time. . . : 04:36
2 Edit Create or change source data Terminal
Terminal. : 3278A
3 Utilities Perform utility functions Screen. . : 1
4 Foreground Interactive language processing Language. : ENGLISH
5 Batch Submit job for language processing Appl ID . : ISR
6 Command Enter TSO or Workstation commands TSO logon : ISPFPROC
7 Dialog Test Perform dialog testing TSO prefix:
9 IBM Products IBM program development products System ID : P390
10 SCLM SW Configuration Library Manager MVS acct. : ACCT#S42
11 Workplace ISPF Object/Action Workplace Release . : ISPF 5.5
M More Additional IBM Products
MQ MQAPPs MQSeries ISPF Utilities
Primary Option Panel
Enter X to Terminate using log/list defaults Option ===>

1 Functions Invoke dialog functions/selection panel


2 Panels Display panels
3 Variables Display/set variable information
4 Tables Display/modify table information
5 Log Browse ISPF log
6 Dialog Services Invoke dialog services
7 Traces Specify trace definitions
8 Breakpoints Specify breakpoint definitions
T Tutorial Display information about Dialog Test
X Exit Terminate dialog testing

F1=Help F2=Split F3=Exit F4=Expand F5=Rfind


F6=Resize F7=Backward F8=Forward F9=Swap F10=Actions
Dialog
og Test
s Option
Op o 4
Batch

 PGM
PGM=IKJEFT1A
IKJEFT1A
 Requires many //ISP* allocations
 Use temporary
p y datasets whereever you
y can
 ISPSLIB, ISPPROF
 Use:
 ISPSTART ........ TRACE
 //ISPLOG DD SYSOUT=*
 Your exec can have parameters
 Note continuation using - (hyphen) for TSO
Running COMPCAT in the Background
//ISPFFT EXEC PGM=IKJEFT1A,DYNAMNBR=128
//*
//SYSEXEC DD DISP=SHR,DSN=&PREFIX..ISPF.EXEC
//**** DD DISP=SHR,DSN=SYS2.COMMON.ISPEXEC
,
//ISPPLIB DD DISP=SHR,DSN=SYS2.COMMON.ISPPLIB
//ISPMLIB DD DISP=SHR,DSN=SYS2.COMMON.ISPMLIB
//ISPSLIB DD DISP=SHR,DSN=&&ISPSLIB
//****ISPLLIB DD DISP=SHR,DSN=SYS2.COMMON.ISPLOAD
//ISPTLIB DD DISP=SHR,DSN=&PREFIX..ISPF.ISPTLIB
DISP=SHR DSN=&PREFIX ISPF ISPTLIB
// DD DISP=SHR,DSN=SYS2.COMMON.ISPTLIB
//ISPTABL DD DISP=SHR,DSN=&PREFIX..ISPF.ISPTLIB
//ISPFILE DD DSN=&PREFIX..SCRATCH.TARGET.ISPFILE,
// DISP=(MOD,CATLG),UNIT=SYSALLDA,
// SPACE=(TRK,(5,10,20)),
// DCB=(LRECL=255,BLKSIZE=0,RECFM=VB)
//*
//ISPPROF DD UNIT=VIO,DISP=(NEW,DELETE),SPACE=(TRK,(1,5,5)),
// DCB=(LRECL=80,BLKSIZE=6160,DSORG=PO,RECFM=FB)
//ISPLOG DD SYSOUT=*,
// DCB=(LRECL=120,BLKSIZE=2400,DSORG=PS,RECFM=FB)
//*
//SYSTSIN DD *
PROFILE NOPREFIX
ISPSTART CMD(COMPCAT -
MASK=P%%% START=P020 NUMBER=20 STATE=NSW QLD) -
NEWAPPL(ISR) TRACE BDISPMAX(20)
//SYSTSPRT DD SYSOUT=*,DEST=P060
//SYSLBC DD DSN
DSN=SYS1.BRODCAST,DISP=SHR
SYS1 BRODCAST DISP SHR
//SYSPRINT DD SYSOUT=*
//SYSTERM DD DUMMY
//SYSIN DD DUMMY
ISREDIT
S 宿主命令环境

 What you can do


 Edit macro versus TSO command
 Code example
 Overview
O i off th
the commands
d
 Selected commands
REXX中编辑宏( Edit Macros )的使用

 Extend Editor commands


 Column editing
 Split/join
 Advanced cut/paste with named buffers
 Compress from Edit
 Perform repeated tasks
 Complex editing
 Reformatting source to be more readable
 Conversions of parameter files
 Mass updates in batch of many members
 Checking on datasets in JCL before submit
 Merge compiler diagnostics and source
编辑宏

 Recognized
g by
y the Editor,, on the Edit command line
 Do not use the ISPF command TSO
 Arguments are not received by:
 ARG
 PARSE ARG
 ARG()
 Editor has its own mechanism:
 ADDRESS ISREDIT
 "MACRO
MACRO (parm1
(parm1, parm2)
parm2)"
编辑宏举例
/* REXX exec to edit VPS printer definition members.*/
signal
i l on novalue
l
address isredit
"macro" /* parm does not work when initial macro from edit service */
"(memvar) = member"
if rc\=0
\ 0 then
h signal
i l error /* query member
b f
failed
il d */
address ispexec
"vget statlst shared"
if rc\=0 then signal error /* vget failed */
grpname = '?'
address isredit
upper statlst
"find ' grpname=' first"
if rc=4
4 th
then signal
i l cannot_do_it
t d it /* no group name */
if rc\= 0 then signal error
"(currow,curcol) = cursor"
"(line) = line .zcsr"
if rc\=0
\ 0 th
then signal
i l error
parse upper var line " GRPNAME=" grpname "," .
编辑宏命令

 There is an Edit macro command for


everything you can do online -96 commands
 FIND, CHANGE, EXCLUDE, LOCATE
 LINE_BEFORE, LINE_AFTER
 COPY, COMPARE
 SHIFT, SORT, SUBMIT
 CREATE, SAVE, CANCEL
 CAPS,
CAPS NULLS
NULLS, NUMBER
 Edit assignment statements
Edit
d t 赋值语句
 Command: FIND
 "FIND ' grpname=' FIRST"
 Assignment: value = keyphrase
 To qquery
y the current cursor position
p
 "(currow,curcol) = cursor"
 "(line) = line .zcsr"
 Assignment to move cursor
 keyphrase = value
 "cursor = (5,20)" /* move cursor to row 5 col
20 */
/
本节总结

 Having completed this unit, you should be able to:


 Understand how REXX drives the ISPF environment
 Understand how to write ISPF Edit Macros in REXX
课堂答疑

You might also like