7/27/2019 Rexx1
1/115
TRN
Training Material REXX
Senin S.
Version 0.0 31 October, 2001
Case Consult (India) Pvt. Ltd.D-1, Block B, Technopark Campus,Trivandrum 695 581.
7/27/2019 Rexx1
2/115
No part of this document may be reproduced or transmitted in any form or by anymeans, electronic or mechanical, including photocopying and recording, for anypurpose without the written permission of Case Consult (India) Pvt. Ltd.Information in this document is subject to change without notice and does notrepresent a commitment on the part of Case Consult (India) Pvt. Ltd.
This document and the referenced software described in this document isfurnished under a licence agreement or nondisclosure agreement. The documentand the referenced software may be used or copied only in accordance with theterms of the agreement. It is against the law to copy the document or the softwareon any medium except as specifically allowed in the licence or nondisclosureagreement.
Copyright 1998 Case Consult (India) Pvt. Ltd. All rights reserved.
7/27/2019 Rexx1
3/115
Case Consult (India) Pvt. Ltd. 03/1998 i REXX
C:\C\WINNT\Profiles\ar5303\Temporary Internet Files\OLK71\rexx.doc
Revision List
TABLE OF CONTENTS
1. REXX .................................................................................................................1
1.1 INTRODUCTION TO REXX.................................................................................11.1.1 What is REXX ? .....................................................................................1
1.1.2 BRIEF HISTORY OF REXX............................................................................11.2 GENERAL FORMAT OF REXX STATEMENTS ......................................................41.3 CREATEAND EXECUTEA REXX PROGRAM......................................................61.4 OPERATORS ...................................................................................................7
1.4.1 Arithmetic Operators ..............................................................................71.4.2 Concatenation Operators.......................................................................71.4.3 Operator Precedence.............................................................................7
1.4.4 Logical Operators...................................................................................81.4.5 Comparison Operators...........................................................................8
2. FUNCTIONS, COMMANDS AND INSTRUCTIONS......................................... 11
2.1 TERMINAL INPUT AND OUTPUT .............................................................112.2 CONDITIONAL INSTRUCTIONS.......................................................................... 142.3 LOOPING INSTRUCTIONS ................................................................................192.4 SUBROUTINES AND FUNCTIONS ......................................................................252.5 BUILT-IN FUNCTIONS ..................................................................................... 33
2.5.1 String Manipulating Functions..............................................................332.5.2 Arithmetic Functions.............................................................................41
2.5.3 Comparison Functions .........................................................................432.5.4 Conversion functions ...........................................................................452.5.5 Formatting Functions ...........................................................................482.5.6 Miscellaneous Functions......................................................................51
2.6 TSO/E EXTERNAL FUNCTIONS....................................................................... 552.7 TSO/E REXX COMMANDS ............................................................................602.8 DEBUGGING EXECS.....................................................................................68
2.8.1 Tracing Commands with the TRACE Instruction..................................682.8.2 Using REXX Special Variables RC and SIGL ......................................69
2.9 COMPOUND VARIABLES AND STEM...................................................... 712.10 SAMPLE REXX PROGRAM............................................................................722.11 REXX CODING STANDARDS ........................................................................ 74
3. ISREDIT MACROS ..........................................................................................75
3.1 ISPF/PDF MACRO COMMAND DESCRIPTIONS INDEX .......................................773.2 ISPF/PDF EDIT MACRO COMMANDS..............................................................803.3 SAMPLE ISREDIT MACRO ..........................................................................99
4. ISPF SERVICES............................................................................................100
4.1 ISPF SERVICES INDEX ................................................................................100
7/27/2019 Rexx1
4/115
1. REXX
1.1 Introduction to REXX
1.1.1 What is REXX ?
TSO/REXX (Restructured EXtended eXecutor) is a powerful interactiveprogramming language that can execute system commands, such as TSO, ISPFetc. It allows you to :
Request input from the terminal and Display output on the terminal
Execute TSO commands under program control
Read and Write files
REXX is more modern, powerful language, and is the procedural language forIBMs System Application Architecture (SAA), which means REXX is implementedacross IBMs product line.
REXX is a procedural language that allows programs and algorithms to be writtenin a clear and structured way. It is easy to use by experts and casual users alike.REXX has been designed to make manipulation of the kinds of symbolic objectspeople normally deal with such as words and numbers. Although REXX has thecapability to issue commands to its host environment and to call programs and
function written in other languages, REXX is also designed to be independent ofits supporting system software when such commands are kept to minimum.
1.1.2 Brief History Of REXX
In the 1970 s C. J. Stephenson and others at the IBM T. J Watson Researchcenter realized that, if applied consistently, this concept of commandprogramming language was extraordinary powerful: a single language couldprovide the extension language -or macro language- for wide variety ofapplications. They took the EXEC language and generalized and improved it forthis enhanced role; the new language was called EXEC 2.
EXEC 2 proved the concept of a general macro language. It was used mostly forwriting system commands and macros for wide variety of editors. Its interpreterwas provably, still is, fewest example of efficient robust system/370 assemblercode. However, EXEC2 (like its predecessor and most other macro languages of1970 s and even early 1980 s) assumed that macro programs would be mostlycommands with relatively little glue of logic and variables. Accordingly, it wasdesigned to allows commands ( literal strings, usually upper case) to be writtenplainly, where as language keywords and variables were identified by prefix of an
ampersand.
7/27/2019 Rexx1
5/115
This style, while adequate for simple commands, proved cumbersome for largeand complex programs and macros that were soon being written in EXEC 2. Itbecame clear that new language was needed, one based on classical syntax andsemantic used by languages in tradition of ALGOL, Pascal, and PL/I yet includingcommand and string programming facilities that EXEC 2 had proven to be so
effective and powerful. This new language initially called Rex (because the namesounded nice) was very much driven by the desire to make programming easy. Itborrows most of its features from other languages, especially PL/I and EXEC 2,but these features are modified or expressed in ways that make them easy to use(but not necessary easy to implement!).
The first specification for the language is dated 29 March 1979. This was writtenbefore any implementation was designed, and it was circulated to number ofpeople for comment: this began the tradition of documentation beforeimplementation the characterized development of REXX. Its name gained an xto avoid any confusion with other products.
REXX was included the third release of IBMs VM / System product shipped in1983. It was soon discovered that IBMs customers liked the language just asmuch as did the internal users. Only 2 years later, the first non-IBMimplementation ( by the Mansfield Software Group, for PC-DOS ) becameavailable.
In 1987 IBM announced that REXX was to be the Procedures language for itsSystems Application Architecture (SAA), which was followed by implementationsfor a number of operating systems including MVS/TSO, AS/400, and (in 1989),the Extended Edition of OS/2 1.2. The first REXX compiler was developed atIBMs Vienna laboratory, following research by the IBM Haifa Scientific Center,and was delivered to customers in 1989. By 1990 there was sufficient interest inthe language to justify the first international REXX Symposium for developers andusers, organised by the Stanford linear accelator center in California. Thissymposium has been held annually since then.
Recent version of REXX from IBM include REXX for the AIX/6000 OperatingSystem, REXX for Netware, and REXX for CICS transaction Monitor. REXX isnow available for the most significant operating systems, and from severalvendors, not just IBM. Freeware or Shareware version, often excellent, are also
available for PC-DOS, UNIX, and other systems.
REXX is also a player in Java environment, too. A new dialect of REXX, calledNet REXX , works seamlessly within Java environment: Net REXX programs canuse any Java class; this Java security and performance to REXX programs , andREXX arithmetic and simplicity to Java. A single language Net REXX, may beused for scripting and application development.
7/27/2019 Rexx1
6/115
REXX (Restructured Extended eXecutor)
IT ALLOWS YOU TO :
EXECUTE SYSTEM COMMANDS, TSO, ISPF
REQUEST INPUT FROM THE TERMINAL
DISPLAY OUTPUT ON THE TERMINAL
EXECUTE TSO COMMANDS UNDER PROGRAMCONTROL
DO FILE MANIPULATIONS
7/27/2019 Rexx1
7/115
1.2 General Format Of REXX Statements
REXX Supports free-format statements, which can appear anywhere betweencolumns 1 and 72. A statement can have any number of embedded blanks and
can be terminated with either an end-of-line character or a semicolon(;).
More than one statement can appear on one line, separated from each other withsemicolons. Also, one statement can span more than one line, in which case acomma at the end of the line indicates a continuation of the statement.
Comments appear between the delimiters /* and */ and can span one or morelines. Variables do not need to be predefined, and you can type instructions inupper, lower, or mixed case. A comma is the continuation character and indicatesthat the instruction continues to then next line. A semicolon indicates the end ofthe instruction and is used to separate multiple instructions on one line.
The general form of a REXX statement is
[Label:] term [;]where term is either a comment or an expression.
7/27/2019 Rexx1
8/115
Beginning an instruction
An instruction can begin in any column on any line. The following are all validinstructions.
SAY 'This is a literal string.'SAY 'This is a literal string.'
SAY 'This is a literal string.'
Continuing an instruction
A comma indicates that the instruction continues to the next line. Note that aspace is added between "extended" and "REXX" when it appears on the screen.
SAY 'This is an extended','REXX literal string.'
The result is as follows
This is an extended REXX literal string.
Continuing a literal string without adding a space
If you need to continue an instruction to a second or more lines but do not wantREXX to add spaces when the line appears on the screen, use the concatenationoperand (||).
SAY 'This is an extended literal string that is bro'||,'ken in an awkward place.'
Results
This is an extended literal string that is broken in an awkward place.
Ending an instruction:
If you put more than one instruction on a line, you must separate each instruction
with a semicolon.SAY 'Hi!'; say 'Hi again!'; say 'Hi for the last time!'
7/27/2019 Rexx1
9/115
1.3 Create And Execute A REXX Program
Before you can write a REXX program, called an exec, you need to create a dataset to contain the exec. The data set can be either sequential or partitioned, but if
you plan to create more than one exec, it is easier to create a REXX library as apartitioned data set (PDS) with execs as members. You can allocate the PDS withthe Utilities option in ISPF/PDF or with the TSO/E ALLOCATE command. It isrecommended that allocate a data set with your prefix as the first qualifier, anyname as the second qualifier, and preferably "exec" as the third qualifier.
Example of a Simple Exec/**************************** REXX ******************************/SAY 'This is a REXX exec.'
Note that this simple exec starts with a comment line to identify the program as a
REXX exec. A comment begins with /* and ends with */. This program displaysthe line
This is a REXX exec
After you have placed REXX instructions in a data set, you can run the execexplicitly by using the EXEC command followed by the data set name or implicitlyby entering the member name. You can run an exec implicitly only if the PDS thatcontains the exec was allocated to a system file (SYSEXEC OR SYSPROC) or itis allocated to an application CLIST OR EXEC.
Explicit execution= TSO EX CCI.TST.EXEC(compile)
Implicit Execution=TSO compile
Implicit execution can be done only if the PDS containing the REXX program isallocated to system files ( SYSEXEC or SYSPROC ) using the tso alloc commandor the the PDS is allocated to a application CLIST or EXEC using TSO ALTLIBcommand.
7/27/2019 Rexx1
10/115
1.4 Operators
1.4.1 Arithmetic Operators
The arithmetic operators used in REXX numeric expressions are as follows
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division, returning decimal quotient
% Division, returning integer
quotient// Division, returning remainder
** Exponential
-n Negation
+n Addition
1.4.2 Concatenation Operators
The following concatenation operators are supported by REXX.
Operator Operation
blank Concatenate two strings with a blank characterin between.
!! Concatenate two strings without a blank character in between.
1.4.3 Operator Precedence
Operations are performed according to the following order of precedence:
Order Operation Operators1 Expressions in parentheses ()
2 Prefix operators -+\
3 Exponential operator **
4 Multiplication and division * / % //
5 Addition and subtraction + -
6 Concatenation !!
7 Comparison == = \== < > >< >=
8 Logical AND &
9 Logical OR and EXCLUSIVE OR ! &&
7/27/2019 Rexx1
11/115
1.4.4 Logical Operators
A logical operator is used when a Boolean operation is performed on two binaryoperands. The following is a list of logical operators, including the operation and
return code.
Operator Operation Returns
& AND 1 if both comparisons are true;otherwise 0.
! OR 1 if one of several comparisons is true;Otherwise 0.
&& XOR 1 if only one of a group of comparisonsis true; otherwise 0.
\ NOT Reverses the logical value of the expression.
1.4.5 Comparison Operators
A comparison operator is used when two operands are compared with eachother. After a comparison expression is processed, from left to right, it yields 1 ifthe comparison condition is true and 0 if the comparison condition is false. Thefollowing is a list of REXX comparison operators.
Operator Operation
== Strictly equal
= Equal\== Not strictly equal
\= Not equal
> Greater than
< Less than
>< Greater than or less than
>= Greater than or equal to
Not greater than
>>= Strictly greater than or equal to strictly greater than
7/27/2019 Rexx1
12/115
OPERATORS
ARITHMETIC OPERATORS
USED FOR ARITHMETIC OPERATIONS
E.G.:- + FOR ADDITION% FOR DIVISION RETURNING INTEGER
QUOTIENT
** FOR EXPONENTIATION
CONCATENATION OPERATORS
FOR THE CONCATENATION OF STRINGE.G.:- !! CONCATENATES TWO STRINGS
LOGICAL OPERATORS
FOR LOGICAL OPERATIONS OF EXPRESSIONS
E.G.:- & FOR LOGICAL AND
! FOR OR
COMPARISON OPERATORS
FOR COMPARISONSE.G.:- = FOR EQUAL TO
>FOR GREATER THAN
7/27/2019 Rexx1
13/115
Variable Names
THE RULES FOR VARIABLE NAMES ARE
FIRST CHARACTER NOT 0-9 OR PERIOD.
REMAINING CHARACTERS ANYTHING EXCEPT BLANK.
CAN BE 250 CHARACTERS LONG
UPPER AND LOWER CASE CHARACTERS ASSUMED BE THE
SAME.
VARIABLES CAN ASSIGN THE VALUE USING SIMPLE
ASSIGNMENT STATEMENT OF THE FORM
= EXPRESSION
E.g.;-
MYSTRING = THIS IS THE CONTENT OF MYSTRING
NUMBER1 = 10
NUMBER2 = 20
NUMBER3 = NUMBER1 + NUMBER2
VARIABLES ARE NOT PRE-DEFINED-REXX DEFINES THEM ON
THE FLY THE FIRST TIME THEY APPEAR IN A STATEMENT.
VARIABLES HAVE A DEFAULT VALUE OF NULL. THEY CAN BE
USED IN ARITHMETIC EXPRESSIONS IF THEY CONTAIN VALID
NUMERIC VALUES. A NULL IS A VALID NUMERIC VALUE.
7/27/2019 Rexx1
14/115
2. Functions, Commands And Instructions
Different commands, functions and instructions in REXX can be divided intofollowing categories.
Terminal Input and OutputE.g.:- SAY, PULL
Instructions for program control and conditional logicE.g.:- IF, SELECT, DO, LEAVE, ITERATE
String Handling FunctionsE.g.:- INSERT, COMPARE, MIDSTR, STRIP
Data Conversion FunctionsEg;-X2C, X2D, C2D
Stacks and Related commandsE.g.:- NEWSTACK, DELSTACK, PUSH
Numeric FunctionsE.g.:- Max, Min, BITXOR
TSO Commands and REXX external functionsE.g.:- ALLOCATE, ADDRESS, OUTTRAP, SYSDSN
File Handling InstructionsE.g.:- EXECIO
2.1 Terminal Input And Output
Terminal instructions Say and Put is used display output and receive input fromthe terminal.
7/27/2019 Rexx1
15/115
7/27/2019 Rexx1
16/115
Pull And Say - Terminal Input And Output
SAY Instruction
General Format
SAY expression
Description
The Say instruction sends a line of data to a terminal SYSTSPRT DD statementin batch mode.
Example
SAY SAY what?
PULL Instruction
General format
PULL template
Description
The pull instruction reads the top element of a data stack and uses it as sourcedata. If the data stack is empty, then PULL will read from the terminal. ThePULL instruction is the same as REXX instruction PARSE UPPER PULL
[template].Template consists of alternating patterns and variable names.
Example
SAY Please enter your first name: PULL name
7/27/2019 Rexx1
17/115
2.2 Conditional Instructions
There are two types of conditional instructions. IF/THEN/ELSE can direct theexecution of an exec to one of two choices. SELECT/WHEN/OTHERWISE/END
can direct the execution to one of many choices.
7/27/2019 Rexx1
18/115
IF/THEN/ELSE INSTRUCTIONS
OR
EXAMPLEIF I=100 THEN
SAY VALUE OF I IS 100
ELSE
SAY VALUE OF I NOT EQUAL TO 100
IF logical-expression THEN
statementELSE
statement
IF logical-expression THEN
DO
statement1
statement 2
.
END
ELSE
DO
statement1
statement 2
.
END
7/27/2019 Rexx1
19/115
IF/THEN/ELSE Instructions
The IF instruction executes one or many REXX statements based on the result ofevaluating an expression.
If the ELSE clause appears on the same line as the last portion of the THENstatement set, a semicolon is needed to tell REXX to terminate the THENstatement set
Miscellaneous "If" Statement Information:
Nested Ifs must have an ELSE clause paired with the THEN clause. If no action isappropriate for the ELSE clause, you can use the 'NOP' (no operation) statementas the statement after the ELSE. ( Example 3 )
Example
1. if reply = YES' then say 'Acknowledged'else say 'Enter alternative:'
2. if reply = YES' then say '10-4'; else say 'Please try again:'
3. if today = Saturday' thenif name = FRED' then say 'Go home, Fred'else nop
else say 'Who are you and what day is this?'
Sometimes it is necessary to have one or more IF/THEN/ELSE instructions withinother IF/THEN/ELSE instructions. Having one type of instruction within another iscalled nesting. With nested IF instructions, it is important to match each IF with anELSE and each DO with an END.
IF weather = fine THENDO
SAY 'What a lovely day!'IF tenniscourt = free THEN
SAY 'Shall we play tennis?'ELSE NOP
END
Not matching nested Ifs to Elses and DOs to ENDs can have some surprisingresults.
7/27/2019 Rexx1
20/115
SELECT Instruction- Conditional Execution of statement
THE SELECT INSTRUCTION EXECUTES ONLY ONE STATEMENT FROM A
GROUP OF STATEMENTS. THE SELECTION DEPENDS ON THE RESULT OF
EVALUATING EXPRESSION PLACED AFTER THE WHEN CLAUSE.
Example
SELECT
WHEN Y = 0 THEN SAY Y IS 0WHEN Y = 1 THEN SAY Y IS 1
WHEN Y = 2 THEN SAY Y IS 2
OTHERWISE SAY Y< 0 OR > 2
END
SELECT
[[[[WHEN expression THEN statement]]]]
[[[[WHEN expression THEN statement]]]]
[[[[WHEN expression THEN statement]]]]
[[[[OTHERWISE statements]]]]
END;
7/27/2019 Rexx1
21/115
Using the SELECT/WHEN/OTHERWISE/END Instruction
Example
"Thirty days hath September, April, June, and November; all the rest have thirty-
one, save February alone ..."Write an exec that provides the number of days in a month. First have the execask the user for a month specified as a number between 1 and 12 (with Januarybeing 1, February 2, and so forth). Then have the exec reply with the number ofdays. For month "2", the reply can be "28 or 29".
/******************************** REXX*****************************//* This exec requests the user to enter a month as a whole number *//* f rom 1 t o 12 a nd r esponds with the number o f days i n that *//* month *//******************************************************************/
SAY 'To find out the number of days in a month,'SAY 'Enter the month as a number from 1 to 12.'PULL month
SELECTWHEN month = 9 THEN
days = 30WHEN month = 4 THEN
days = 30WHEN month = 6 THEN
days = 30WHEN month = 11 THEN
days = 30WHEN month = 2 THEN
days = '28 or 29'OTHERWISE
days = 31END
SAY 'There are' days 'days in Month' month '.'
7/27/2019 Rexx1
22/115
2.3 Looping Instructions
There are two types of looping instructions, repetitive loops and conditional loops.Repetitive loops allow you to repeat instructions a certain number of times, and
conditional loops use a condition to control repeating. All loops, regardless of thetype, begin with the DO keyword and end with the END keyword. You cancombine repetitive and conditional loops to create a compound loop. There aretwo types of conditional loops, DO WHILE and DO UNTIL. Both types of loopsare controlled by one or more expressions. However, DO WHILE loops test theexpression before the loop executes the first time and repeat only when theexpression is true. DO UNTIL loops test the expression after the loop executes atleast once and repeat only when the expression is false. The LEAVE instructioncauses an immediate exit from a repetitive loop. Another instruction, ITERATE,stops execution from within the loop and passes control to the DO instruction atthe top of the loop.
7/27/2019 Rexx1
23/115
DO INSTRUCTION
THE DO INSTRUCTION IS USED TO EXECUTE A GROUP OF
REXX STATEMENTS UNDER THE CONTROL OF AN
EXPRESSION THAT DETERMINES HOW MAY TIMES THE DO
STATEMENT SET IS TO BE EXECUTED. THE DO STATEMENT
HAS SEVERAL FORMATS
DO [ expression or variable = start]
[ TO limit ] [ BY increment];
[ FOR expression ];
[ WHILE expression];
[ UNTIL expression];
statement
END
7/27/2019 Rexx1
24/115
SIMPLE DO:
DOstatement 1
....END
Simple DO executes statements only one time
Controlled Repetitive DO :
DO variable = start [TO end ] [BY increment]statement 1statement 2
END;
Here variable starts with the value given by start and is incremented byincrement until the variable passes the value given by end. The control variablecan be changed within the loop; the changed value will affect the number of timesthe loop is executed.
DO-FOR loop
DO variable = start [TO end ] FOR expression;statement
......
....
END;
The FOR clause specifies a non-negative whole number that sets a second limiton the number of passes through the loop if no other condition terminates theloop
DO-WHILE loop
DO variable=start [TO end ] WHILE expression;
statement.........
END;
You can use another type of DO statement, called a DO-WHILE or DO-UNTIL. Ifa WHILE or UNTIL clause is specified on a DO statement, it supplies anexpression that must evaluate to either a 0 (false) or a 1 (true). The DO loop isrepeatedly executed either WHILE the evaluated expression result is 1, or UNTILthe evaluated expression result is 1.
7/27/2019 Rexx1
25/115
1. DO 7 /* Repeats 7 times */statement 1statement 2..
END
2.Do I = 2 to - 1 by - 1 /* W ould d isplay:*/
say I /* 2 on 1st pass through loop */End /* 1 on 2nd pass through loop */
3. Do K = 1 t o 8 by 2 for 3 /* Loop will be executed 3 times */
say k /*since for 3 overrides the*/End /*K=1 to 8 by 2*/
4. Do i=1 to 20 by 2 until I > 6
say I
end/* This loop would display: 1, 3, 5, 7, stopping at 7, since 7 > 6 */
5. switch = 1 /* s witch i s a l ogical v ariable * /Do i= 1 to 20 while switch
say Iif i=7 then switch=0
End /* this loop would display 1 to 7, since switch = 0 when i=7 */
6 DO FOREVER
say execute this loop foreverEND
7. The following loop is set to repeat 10 times while a certain condition is met, at
which point it stops.
quantity = 20DO number = 1 TO 10 WHILE quantity < 50
quantity = quantity + numberSAY 'Quantity = 'quantity ' (Loop 'number')'
END
7/27/2019 Rexx1
26/115
LEAVE Instruction-Terminate a DO loop
THE LEAVE INSTRUCTION STOPS A DO LOOP AND TRANSFERS
CONTROL TO THE STATEMENT FOLLOWING THE END
STATEMENT.
NAME IS A CONTROL VARIABLE FOR THE DO LOOP.
Example
D O j = 1 t 0 4
if j= 2 THEN LEAVE
SAY J /* Display 1 only */
END
LEAVE [[[[name]]]];
7/27/2019 Rexx1
27/115
ITERATE INSTRUCTION- END CURRENT ITERATION OF
DO LOOP
THE ITERATE INSTRUCTION STOPS THE CURRENT ITERATION
OF A DO LOOP AND TRANSFERS CONTROL TO THE END
STATEMENT. THE DO LOOP CONTINUES AFTER TESTING ANY
EXPRESSION ASSOCIATED WITH THE LOOP. LIKE LEAVE,
ITERATE IS USED WITHIN THE LOOP.
NAME IS THE CONTROL VARIABLE FOR THE DO LOOP.
DO count = 1 TO 10
IF count = 8 THEN
ITERATE
ELSE
SAY 'Number' count /*List of numbers 1 t0 10exception of number 8*/
END
ITERATE [[[[name]]]]
7/27/2019 Rexx1
28/115
2.4 Subroutines and Functions
Subroutines and functions are routines made up of a sequence of instructionsthat can receive data, process that data, and return a value. The routines can be
Internal, external. Internal routine is within the current exec, marked by a labeland used only by that exec. External routine is program or exec in a member of apartitioned data set that can be called by one or more execs. In many aspects,subroutines and functions are the same; yet they are different in a few majoraspects, such as the way they are called and the way they return values. CALLinstruction is used to call a subroutine and RETURN is used to return values fromthe routine.
7/27/2019 Rexx1
29/115
Subroutines and Functions
CALLING A SUBROUTINE
CALLING A FUNCTION
RETURNING A VALUE FROM A SUBROUTINE
A SUBROUTINE DOES NOT HAVE TO RETURN A VALUE, BUT WHEN IT
DOES, IT SENDS BACK THE VALUE WITH THE RETURN INSTRUCTION.
THE CALLING EXEC RECEIVES THE VALUE IN THE REXX SPECIAL
VARIABLE NAMED RESULT.
SAY 'The answer is' RESULT
Returning a value from a function
A FUNCTION MUST RETURN A VALUE. THE CALLING EXEC RECEIVES THEVALUE AT THE FUNCTION CALL. THE VALUE REPLACES THE FUNCTION
CALL, SO THAT IN THE FOLLOWING EXAMPLE, X = VALUE.
CALL subroutine_name argument1, argument2,...
x = function(argument1, argument2,...)
RETURN value
x = function(argument1, argument2,...)
7/27/2019 Rexx1
30/115
Passing Information by Using Variables
When an exec and its internal function share the same variables, the value of avariable is what was last assigned, regardless of whether the assignment was inthe main part of the exec or in the function.
Example/*REXX*******/number1 = 5number2 = 10SAY add()SAY answerEXIT
add:answer = number1 + number2RETURN answer
Using the same variables in an exec and its internal function can sometimescreate problems.
To avoid this kind of problem in an internal function, you can use: ThePROCEDURE instruction.
Passing Information by Using Arguments
A way to pass information to either internal or external functions or subroutines isthrough arguments. You can pass up to 20 arguments separated by commas in afunction call.
function(argument1,argument2,argument3,..........)
Using the ARG Instruction: The function can receive the arguments with the ARGinstruction. Arguments are also separated by commas in the ARG instruction.ARG arg1,arg2,arg3 .......
7/27/2019 Rexx1
31/115
PROCEDURE INSTRUCTION-DEFINE A PROCEDURE
THE PROCEDURE INSTRUCTION DEFINES A PROCEDURE.
EXPOSE IS THE KEYWORD USED TO DEFINE ONE OR MORE
GLOBAL VARIABLES THAT ARE USED WITHIN THE
PROCEDURE.
NAME IS GLOBAL VARIABLE NAME.
Example
X = "MY VALUE IS USED IN THE PROCEDURE"
Y = "MY VALUE IS NOT USED IN THE PROCEDURE "
CALL PROC
EXIT
PROC: PROCEDURE EXPOSE X
SAY X
SAY Y /* Y has no value here */
RETURN
PROCEDURE [[[[ EXPOSE name,.... ]]]];
7/27/2019 Rexx1
32/115
ARG instruction
THE ARG INSTRUCTION PARSES THE ARGUMENTS PASSED TO
A PROGRAM OR SUBROUTINE AND PLACES THEM IN
VARIABLES. THE PARSING IS DONE ACCORDING TO PARSING
RULES OF REXX.
TEMPLATE CONSISTS OF SYMBOLS SEPARATED BY BLANKS.
Example
ret = MYWORK(DATA 3 30 50)
Mywork: ARG string, num1, num2
AFTER PARSING, THE SYMBOLS WILL HAVE THE FOLLOWING
VALUES:
STRING HAS DATA 3 , NUM1 HAS 30 AND NUM2 HAS 50.
ARG template
7/27/2019 Rexx1
33/115
CALL Instruction
THE CALL INSTRUCTION EXECUTES A SUBROUTINE, A
PROGRAM, A BUILT-IN FUNCTION, OR AN EXTERNAL ROUTINE.
CONTROL IS PASSED TO THE CALLED ROUTINE, AND AFTER
ITS EXECUTION IS COMPLETED, CONTROL IS RETURNED TO
THE STATEMENT FOLLOWING THE CALL STATEMENT IN THE
CALLING ROUTINE.
AFTER COMPLETION OF THE CALLED ROUTINE, ANY RETURN
VALUE IS PLACED IN THE VARIABLE RETURN. IF NO VALUE IS
RETURNED BY THE INVOKED ROUTINE, THEN RETURN IS
INITIALISED TO NULL.
Example
Y = 2
CALL SQUARE Y /* CALL THE ROUTINE TO CALCULATE
SQUARE OF Y */
SAY SQUARE OF Y IS RESULT
SQUARE: PROCEDURE
ARG NRETURN N*N
CALL name [expression,...];
7/27/2019 Rexx1
34/115
EXIT INSTRUCTION-TERMINATE EXEC
THE EXIT INSTRUCTION ENDS THE EXECUTION OF A REXX
EXEC AND RETURNS CONTROL TO THE CALLING PROGRAM.
EXPRESSION IS OPTIONAL; ITS VALUE IS EVALUATED
BEFORE TERMINATION OF THE EXEC.
A VALUE IS RETURNED TO THE CALLING PROGRAM
DEPENDING ON WHETHER EXPRESSION IS PART OF THE EXIT
INSTRUCTION.
Example
In the following program fragment, the exec will terminate
returning the value 12.
X=4
EXIT x*3 /* terminate exec */
EXIT [[[[expression]]]];
7/27/2019 Rexx1
35/115
Examples
The following program calls the function greatest which returns the max of threenumbers. First time it is called as a subroutine and then it is called as a function.
/*REXX*/A= 1B = 4C = 5M A X = 0CALL GREATEST A B C /* SUBROUTINE CALL*/SAY 'EXPOSED VARIABLE MAX' MAXSAY 'RETURNED VALUE RESELT' RESULTSAY GREATEST(A B C) GREATEST(A B C) /* FUNCTION CALL */EXIT/*******************************************//*Function :greatest *//*Arguments :N1 N2 N3 */
/*Returns greatest among N1,N2 and N3 *//******************************************/
GREATEST: PROCEDURE EXPOSE MAXARG N1 N2 N3MAX = N1IF N2 > N1 THEN MAX = N2IF N3 > MAX THEN MAX = N3RETURN(MAX)
Recursive routines
Functions or subroutines can be called recursively.
/*REXX*/N= 10D O I = 0 T O N
SAY B(N I)/* Binomial coefficients */ENDEXITB:PROCEDUREA R G N RSELECT
WHEN R = 1 THEN RETURN(N)WHEN (R = N ! N = 1! R = 0 ) THEN RETURN(1)WHEN N = 0 THEN SAY 'ERROR! NOT DEFINED!'
OTHERWISERETURN(B(N-1 R) + B(N-1 R-1))
END
7/27/2019 Rexx1
36/115
2.5 Built-in Functions
Over 50 functions are built into the language processor. The built-in functions fallinto the following categories: Arithmetic functions, Comparison functions,
Conversion functions, Formatting functions, String manipulating functions,Miscellaneous functions.
2.5.1 String Manipulating Functions
These functions analyze a string supplied in the argument (or a variablerepresenting a string) and return a particular value.
7/27/2019 Rexx1
37/115
Following is the list of all string manipulating functions. Commonly used functionsare explained later.
Function Description
ABBREV Returns a string indicating if one string is equal to the specified
number of leading characters of another string.DELSTR Returns a string after deleting a specified number of
characters, starting at a specified point in the input string.
DELWORD Returns a string after deleting a specified number of words,starting at a specified word in the input string.
FIND * Returns the word number of the first word of a specified phrasefound within the input string.
INDEX * Returns the character position of the first character of aspecified string found in the input string.
INSERT Returns a character string after inserting one input string into
another string after a specified character position.LASTPOS Returns the starting character position of the last occurrence ofone string in another.
LENGTH Returns the length of the input string.
OVERLAY Returns a string that is the target string overlaid by a secondinput string.
POS Returns the character position of one string in another.
REVERSE Returns a character string, the characters of which are inreverse order (swapped end for end).
STRIP Returns a character string after removing leading or trailingcharacters or both from the input string.
SUBSTR Returns a portion of the input string beginning at a specifiedcharacter position.
SUBWORD Returns a portion of the input string starting at a specified wordnumber.
TRANSLATE Returns a character string with each character of the inputstring translated to another character or unchanged.
VERIFY Returns a number indicating whether an input string iscomposed only of characters from another input string orreturns the character position of the first unmatched character.
WORD Returns a word from an input string as indicated by a specified
number.WORDINDEX Returns the character position in an input string of the firstcharacter in the specified word.
WORDLENGTH Returns the length of a specified word in the input string.
WORDPOS Returns the word number of the first word of a specified phrasein the input string.
WORDS Returns the number of words in the input string.
* Indicates a non-SAA built-in function provided only by TSO/E.
7/27/2019 Rexx1
38/115
FIND FUNCTION
DESCRIPTION
THE FIND FUNCTION FINDS THE FIRST OCCURRENCE OF A
PHRASE IN A STRING OF WORDS. FIND COMPRESSES BLANKS
INTO A SINGLE BLANK.
RETURN
THE FUNCTION RETURNS THE FIRST POSITION OF THE
PHRASE IF IT IS FOUND, OTHERWISE IT RETURNS 0.
EXAMPLE
Find(All dogs go to Heaven, go to) returns 3
Find(Honey they shrunk my pay, my pay)returns 4
FIND(Honey they shrunk my pay the baby)returns 0
FIND (string, pharase)
7/27/2019 Rexx1
39/115
INDEX function-Search for substring
THE INDEX FUNCTION SEARCHES FOR A SUBSTRING IN A
STRING AND RETURNS THE POSITION OF THE FIRST
OCCURRENCE OF THE SUBSTRING.
THE FUNCTION RETURNS
0 IF SUBSTRING IS NOT FOUND IN STRING
A NUMERIC VALUE WHICH IS RELATIVE TO 1 IF THE
SUBSTRING IS FOUND
EXAMPLE
INDEX('abcdef, cd') ->3
INDEX('abcdef, xd') ->0
INDEX('abcdef','bc',3) ->0INDEX('abcabc','bc',3) ->5
INDEX('abcabc','bc',6) ->0
INDEX(string, substring[[[[,startposition]]]] )
7/27/2019 Rexx1
40/115
INSERT FUNCTION-INSERT A STRING
THE INSERT FUNCTION INSERTS A STRING INTO ANOTHER
STRING AT A SPECIFIED POSITION. PADDING IS DONE IF
REQUIRED.
INS-STRING IS THE STRING INSERTED INTO STRING.
STRING IS THE STRING IN WHICH INS-STRING IS INSERTED.
N IS THE CHARACTER POSITION AFTER WHICH INS-STRING
IS INSERTED IN STRING. THE VALUE OF N MUST BE
NONNEGATIVE, AND ITS DEFAULT VALUE IS 0.
LENGTH IS THE LENGTH OF INS-STRING.
PAD IS THE CHARACTER FOR PADDING IF LENGTH IS
GREATER THAN THE LENGTH OF INS-STRING.
THE FUNCTION RETURNS STRING WITH INS-STRING INSERTED.
Example
INSERT(' ','abcdef',3) ->'abc def'
INSERT('123','abc',5,6) ->'abc 123 '
INSERT('123','abc',5,6,'+'->'abc++123+++'
INSERT('123','abc') ->'123abc'
INSERT('123','abc',,5,'-') ->'123--abc'
INSERT(ins-string, string[[[[,[[[[n]]]][[[[,[[[[length]]]][[[[,pad]]]]]]]]]]]] )
7/27/2019 Rexx1
41/115
LENGTH function-Get the length of a string
Description
The LENGTH function determines he number of characters in a
string.
Return
The function returns the length of string
ExampleLENGTH(All dogs go to heaven) returns 21.
LENGTH(string)
7/27/2019 Rexx1
42/115
STRIP function-Remove leading/trailing characters
Description
The STRIP function removes any leading and trailing characters
from a string.
string is the data from which characters are removed.
Both means to remove both leading and trailing characters from
string.
Leading/Trailing means to remove leading/trailing characters
from string.
char is the character to be removed from string; the default is a
blank.
Return
The function returns the stripped string. Example
STRIP(' ab c ') ->'ab c'
STRIP(' ab c ','L') ->'ab c '
STRIP(' ab c ','t') ->' ab c'
STRIP('12.7000',,0) ->'12.7'
STRIP('0012.700',,0) ->'12.7'
STRIP(string[[[[,[[[[Both or Leading or Trailing ]]]][[[[,char]]]]]]]])
7/27/2019 Rexx1
43/115
SUBSTR function-Extract a substring
Description
THE SUBSTR FUNCTION EXTRACTS A SUBSTRING FROM A
STRING STARTING AT A SPECIFIED CHARACTER POSITION.
STRING IS THE STRING FROM WHICH A PORTION IS
EXTRACTED.
POSITION IS THE CHARACTER POSITION IN STRING AT WHICH
THE SUBSTRING IS EXTRACTED; IT IS ALSO THE FIRST
CHARACTER OF THE EXTRACTED SUBSTRING.
LENGTH IS THE NUMBER OF BYTES OF THE SUBSTRING.
PAD IS THE PADDING CHARACTER. RETURN
THE FUNCTION RETURNS THE SUBSTRING.
EXAMPLE
SUBSTR(HOT DOG,4) RETURNS DOG.
SUBSTR(string, position[[[[,[[[[length]]]][[[[,pad]]]]]]]])
7/27/2019 Rexx1
44/115
7/27/2019 Rexx1
45/115
MAX function-Determine the maximum value
Description
THE MAX FUNCTION RETURNS THE MAXIMUM NUMERIC VALUE
FROM A LIST OF NUMERIC VALUES. UP TO 20 NUMBERS ARE
ALLOWED.
NUMBER IS A NUMERIC VALUE.
RETURN
THE FUNCTION RETURNS THE MAXIMUM VALUE. THE SIZE OF
THE RETURNED VALUE DEPENDS ON THE CURRENT SETTINGS
OF NUMERIC DIGITS.
EXAMPLE
MAX(22,34,67,100,1,4) RETURNS 100.
MAX(number,....)
7/27/2019 Rexx1
46/115
2.5.3 Comparison Functions
These functions compare numbers and/or strings and return a value.
Function DescriptionCOMPARE Returns 0 if the two input strings are identical. Otherwise, returns
the position of the first character that does not match.
DATATYPE Returns a string indicating the input string is a particular datatype, such as a number or character.
SYMBOL Returns this state of the symbol (variable, literal, or bad).
7/27/2019 Rexx1
47/115
COMPARE function
Description
THE COMPARE FUNCTION COMPARES TWO STRINGS.
string1 and string2 ARE STRINGS BEING COMPARED.
pad IS AN OPTIONAL PADDING CHARACTER; IF IT IS NOT
SPECIFIED, THE DEFAULT CHARACTER IS BLANK (X40).
RETURN
THE FUNCTION RETURNS:
ZERO IF BOTH INPUT STRINGS ARE THE SAME.
A NONZERO VALUE IF THE INPUT STRINGS ARE NOT
THE SAME; THIS VALUE IS ALSO THE POSITION OF THE
FIRST MISMATCHED CHARACTERS.
Example
COMPARE(345,345) returns 0 (exact match )
COMPARE(MOO%% , MOO,% ) returns 6 ( Ist
mismatch after padding character )
COMPARE(daa, do) returns 2 (Ist mismatched
character )
COMPARE(string1,string2[[[[,pad]]]])
7/27/2019 Rexx1
48/115
2.5.4 Conversion functions
These functions convert one type of data representation to another type of datarepresentation.
7/27/2019 Rexx1
49/115
Data Conversion functions
Function Description
B2X Returns a string, in character format, that represents the input binarystring converted to hexadecimal. (Binary to hexadecimal)
C2D Returns the decimal value of the binary representation of the inputstring. (Character to Decimal)
C2X Returns a string, in character format, that represents the input stringconverted to hexadecimal. (Character to Hexadecimal)
D2C Returns a string, in character format, that represents the input decimalnumber converted to binary. (Decimal to Character)
D2X Returns a string, in character format, that represents the input decimalnumber converted to hexadecimal. (Decimal to Hexadecimal)
X2B Returns a string, in character format, that represents the inputhexadecimal string converted to binary. (Hexadecimal to binary)
X2D Returns the decimal representation of the input hexadecimal string.(Hexadecimal to Decimal)
7/27/2019 Rexx1
50/115
X2C function-Convert hexadecimal to character
Description
The X2C function converts a string of hexadecimal values into a
character string.
Hex-string is one or more hexadecimal digits to be converted.
Return
The function returns the converted character string.
ExampleX2C(F0F1F2) returns 012.
X2C(hex-string)
7/27/2019 Rexx1
51/115
2.5.5 Formatting Functions
These functions manipulate the characters and spacing in strings supplied in theargument.
Function Description
CENTER/CENTRE
Returns a string of a specified length with the input stringcentered in it, with pad characters added as necessary tomake up the length.
COPIES Returns the specified number of concatenated copies of theinput string.
FORMAT Returns the input number, rounded and formatted.
JUSTIFY * Returns a specified string formatted by adding padcharacters between words to justify to both margins.
LEFT Returns a string of the specified length, truncated or paddedon the right as needed.
RIGHT Returns a string of the specified length, truncated or paddedon the left as needed.
SPACE Returns the words in the input string with a specifiednumber of pad characters between each word.
* Indicates a non-SAA built-in function provided only by TSO/E.
7/27/2019 Rexx1
52/115
SPACE
RETURNS THE BLANK-DELIMITED WORDS IN STRING WITH N
PAD CHARACTERS BETWEEN EACH WORD. IF YOU SPECIFY N,
IT MUST BE A POSITIVE WHOLE NUMBER OR ZERO. IF IT IS 0,
ALL BLANKS ARE REMOVED. LEADING AND TRAILING BLANKS
ARE ALWAYS REMOVED. THE DEFAULT FOR N IS 1, AND THEDEFAULT PAD CHARACTER IS A BLANK.
Examples
SPACE('ABC DEF ') ->'ABC DEF'
SPACE(' ABC DEF',3) ->'ABC DEF'SPACE('ABC DEF ',1) ->'ABC DEF'
SPACE('ABC DEF ',0) ->'ABCDEF'
SPACE('ABC DEF ',2,'+')->'ABC++DEF'
SPACE(string[[[[,n]]]][[[[,pad]]]])
7/27/2019 Rexx1
53/115
JUSTIFY
RETURNS STRING FORMATTED BY ADDING PAD CHARACTERS BETWEEN
BLANK-DELIMITED WORDS TO JUSTIFY TO BOTH MARGINS. THIS IS DONE
TO WIDTH LENGTH (LENGTH MUST BE NONNEGATIVE). THE DEFAULT
PAD CHARACTER IS A BLANK.
Examples
JUSTIFY('The blue sky',14) ->'The blue sky'
JUSTIFY('The blue sky',8) ->'The blue'
JUSTIFY('The blue sky',9) ->'The blue'
JUSTIFY('The blue sky',9,'+') ->'The++blue'
JUSTIFY(string, length,[[[[pad]]]])
7/27/2019 Rexx1
54/115
2.5.6 Miscellaneous Functions
These functions do not clearly fit into any of the other categories.
7/27/2019 Rexx1
55/115
Miscellaneous Functions
Function Description
ADDRESS Returns the name of the environment to which commands arecurrently being sent.
ARG Returns an argument string or information about the argumentstrings to a program or internal routine.
BITAND Returns a string composed of the two input strings logicallyANDed together, bit by bit.
BITOR Returns a string composed of the two input strings logicallyORed together, bit by bit.
BITXOR Returns a string composed of the two input strings exclusiveORed together, bit by bit.
CONDITION Returns the condition information, such as name and status,associated with the current trapped condition.
DATE Returns the date in the default format (dd mmm yyyy) or in oneof various optional formats.
ERRORTEXT Returns the error message associated with the specified errornumber.
EXTERNALS* Returns the number of elements in the terminal input buffer. InTSO/E, this function always returns a 0.
LINESIZE* Returns the current terminal line width minus 1.
QUEUED Returns the number of lines remaining in the external dataqueue at the time when the function is invoked.
SOURCELINE Returns either the line number of the last line in the source file orthe source line specified by a number.
TIME Returns the local time in the default 24-hour clock format(hh:mm:ss) or in one of various optional formats.
TRACE Returns the trace actions currently in effect.
USERID* Returns the TSO/E user ID, if the REXX exec is running in theTSO/E address space.
VALUE Returns the value of a specified symbol and optionally assigns ita new value.
XRANGE Returns a string of all 1-byte codes (in ascending order) betweenand including specified starting and ending values.
* Indicates a non-SAA built-in function provided only by TSO/E.
7/27/2019 Rexx1
56/115
ADDRESS instruction
Description
THE ADDRESS INSTRUCTION SPECIFIES THE HOST
ENVIRONMENT WHERE NON-REXX COMMANDS ARE TO BE
EXECUTED.
THE SETTING OF THE HOST ENVIRONMENT IS CHECKED WITH
THE ADDRESS FUNCTION.HOST-ENVIRONMENT IS A CHARACTER STRING CONSTANT, IT
IS ONE OF THE FOLLOWING:
ISPEXEC Routes commands to SPFF/PDF.
ISREDIT Routes commands to a PDF edit macro
processor.
TSO Routes commands to TSO.
MVS Invokes a program using the normal MVSprogram Search
LINK Issues an MVS LINK macro to the routine being
invoked.
ATTACH Issues an MVS ATTACH macro to the routine
being invoked.
CMS Routes commands to CMS.
DOS Routes commands to DOS/VSE.
XEDIT Routes commands to XEDIT
EXAMPLE
ADDRESS TSO FREE DATASET(TEST.COBOL.PGMLOAD ).
ADDRESS host-environment [[[[expression]]]] or[[[[value]]]] expression;
7/27/2019 Rexx1
57/115
ADRESS INSTRUCTION
General format
ADDRESS host-environment [expression] or[value] expression;
Expression is first evaluated by REXX; the result is sent to the host environmentas a command to be executed. IF expression is not specified then the destinationis set permanently until the next ADDRESS instruction is issued. Subsequentnon-EXEC commands will be sent to this new host environment. If expression isspecified, then the host environment is effective during the execution of thisADDRESS instruction.
VALUE is used if the first character of expression is a special character.
Return
The return code from the host environment, after the command is executed, isplaced in the special variable RC.
Example
The following ADDRESS instruction sends the commandFREE DATASET(TEST.COBOL.PGMLOAD ) to TSO to be executed.ADDRESS TSO FREE DATASET(TEST.COBOL.PGMLOAD ).
/*REXX*/SAY 'DO YOU KNOW YOUR PF KEYS?'
PULL ANSWERIF ANSWER = 'NO' ! ANSWER = 'N' THEN
ADDRESS ISPEXEC "DISPLAY PANEL(ISPOPT3C)"
/*Address ISPEXEC to issue to ISPF service*/ELSE
SAY 'O.K. NEVER MIND.'
7/27/2019 Rexx1
58/115
2.6 TSO/E External Functions
In addition to the built-in functions, TSO/E provides external functions that youcan use to do specific tasks. Some of these functions perform the same services
as control variables in the CLIST language.
7/27/2019 Rexx1
59/115
The TSO/E external functions
GETMSG - returns in variables a system message issued during an extendedMCS console session. It also returns in variables associated information aboutthe message. The function call is replaced by a function code that indicates
whether or not the call was successful.
LISTDSI - returns in variables the data set attributes of a specified data set. Thefunction call is replaced by a function code that indicates whether or not the callwas successful.
MSG - controls the display of TSO/E messages. The function returns the previoussetting of MSG.
MVSVAR - uses specific argument values to return information about MVS,TSO/E, and the current session.
OUTTRAP - traps lines of TSO/E command output into a specified series ofvariables. The function call returns the variable name specified.
PROMPT - sets the prompt option on or off for TSO/E interactive commands. Thefunction returns the previous setting of prompt.
SETLANG - retrieves and optionally changes the language in which REXXmessages are displayed. The function returns the previous language setting.
STORAGE - retrieves and optionally changes the value in a storage address.
SYSCPUS - returns in a stem variable information about all CPUs that are online.
SYSDSN - returns OK if the specified data set exists; otherwise, it returns anappropriate error message.
SYSVAR - uses specific argument values to return information about the user,terminal, language, exec, system, and console session.
7/27/2019 Rexx1
60/115
OUTTRAP FUNCTION
The OUTTRAP function puts lines of command output into a
series of numbered variables, each with the same prefix. Thesevariables save the command output and allow an exec to process
the output. Specify the variable name in parentheses following
the function call.
To turn trapping off, reissue the OUTTRAP function with the
word "OFF".
x = OUTTRAP('OFF') /* turns trapping OFF */
The OUTTRAP function can be used only in REXX EXECs that
run in the TSO/E address space.
X = OUTTRAP(Var)
X = OUTTRAP(Var,5)
X = OUTTRAP(OFF)
7/27/2019 Rexx1
61/115
Examples
SAY 'The OUTTRAP variable name is' OUTTRAP('var')/* Displays the variable name in which command output istrapped.*/
The total number of lines trapped is stored in var0.To limit the number of lines of output saved, you can specify a limit, for after thevariable name.
x = OUTTRAP('var',5)
This results in up to 5 lines of command output stored in var1, var2, var3, var4,var5; and var0 contains the number 5.
The stem variable includes a period, which causes the lines of output to be storedin a series of compound variables.
x = OUTTRAP('var.')"LISTC"SAY 'The number of lines trapped is' var.0lines = var.0 + 1"LISTDS mynew.exec MEMBERS"SAY 'The number of lines trapped is' var.0DO I = lines TO var.0
SAY var.iEND
To turn trapping off, reissue the OUTTRAP function with the word "OFF"
x = OUTTRAP('OFF') /* turns trapping OFF */
7/27/2019 Rexx1
62/115
SYSDSN function-Check dataset status
SYSDSN IS A TSO FUNCTION THAT CHECKS THE STATUS OF A
DATASET.
DSNAME IS THE NAME FOR WHICH THE STATUS IS
REQUESTED.
MEMBER IS THE MEMBER OF THE PARTITIONED DATASET FOR
WHICH THE STATUS IS REQUESTED.
Return
The function returns the following information about dataset or
member:
OK
MEMBER NOT FOUND
MEMBER SPECIFIED, BUT DATA SET IS NOT PARTITIONED
DATA SET IS NOT FOUND
ERROR PROCESSING REQUESTED DATA SET
PROTECTED DATA SET
VOLUME NOT IN THE SYSTEM
INVALID DATA SET NAME
UNAVAILABLE DATA SET
Exampledsn =SYSDSN( SYS1.PROCLIB )
if dsn = OK say SYS1.PROCLIB exists
SYSDSN(dsname or dsname(member))
7/27/2019 Rexx1
63/115
2.7 TSO/E REXX Commands
Commands provided with the TSO/E implementation of the language. These
commands do REXX-related tasks in an exec, such as
Control I/O processing of information to and from data sets, (EXECIO)
Perform data stack services (MAKEBUF, DROPBUF, QBUF, QELEM,NEWSTACK, DELSTACK, QSTACK)
Change characteristics that control the execution of an exec (EXECUTIL andthe immediate commands)
Check for the existence of a host command environment (SUBCOM).
7/27/2019 Rexx1
64/115
Using REXX commands
An exec can consist of nothing but TSO/E commands, such as an exec that setsup a user's terminal environment by allocating the appropriate libraries of datasets, or the exec can contain commands intermixed with REXX language
instructions.
When an exec issues a command, the REXX special variable RC is set to thereturn code. An exec can use the return code to determine a course of actionwithin the exec. Every time a command is issued, RC is set. Thus RC containsthe return code from the most recently issued command.
Using Quotation marks: Generally, to differentiate commands from other typesof instructions, enclose the command within single or double quotation marks.When issuing TSO/E commands in an exec, it is recommended that you enclosethem in double quotation marks.
Many TSO/E commands use single quotation marks within the command. Forexample, ALLOCATE, require single quotation marks around fully-qualified dataset names.
ALLOC DA('USERID.MYREXX.EXEC') F(SYSEXEC) SHR REUSE
Using Variables: When a variable is used in a TSO/E command, the variablecannot be within quotation marks if its value is to be substituted. Only variablesoutside quotation marks are processed by the language processor.When a variable represents a fully-qualified data set name, the name must beenclosed in two sets of quotation marks to ensure that one set of quotation marksremains as part of the value.
name = " 'project.rel1.new' "
"LISTDS" name "STATUS"
Executing EXEC : To explicitly invoke another exec from within an exec, issuethe EXEC command as you would any other TSO/E command."EXEC myREXX.exec(calc) '24 55 12 38' "
You might want to invoke an exec with the EXEC command rather than as anexternal routine when the exec is not within the same PDS as the calling exec, orwhen the PDSs of the two execs are not allocated to either SYSEXEC orSYSPROC.
7/27/2019 Rexx1
65/115
Stacks and Related commands
NEWSTACK and DELSTACK command
The NEWSTACK command creates a new data stack which
becomes current stack
Example
NEWSTACK
DELSTACK host REXX command
The DELSTACK command removes the data stack and deletes all
elements from it.
Example
DELSTACK /*removes stack */
NEWSTACK
DELSTACK
7/27/2019 Rexx1
66/115
PUSH instruction- Put an element at the top of the datastack
Description
The PUSH instruction places a new element at the top of the data
stack.
expression is the element to be placed in the data stack.
Example
line = WallyMagoo
PUSH line /* place line at the top of the stack */
PUSH expression
7/27/2019 Rexx1
67/115
PULL instruction- Get an element from the top of the data
stack
Description
THE PULL INSTRUCTION READS THE TOP ELEMENT OF DATA
STACK AND USES IT AS SOURCE DATA. IF THE DATA STACK IS
EMPTY, THEN PULL WILL READ FROM THE TERMINAL. THE
PULL INSTRUCTION IS THE SAME AS THE REXX INSTRUCTION
PARSE UPPER PULL
template CONSISTS OF ALTERNATING PATTERNS AND
VARIABLE NAMES.
EXAMPLE
SAY PLEASE ENTER YOUR FIRST NAME:
PULL NAME.
PULL template
7/27/2019 Rexx1
68/115
EXECIO command-Read and write data
Read Operation
Write operation
THE EXECIO REXX COMMAND IS USED TO READ OR WRITE DATA TO OR
FROM DATASETS AND PDS MEMBERS. IT PERFORMS THE FOLLOWING
OPERATIONS
READ DATA FROM FILE AND PLACE IN DATA STACK
READ DATA FROM FILE AND PLACE IN VARIABLES
READ DATA FROM DATA STACK AND WRITE TO FILE
READ DATA FROM VARIABLES AND WRITE TO FILE
LINES IS THE NUMBER OF LINES TO READ OR WRITE
DISKR MEANS A READ OPERATION.
DISKRU MEANS A READ OPERATION FOR UPDATE
DISKW MEANS A WRITE OPERATION.
LINENUM IS THE RECORD NUMBER FOR READ OPERATION
FINIS MEANS TO CLOSE THE FILE AFTER A READ OR WRITE OPERATION
LIFO/FIFO MEANS TO WRITE TO THE DATA STACK IN LAST-IN-FIRST-OUT
SEQUENCE OR FIRST-IN-FIRST-OUT SEQUENCE.
SKIP MEANS TO ONLY READ THE NUMBER OF RECORDS CONTAINED IN
LINES, AND NOT TO WRITE THEM TO THE DATA STACK.
STEM SPECIFIES THE NAMES OF VARIABLES TO WHICH DATA ARE
WRITTEN OR FROM WHICH DATA ARE READ.
EXECIO [lines or *] [ DISKR or DISKRU ] ddname
[ linenum or 1 ]
[ ( [ [FINIS] [ LIFO or FIFO or SKIP ] ] or
[ STEM var [FINIS] ] [ ) ]
EXECIO [ lines or * ] DISKW ddname[( [STEM var ] [FINIS ] [ ) ] ]
7/27/2019 Rexx1
69/115
EXECIO command-Read and write data
After completion of EXECIO, command variable RC is set to the following codes:0-Successful completion1-Data truncated during a write operation
2-End of file reached20-Fatal error
Example
1. To open a data set without reading any records, put a zero immediatelyfollowing the EXECIO command and specify the OPEN operand.
"EXECIO 0 DISKR mydd (OPEN"
2. To read a specific number of lines, put the number immediately following the
EXECIO command.
"EXECIO 25 ..."
3. To read the entire data set, put an asterisk immediately following the EXECIOcommand.
"EXECIO * DISKR TEMP (FINIS STEM A"
Here EXECIO performs a diskread operation of a preallocated file using a TSOALLOC instruction and the all records are placed in the stem variable A. Do notuse the FINIS option if you want the next EXECIO statement in your exec to
continue reading at the line immediately following the last line read.
4. "ALLOC F(IN) DA('"DDNAME"') SHR"'EXECIO * DISKR IN ( FINIS'/* COPY FILE ONTO STACK */
5. To read just 5 lines to the data stack starting at line 100, write the following:
"EXECIO 5 DISKR myindd 100 (FINIS"
6. To open a data set at line 100 without reading lines to the data stack, write the
following:
"EXECIO 0 DISKR myindd 100 (OPEN"
If the data set is already open, no operation is performed for OPEN.
7/27/2019 Rexx1
70/115
EXECIO Example
/***************************** REXX *********************************//* This exec copies records from data set 'my.input' to the end of *//* data set 'my.output'. Neither data set has been allocated to a *//* ddname. It assumes that the input data set has no null lines. */
/********************************************************************/"ALLOC DA('my.input') F(indd) SHR REUSE""ALLOC DA('my.output') F(outdd) MOD REUSE"SAY 'Copying ...'"EXECIO * DISKR indd (FINIS"QUEUE '' /* Insert a null line at the end to indicate end of file */"EXECIO * DISKW outdd (FINIS"
SAY 'Copy complete.'"FREE F(indd outdd)"EXIT 0
/***************************** REXX ***********************************//* This exec reads five records from the data set allocated to */
/* MYINDD starting with the third record. It strips trailing blanks *//* from the records, and then writes any record that is longer than *//* 20 characters. The file is not closed when the exec is finished. *//***********************************************************************"EXECIO 5 DISKR myindd 3"D O I = 1 t o 5
PARSE PULL linestripline = STRIP(line,t)len = LENGTH(stripline)
IF len > 20 THENSAY 'Line' stripline 'is long.'
ELSE NOPEND
/* The file is still open for processing */
EXIT 0
7/27/2019 Rexx1
71/115
2.8 Debugging EXECS
2.8.1 Tracing Commands with the TRACE Instruction
The TRACE instruction has many options for various types of tracing, two ofwhich are "commands" or "c" and "error" or "e".
TRACE C: When you specify "trace c" in an exec, any command that follows istraced before it is executed, then it is executed, and the return code from thecommand is displayed.
E.g.:- Trace ? C?- is the prefix which means enables interactive tracing
If an exec includes "trace c" and again incorrectly issues a command, the execdisplays the line number and the command, executes it, and displays the errormessage and the return code from the command
TRACE E: When you specify "trace e" in an exec, any host command that resultsin a nonzero return code is traced after it executes and the return code from thecommand is displayed.
7/27/2019 Rexx1
72/115
2.8.2 Using REXX Special Variables RC and SIGL
RC: RC stands for return code and is set every time a command is issued. Whena command ends without error, RC is usually set to 0. When a command ends in
error, RC is set to whatever return code is assigned to that error.
The RC variable can be especially useful in an IF instruction to determine whichpath an exec should take.
'ALLOC DA('dsname') F(SYSPROC) SHR REUSE'IF RC \= 0 THEN
CALL error1
ELSE NOP
The value of RC is set by every command and might not remain the same for the
duration of an exec. When using RC, make sure it contains the return code of thecommand you want to test.
SIGL: The SIGL special variable is used in connection with a transfer of controlwithin an exec because of a function, or a SIGNAL or CALL instruction. When thelanguage processor transfers control to another routine or another part of theexec, it sets the SIGL special variable to the line number from which the transferoccurred.
SIGL and the SIGNAL ON ERROR instruction can help determine what commandcaused an error and what the error was. When SIGNAL ON ERROR is included
in an exec, any host command that returns a nonzero return code causes atransfer of control to a routine named "error".
Example/* REXX */
SIGNAL ON ERROR"ALLOC DA(new.data) LIKE(old.data)"
"LISTDS ?"
EXITERROR:
SAY 'The return code from the command on line' SIGL 'is' RC
7/27/2019 Rexx1
73/115
Debugging EXECs
WHEN YOU ENCOUNTER AN ERROR IN AN EXEC, THERE ARE
SEVERAL WAYS TO LOCATE THE ERROR.
THE TRACE INSTRUCTION DISPLAYS HOW THE LANGUAGE
PROCESSOR EVALUATES EACH OPERATION.
SPECIAL VARIABLES, RC AND SIGL, ARE SET BY THE
SYSTEM TO INDICATE
THE RETURN CODE FROM A COMMAND - (RC)
THE LINE NUMBER FROM WHICH THERE WAS A
TRANSFER OF CONTROL BECAUSE OF A FUNCTION
CALL, A SIGNAL INSTRUCTION, OR A CALL INSTRUCTION
(SIGL).
7/27/2019 Rexx1
74/115
2.9 Compound Variables And STEM
Compound variables are a way to create a one-dimensional array or a list ofvariables in REXX. Subscripts do not necessarily have to be numeric. A
compound variable contains at least one period with characters on both sides ofit. The following are examples of compound variables.
FRED.5Array.Row.Colemployee.name.phone
The first variable in a compound variable always remains a symbol with nosubstitution. The remaining variables in a compound variable take on valuespreviously assigned. If no value was previously assigned, the variable takes onthe uppercase value of the variable name.
You can use a DO loop to initialize a group of compound variables and set up anarray.
D O i = 1 T O 6
SAY 'Enter an employee name.'
PARSE PULL employee.iEND
STEMS : When working with compound variables, it is often useful to initialize an
entire collection of variables to the same value. You can do this easily with astem. A stem is the first variable name and first period of the compound variable.Thus every compound variable begins with a stem. The following are stems:FRED.Array.employee.
you can alter all the compound variables in an array through the stem. you canalter all the compound variables in an array through the stem.assignmentinstruction:
employee. = 'Nobody'
As a result, all compound variables beginning with employee. , whether or notthey were previously assigned, return the value Nobody. Compound variables thatare assigned after the stem assignment are not affected
SAY employee.5/* Displays 'Nobody' */
You can use stems with the EXECIO command when reading to and writing froma data set. You can also use stems with the OUTTRAP external function whentrapping command output:
7/27/2019 Rexx1
75/115
2.10 Sample REXX Program
/*REXX*/
/* THIS PROGRAM ENCRPYTS/DECRYPTS A DATA SET*//* USAGE : TSTMAC CODE DDNAME1 DDNAME2 KEY*/PARSE ARG CODE DDNAME1 DDNAME2 KEYALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ 'SUB = 'ZYXWABCDVU TSRQPONMLKJIHGFE'/* FOR ENCRYPTION THIS MACRO REPLACES THE CHARACTER WITH THE *//*CORRESPONDING CHARACTER IN SUB */
ADDRESS TSO"ALLOC F(IN) DA('"DDNAME1"') SHR""ALLOC F(OUT) DA('"DDNAME2"') SHR"'EXECIO * DISKRU IN ( FINIS STEM Q'FIRST_CHARACTER = 1IF RC > 0 THEN DO
SAY 'ERROR IN ALLOCATE FILE .EXITING ..'EXITENDDO LINE = 1 TO Q.0 /*FOR EACH LINE*/
LINE_LENGTH = LENGTH(Q.LINE)DO CHARACTER=1 TO LINE_LENGTH/*FOR EACH CHARACTER*/
CH = SUBSTR(Q.LINE,CHARACTER,1)IF KEY = '' THEN/* IF KEY IS NOT SPECIFIED */
CH = GET_SUB(CODE,CH) /*ENCRYPTION BY SUBSTITUTION*/ELSE
CH = BITXOR(CH,KEY)/* ENCRYPTION BY XOR BETWEEN CH AND*//*KEY*/
IF CHARACTER = FIRST_CHARACTER THENP.LINE = CH
ELSEP.LINE = P.LINE!!CH
ENDEND'EXECIO * DISKW OUT ( FINIS STEM P'"FREE F(IN)""FREE F(OUT)"EXIT
7/27/2019 Rexx1
76/115
/*THIS PROCEDURE RETURNS THE REPLACEMENT CHARACTER*/GET_SUB : PROCEDURE EXPOSE SUB ALPHABETARG CODE1,CH1D O I = 1 T O 2 7
IF CODE1 = 'E' THENIF SUBSTR(ALPHABET,I,1) = CH1 THEN
RETURN SUBSTR(SUB,I,1)
ELSENOP
ELSEIF SUBSTR(SUB,I,1) = CH1 THEN
RETURN SUBSTR(ALPHABET,I,1)ELSE
NOPENDRETURN CH1
7/27/2019 Rexx1
77/115
2.11 REXX Coding Standards
CCI designed a REXX coding standard. It mentions about naming conventions ofvariable names, Program structure, coding structure, naming convention of dialog
components like panels, skeletons, tables. Refer to current version of REXXcoding standards.
7/27/2019 Rexx1
78/115
3. ISREDIT MACROS
You can use edit macros, which look like ordinary editor commands, to extend
and customize the editor. You create an edit macro by placing a series ofcommands into a data set or member of a partitioned data set. Then you can run
those commands as a single macro by typing the defined name in the
commandline.
7/27/2019 Rexx1
79/115
EDIT MACROS
Edit macros are used to extend and customize the editor
You create an edit macro by placing a series of commandsinto a data set or member of a partitioned data set.
Edit macros can contain edit assignment statements that
communicate between a macro and the editor.
Edit macros can be either CLISTs or REXX EXECs , or
program macros written in a programming language (such as
FORTRAN, PL/I, or COBOL). Edit macros have access to the dialog manager and system
services.
All edit macros must have an ISREDIT MACRO statement as
the first edit command.
You can use edit macros to:
Perform repeated tasks
Simplify complex tasks
Pass parameters
Retrieve and return information
7/27/2019 Rexx1
80/115
3.1 ISPF/PDF Macro Command Descriptions Index
ISPF/PDF macros may contain entries that may be a command, an assignment
statement or either. The column 'Type' indicates which way a particular macrocommand may be used; c = command only, a = assignment statement only, orc/a = either.
MACRO TYPE DESCRIPTION
AUTOLIST c/a set or obtain current autolist mode
AUTONUM c/a set or obtain current autonum mode
AUTOSAVE c/a set or obtain current autosave mode
BLKSIZE a obtain blocksize of current data set
BOUNDS c/a set or obtain left and right boundary columns
BUILTIN c execute a built-in edit commandCANCEL c end an edit session without saving latest
changes
CAPS c/a set or obtain current caps mode
CHANGE c search for a string and change it to anotherstring
CHANGE_COUNTS a obtain number of changed strings
COPY c copy a PDS member or data set into currentdata
CREATE c create a new PDS member from the currentdata
CTL_LIBRARY a obtain LMF library lock status
CURSOR c/a set or obtain current cursor position
DATA_CHANGED a obtain current status of changed data
DATA_WIDTH a obtain logical data width
DATAID a obtain data ID for current data set
DATASET a obtain current data set name
DEFINE c define a session-only macro command,program or alias
DELETE c delete selected lines from current data set
DISPLAY_COLS a obtain column numbers of displayed data
DISPLAY_LINES a obtain top and bottom line numbers ofdisplayed data
DOWN c scroll down a variable line amount
EDIT c invoke another edit session
END c end the current edit session, saving the data
EXCLUDE c exclude selected lines from the display
EXCLUDE_COUNTS a obtain line counts from last EXCLUDEcommand
FIND c find a search string in any or selected displaylines
FIND_COUNTS a obtain line counts from last FIND commandFLOW_COUNTS a obtain line counts from last TFLOW command
HEX c/a set or obtain hexadecimal display mode
IMACRO c/a set or obtain the initial edit macro
INSERT c create one or more blank lines for new data
7/27/2019 Rexx1
81/115
MACRO TYPE DESCRIPTION
LABEL c/a set or obtain a line label
LEFT c scroll display data to the left
LEVEL c/a set or obtain library member modification level
LINE a set or obtain line data values
LINE_AFTER a add a specific-data line after indicated lineLINE_BEFORE a add a specific-data line before indicated line
LINENUM a obtain current line number of a given label
LOCATE c locate a specific data line
LRECL a obtain the logical record length
MACRO c identify a command as a macro
MACRO_LEVEL a obtain current macro nesting level
MASKLINE a set or obtain mask line value
MEMBER a obtain the current member name
MEND c end a batch macro in MVS/370 environment
MODEL c copy a development model into the currentdata
MOVE c move a library member into the current data
NONUMBER c turn off number mode of the current data
NOTES c/a set or obtain the current note mode
NULLS c/a set or obtain the current nulls mode
NUMBER c/a set or obtain the current number mode
PACK c/a set or obtain the current pack mode
PROCESS c process input line commands and changes
PROFILE c/a define, switch, lock, unlock and display edit
profileRANGE_CMD a identify an entered key command
RCHANGE c repeatedly process the most recent CHANGErequest
RECFM a obtain the current data record format
RECOVERY c/a set or obtain the edit recovery mode
RENUM c turn on number mode and renumber all datalines
REPLACE c replace a data set member
RESET c reset the line command area
RFIND c repeat a find of a search string
RIGHT c scroll the data to the right
RMACRO c/a set or obtain current recovery macro name
SAVE c save the current data into a data set
SCAN c/a set or obtain the current scan mode setting
SEEK c seek a data string and place cursor on thatline
SEEK_COUNTS a obtain counts from last SEEK command
SHIFT ( c shift all columns to the left
SHIFT ) c shift all columns to the right
SHIFT < c shift program statements to the left
SHIFT > c shift program statements to the rightSORT c sort data into a indicated order
STATS c/a set or obtain PDS member statistics
SUBMIT c submit data to run as a batch job
7/27/2019 Rexx1
82/115
MACRO TYPE DESCRIPTION
TABS c/a set or obtain the tabs mode and define tabcharacter
TABSLINE a set or obtain the tabs line
TENTER c set text entry mode for multi-line "power
typing"TFLOW c text flow a paragraph to restructure
fragmented pieces
TSPLIT c text split a line, moving some data to the nextline
UNNUMBER c remove sequence numbers and set numbermode off
UP c scroll up through the data a specified amount
USER_STATE a save and restore the user status of the editdisplay
VERSION c/a set or obtain the ISPF library member versionnumber
XSTATUS a set or obtain a lines exclude status
7/27/2019 Rexx1
83/115
3.2 ISPF/PDF Edit Macro Commands
Commonly used edit macros commands like Bound, change, Cursor, Edit aredescribed in this sections.
7/27/2019 Rexx1
84/115
BOUNDS ISPF/PDF Edit Macro Command
Setting of Left and Right boundaries
Assignment of current boundaries in variables
The 'lcol' parameter is the left boundary column value, which will
be set. The 'rcol' parameter is the right boundary column value tobe set. The 'lvar' and 'rvar' parameters are the names of the
variables that will receive the current left and right boundaries
respectively.
ISREDIT BOUNDS lcol rcol
ISREDIT (lvar, rvar) = BOUNDS
7/27/2019 Rexx1
85/115
The BOUNDS macro allows for the setting of the left and right boundaries andsaving them in the edit profile. The assignment statement form of the BOUNDSmacro provides the current boundaries values in variables.
If both the BOUNDS macro command and the BOUNDS line command are used
at the same time, then the BOUNDS line command will override the macrocommand.
Possible return codes are:
0 - the command or statement ended successfully4 - the specified right boundary is greater than the default, so thedefault will be used12 - one or more of the specified boundaries is invalid20 - a critical error has occurred
Example #1 - the default boundaries will be set:
ISREDIT BOUNDS
Example #2 - set the right boundary to column 72, while leaving the leftboundary alone by specifying an asterisk("*"):
ISREDIT BOUNDS * 72
Example #3 - obtain the current left boundary and put into variable &L:
ISREDIT (L) = BOUNDS
7/27/2019 Rexx1
86/115
The CANCEL ISPF/PDF Edit Macro Command
Terminate an edit session
Undo the changes since the beginning of last save
The following is an example of the CANCEL macro command:
ISREDIT CANCEL
This will cause the current edit session to be cancelled.
Possible return codes are:
0 - the command or statement ended successfully
20 - a critical error has occurred
ISREDIT CANCEL
7/27/2019 Rexx1
87/115
The FIND ISPF/PDF Edit Macro Command
THE FIND MACRO COMMAND MAY BE USED TO FIND A
SEARCH STRING IN ANY OR SELECTED DISPLAY LINES
str is the string that will be searched for
col1 and col2 are optional range of column numbers that may be usedto limit the search done by the FIND command
'label1 label2' parameter identifies two labels that specify a range of lines
that will searched by the FIND macro command. The defaults are thelabels .ZFIRST and .ZLAST
The default NEXT parameter indicates the search will begin at the nextposition after the cursor and will scan forward to the next occurrence
The 'ALL' parameter indicates the search will begin at the top of the data
and will scan ahead to find all occurrences of the string
The 'FIRST' parameter indicates the search will begin at the top of thedata, but it will stop at the first occurrence of the string
The 'LAST' parameter indicates the search will begin at the bottom of thedata and scan backwards to locate the last occurrence of the string
The 'PREV' parameter indicates the search will begin at the current
cursor location and scan backward to locate the previous occurrence ofthe string
The 'PREFIX' parameter indicates the string must be found as a prefix ofa word
The 'SUFFIX' parameter indicates the string must be found as a suffix of a
word The default 'CHARS' parameter indicates the string may be found
anywhere the characters match
The parameter 'WORD' indicates the string will be found when it issurrounded by blanks, or other alphanumeric characters, on both sides
The 'X' parameter indicates only excluded lines are searched. The 'NX'parameter indicates only non-excluded lines are searched
ISREDIT FIND str {col1 {col2 } }
{label1 label2}
{NEXT } {ALL } {FIRST} {LAST } {PREV}
{CHARS } {PREFIX} {SUFFIX} {WORD }
{X} {NX}
7/27/2019 Rexx1
88/115
String to be searched is any one of the followingSimple string - Not case sensitiveHex string - eg. Xc27BCharacter string - Case sensitive (start with c) eg. CDonPicture string - starts with p eg. P
Possible return codes are:
0 - the command or statement ended successfully4 - the search string was not found12 - an error was detected with the syntax20 - a critical error has occurred
The following are examples of the FIND macro command:
Example #1 - find lines that contain the letters THEN:
ISREDIT FIND C'THEN'
Example #3 - find first line between .A and .C with prefix of THEN:
ISREDIT FIND THEN .A .C FIRST PREFIX
Example #4 - find last excluded line from .A to .B with suffix of THEN:
ISREDIT FIND THEN .A .B LAST SUFFIX X
Example #5 - find the first preceding non-excluded line within labels.A and .C with a word equal to THEN in columns 1 through 5:
ISREDIT FIND THEN .A .C PREV WORD 1 5 NX
Example#6 Find all the 4 digit numerals in 8 th column
"ISREDIT F P'####' 8 ALL"
Example#7 : Find all strings matching the pattern -anteil- followed by 2 digitnumber.
ISREDIT F P'-anteil-##' ALL
7/27/2019 Rexx1
89/115
The EXCLUDE ISPF/PDF Edit Macro Command
THE EXCLUDE MACRO COMMAND MAY BE USED TO EXCLUDE LINES
FROM THE DISPLAY BY REPLACING LINES CONTAINING A SEARCH
STRING WITH A DASHED LINE UNTIL A RESET OR RESET EXCLUDED
COMMAND IS ISSUED.
The EXCLUDE command may be used with the FIND or CHANGE commands
to locate a string, change the string, and then exclude that line from the
display.
str is the string that will be searched for, to exclude lines
col1 and col2 are the optional range of column numbers
label1 and label2 are range of line numbers that will be searched by
exclude command
NEXT or ALL or FIRST or LAST or PREV denotes the search order
PREFIX parameter indicates string must be found as a prefix of a word.
SUFFIX parameter indicates string must be found as a suffix of a word.
The default 'CHARS' parameter indicates the string may be found
anywhere the characters match.
The parameter 'WORD' indicates the string will be found when it is
surrounded by blanks, or other non-alphanumeric characters, on both
sides
ISREDIT EXCLUDE str col1 col2 label1 label2{NEXT or ALL or FIRST or LAST or PREV }
{CHARS or PREFIX or SUFFIX or WORD}
7/27/2019 Rexx1
90/115
Examples:
Example #1 - exclude lines that contain the letters THEN:ISREDIT EXCLUDE THEN
Example #2 - exclude last line between .A and .B with suffix of THEN:ISREDIT EXCLUDE THEN .A .B LAST SUFFIX
Example #3- exclude the first preceding line within labels .A and .C with a wordequal to THEN in columns 1 through 5:
ISREDIT EXCLUDE THEN .A .C PREV WORD 1 5
Possible return codes are:
0 - the command or statement ended successfully4 - the search string was not found8 - no lines were excluded20 - a critical error has occurred
7/27/2019 Rexx1
91/115
The XSTATUS ISPF/PDF Edit Macro Command
THE XSTATUS ASSIGNMENT STATEMENT MAY BE USED TO
SET THE EXCLUDE STATUS OF A LINE
OBTAIN THE EXCLUDE STATUS OF THE SPECIFIED LINE BY
STORING IT IN A VARIABLE
THE EXCLUDE COMMAND SHOULD BE USED TO EXCLUDE
SEVERAL LINES AT ONE TIME AND THE FIND COMMAND
SHOULD BE USED TO DISPLAY SEVERAL LINES, THAT WERE
EXCLUDED, AT ONE TIME.
EXAMPLE #1 - EXCLUDE LINE NUMBER 6:
ISREDIT XSTATUS 6 = X
EXAMPLE #1 - STORE THE EXCLUDE STATUS OF LINE &LN IN
VARIABLE &EXCLSTAT:
ISREDIT (EXCLSTAT) = XSTATUS &LN
ISREDIT (var) = XSTATUS lnptr
ISREDIT XSTATUS lnptr = X or NX
7/27/2019 Rexx1
92/115
CHANGE ISPF/PDF Edit Macro Command
THE CHANGE MACRO COMMAND PERFORMS A SEARCH FOR A STRINGAND CHANGES IT TO ANOTHER STRING.
THE 'STR1' PARAMETER IS THE EXISTING STRING TO BE SEARCHEDFOR. THE 'STR2' PARAMETER IS THE STRING THAT 'STR1' WILL BECHANGED TO.
LBLS PARAMETER SPECIFIES THE RANGE OF LABELS TO BESEARCHED
NEXT OR PREV OR ALL OR FIRST OR LAST DENOTES THE SEARCH
ORDER.
CHARS OR PREFIX OR SUFFIX OR WORD MEANS THE STRING ISCONSIDERED AS A WORD OR PREFIX OR SUFFIX OR CHARS FOR THE
SEARCH
THE X/NX MEANS WHETHER THE STRING TO BE SEARCHED ONEXCLUDED LINES OR NON-EXCLUDED LINES
THE 'COL1' AND 'COL2' PARAMETERS SPECIFY A BEGINNING AND
ENDING COLUMN NUMBER RESPECTIVELY THAT WILL BE USED TOLIMIT THE SEARCH.
ISREDIT CHANGE str1 str2
[ lbls][ NEXT Or ALL Or FIRST Or LAST Or PREV ]
[ CHARS Or PREFIX Or SUFFIX Or WORD ]
[ X Or NX ]
[ col1 ] [col2 ]
7/27/2019 Rexx1
93/115
CHANGE ISPF/PDF Edit Macro Command
The following are examples of the CHANGE macro command:
Example #1:
ISREDIT CHANGE ME YOUThis example, the next occurrence of ME is changed to YOU. The letters ME canbe upper, lower or mixed case letters, and may be located anywhere within aword, on any line
Example #2:
ISREDIT (CURMEM) = MEMBERISREDIT CHANGE WORD &CURMEM "MEMBER:&CURMEM" 1 20 .ZFIRST.LAB9In this example, the current member name is put it into the variable named
CURMEM, then an identifier is added to that name, when it appears in columns 1through 20 in the lines from the beginning to the label of .LAB9.
Possible return codes are:
0 - the command or statement ended successfully4 - the specified string 'str1' was not found8 - the string 'str1' could not be changed to 'str2' because 'str2' is longer than 'str1'and there was no substitution on at least one change.12 - the string 'str1' does not fit between the specified columns20 - a critical error has occurred
7/27/2019 Rexx1
94/115
The DELETE ISPF/PDF Edit Macro Command
THE DELETE MACRO MAY BE USED TO DELETE LINES FROM
THE DATA BEING EDITED. DELETE CAN SPECIFY A SINGLE
LINE OR A RANGE OF LINES. IT CAN LIMIT THE LINES TO BE
DELETED TO ALL EXCLUDED OR NONEXCLUDED LINES IN THE
DATA, OR TO ALL EXCLUDED OR NONEXCLUDED LINES
WITHIN A LINE POINTER RANGE.
ALL indicates all matching lines will be deleted
'X ! NX' parameters indicate the lines being deleted will be
those that are excluded or not excluded, respectively.
The 'lptr' parameter indicates a label or relative line number is
to be used to specify which lines will be deleted.
The 'lrange' parameter indicates a range of relative line
numbers or labels specifying the range of lines to be deleted.
When either one is omitted, then one of the defaults, .ZFIRSTand .ZLAST, will be used.
ISREDIT DELETE { ALL X or NX [lptr-range]}
{[ALL] X or NX lptr-range}
{lptr}
{lptr-range}
7/27/2019 Rexx1
95/115
Example #1 - delete all non-excluded lines:ISREDIT DELETE ALL NX
Example #2 - delete the lines between labels .HERE and .THERE that have ablank in column 1:
ISREDIT RESET X .HERE .THEREISREDIT EXCLUDE ALL " " 1 .HERE .THEREISREDIT DELETE ALL X .HERE .THERE
Example #3 - delete the last line of the current data set:
ISREDIT DELETE .ZLAST
Example #4 - delete the first 15 lines of current data set:
ISREDIT DELETE 1 15
Possible return codes are:
0 - the service ended successfully, deleting the lines4 - no lines were deleted8 - no standard records exist to be deleted12 - a line number was invali