Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
IBM ^
Objectives
Describe the difference between constants and variables Demonstrate and describe the parts of a compound symbol and how they can be used to create an array Explain the importance of user defined functions and how they are created Describe the uses of the FORMAT( ) function and its manipulation of numerical output
IBM ^
Objectives continued
List and explain string functions:
ABBREV( )
Explain the program stack and demonstrate its practical uses with REXX Explain the uses of the EXTRACT subcommand
IBM ^
Objectives continued
Describe the DO loop and when to use compound DO loops Explain subroutines and their most important language constructs:
CALL ARG PROCEDURE
Discuss the differences and similarities of subroutines and functions State the conditions needed for a condition trap to take place
IBM ^
Objectives continued
Explain what streaming information can do in a REXX program, using:
LINEOUT, CHAROUT, LINEIN, CHAROUT, External Data Queue, LINES, and CHARS
Describe the uses of the STREAM function, with examples List the functions of the commands:
ADDRESS
INTERPRET ITERATE
IBM ^
The default value for a variable is set by the equals operator in an assignment statement. The variable name is translated into uppercase letters by the REXX language.
IBM ^
Compound Symbols
A compound symbol is a variable containing a period:
name = stem.tail[.tail2.tail3..]
The portion up to and including the first period is referred to as the stem. The stem is followed by a tail comprising one or more valid symbols, separated by periods. You can use compound symbols to create an array of variables that can be processed by their derived names.
IBM ^
IBM ^
User-Defined Functions
If a function you need is not available in REXX, it is easy to create your own. You need two instructions to create your own functions effectively:
ARG instruction
Is used to obtain the arguments of an expression
RETURN instruction
Allows you to return the results from the function call to the main program
IBM ^
The number to be formatted should always be small enough to fit into the space you have reserved.
IBM ^
IBM ^
POS( ) Function
POS( ) is used to find the position of a string in another string
STR = Hi, how are you this evening? say POS(eve, STR) What do you think the answer is? HINT: 22 How about: say POS(is even, STR) answer: 19
IBM ^
WORDPOS( ) Function
WORDPOS( ) is used to find a phrase in a string
STR = Hi, how are you this evening? say WORDPOS(this, STR) What do you think the answer is? HINT: 5 How about: say WORDPOS(are you, STR) answer: 3
IBM ^
COMPARE( ) Function
COMPARE( ) is used to compare two strings and find the position of the first character in the string that does not match the second string
STR = Hi, how are you this evening? CMP = Hi, how are you? CMP2 = Hi how are you this morning?
say COMPARE(CMP, STR) What do you think the answer is? HINT: 16
How about: say COMPARE(CMP2, STR) answer: 3 Look out for the missing comma!
IBM ^
ABBREV( ) Function
ABBREV( ) is used to accept abbreviations that a user might enter as input The ABBREV( ) function is a friendly environment function, to allow users to use abbreviations in a REXX program Two examples are:
abbrev(YES, answer, 1) /* accepts YES, YE, or Y */ abbrev(NO, choice) /* accepts NO, N, or (blank) */
IBM ^
IBM ^
IBM ^
IBM ^
Example: A CMS Command That Puts Data onto the Program Stack
IBM ^
IBM ^
IBM ^
loop names, you can specify commands to exit the loops from those names.
IBM ^
Subroutines
IBM ^
IBM ^
IBM ^
Functions:
To
Similarities: a subroutine, you use a CALL instruction to start the subroutine. Both use the ARG and PARSE ARG instructions to obtain the values A subroutine does not need to return of their arguments. a result, but it can. A subroutine sets the value of the Both can be either internal or special variable RESULT. external.
run a function, you use a function
Both
call. A function must return a result, using the return instruction. A function uses a return instruction to pass a variable to the main program.
use the same search order to allow users to store external functions and subroutines on other minidisks.
When
functions are internal, they can use the PROCEDURE instruction just like subroutines.
IBM ^
External Subroutines
IBM ^
SIGNAL label
SIGNAL can be used for error detection and program debugging. You are not able to jump back into or jump around within a DO loop, but you can SIGNAL to exit a DO loop.
IBM ^
IBM ^
IBM ^
IBM ^
IBM ^
You enter a file name, which the pull instruction then parses and stores in the variable fileid. As each line is typed: The PARSE PULL instruction stores it as a string in the variable line The LINEOUT function writes the string contained in line to the file name stored in the variable fileid The DO loop continues until you press Enter twice, thereby entering a NULL string The program then calls LINEOUT with only the file name and exits.
IBM ^
The CHAROUT function writes single-byte characters. The first time a program uses CHAROUT, the named stream is opened for writing and the characters are written to the end of the stream.
IBM ^
IBM ^
IBM ^
IBM ^
if a stream exists
The stream function is for more intricate and specialized input and output tasks.
IBM ^
IBM ^
used to execute instructions that have been built dynamically by evaluating an expression
Is
ITERATE:
Alters The
the flow of control within a repetitive DO loop control variable steps (iterates) the instruction list and is executed again, unless the DO loop is terminated by its conditions
ITERATE
usually required only in special cases such as when more than one instruction is to be interpreted at once
INTERPRET
expr ;
[name] ;
IBM ^
Conclusion
You should now be familiar with REXX programming and syntax. You should be able to create your own REXX programs. Major topics within this module are stacks, subroutines, functions, and stream information. REXX is an important component of z/VM and can be used in many environments.
IBM ^
Glossary
Condition traps are enabled or disabled using the ON or OFF sub-keywords of the CALL and SIGNAL instructions, and can be used to trap a variety of conditions, such as errors in commands, input, or output. External routine A function or subroutine that is neither a built-in routine nor is in the same program as the CALL instruction or function call that invokes it.
IBM ^
Glossary
Function An internal, built-in, or external routine that returns a single result string and is invoked by a function call. Function Call A term in an expression that invokes a routine that carries out some procedure and then returns a string; then replaces the function call for the continuing evaluation of the expression. Internal Routine A function or subroutine that is in the same program as the CALL instruction or function call that is invokes.
IBM ^
Glossary
Read position The position in a character input stream from which the next character or line will be read. Return code A string, typically a number, passed in an implementation-dependent way, that conveys some information about the command that has been executed; it usually indicates the success or failure of the command but can also be used to convey other information.
IBM ^
Glossary
Subroutine An internal, built-in, or external routine that may or may not return a result string and is invoked by the CALL instruction. If it returns a result string, a subroutine can also be invoked by a function call. Trace A description of some or all of the clauses in a program, produced as each is executed; it is the simplest form of debugging aid. Write position The position in a character output stream at which the next character or line will be written.
IBM ^
References
Cowlishaw, Michael, The REXX language: A Practical Approach to Programming 2nd ed. ISBN:0-13-780851-5 z/VM: REXX/VM Users Guide (Version 3 Release 1.0) The REXX language: http://www2.hursley.ibm.com/rexx/ The REXX Language Association: http://www.rexxla.org/