Chapter 6. Writing Subroutines and Functions
What are Subroutines and Functions? . . . . . . . . . . . . . . . . 69
When to Write Subroutines vs. Functions . . . . . . . . . . . . . . . 70
Writing a Subroutine . . . . . . . . . . . . . . . . . . . . . . . 70
Passing Information to a Subroutine . . . . . . . . . . . . . . . . 72
Passing Information by Using Variables . . . . . . . . . . . . . . 72
Passing Information by Using Arguments . . . . . . . . . . . . . 74
Receiving Information from a Subroutine
. . . . . . . . . . . . . . 75
Example - Writing an Internal and an External Subroutine . . . . . . . 76
Writing a Function . . . . . . . . . . . . . . . . . . . . . . . . 77
Passing Information to a Function . . . . . . . . . . . . . . . . . 79
Passing Information by Using Variables . . . . . . . . . . . . . . 79
Passing Information by Using Arguments . . . . . . . . . . . . . 81
Receiving Information from a Function . . . . . . . . . . . . . . . 83
Exercise - Writing a Function. . . . . . . . . . . . . . . . . . 83
Summary of Subroutines and Functions. . . . . . . . . . . . . . . . 83
This chapter shows how to write subroutines and functions and compares their
differences and similarities.
What are Subroutines and Functions?
Subroutines and functions are routines made up of a sequence of instructions that
can receive data, process that data, and return a value. The routines can be:
Internal
The routine is within the current exec, marked by a label and used
only by that exec.
External
A program or exec in a member of a partitioned data set that can
be called by one or more execs. In order for an exec to call the
routine, the exec and the routine must be allocated to a system file,
for example SYSEXEC or SYSPROC, or be in the same PDS. For
more information about allocating to a system file, see “Appendix A.
Allocating Data Sets” on page 185.
In many aspects, subroutines and functions are the same; yet they are different in a
few major aspects, such as the way they are called and the way they return values.
v
Calling a subroutine
To call a subroutine, use the CALL instruction followed by the subroutine name
(label or exec member name) and optionally followed by up to 20 arguments
separated by commas. The subroutine call is an entire instruction.
CALL subroutine_name argument1, argument2,...
Issuing a CALL to internal label names for REXX subroutines and functions that
are greater than eight characters, may have unintended results. Label names will
be truncated to eight characters.
v
Calling a function
To call a function, use the function name (label or exec member name)
immediately followed by parentheses that can contain arguments. There can be
no space between the function name and the parentheses. The function call is
part of an instruction, for example, an assignment instruction.
x = function(argument1, argument2,...)
v
Returning a value from a subroutine
© Copyright IBM Corp. 1988, 2001
69
Содержание TSO/E REXX
Страница 1: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Страница 2: ......
Страница 3: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Страница 10: ...viii z OS V1R1 0 TSO E REXX User s Guide ...
Страница 12: ...x z OS V1R1 0 TSO E REXX User s Guide ...
Страница 14: ...xii z OS V1R1 0 TSO E REXX User s Guide ...
Страница 18: ...xvi z OS V1R1 0 TSO E REXX User s Guide ...
Страница 20: ...2 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 58: ...Tracing Expressions with the TRACE Instruction 40 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 78: ...60 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 86: ...Built In Functions 68 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 128: ...Issuing Other Types of Commands from an Exec 110 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 136: ...Debugging Execs 118 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 170: ...Protecting Elements in the Data Stack 152 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 201: ...Part 3 Appendixes Copyright IBM Corp 1988 2001 183 ...
Страница 202: ...184 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 222: ...Using Variables 204 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 226: ...208 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 238: ...220 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 241: ......