1 / 45

# Module Objectives - PowerPoint PPT Presentation

z/VM Module 6: The REXX Programming Language. Module Objectives. Data structures IF-THEN-ELSE SELECT LOOPS Data formats An example of formatting numbers and strings are: FORMAT( )  numerical SUBSTR( )  string manipulation Input/Output (I/O) functions STREAM( ) function

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Module Objectives' - daktari

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### z/VMModule 6: The REXX Programming Language

• Data structures

• IF-THEN-ELSE

• SELECT

• LOOPS

• Data formats

• An example of formatting numbers and strings are:

• FORMAT( )  numerical

• SUBSTR( )  string manipulation

• Input/Output (I/O) functions

• STREAM( ) function

• CHARIN, LINEIN, CHAROUT, LINEOUT instructions

• Parameters

• To retrieve parameters use:

• ARG, PULL, etc.

• Describe REXX and how it works with z/VM

• Describe how to write REXX programs using:

• Keywords and literal strings

• Clauses

• Syntax error messages

• Explain the use of REXX variables with names, values, and assignments

• Understand which expressions can be used within a REXX clause:

• Operators and terms

• Comparisons (equal, and, or)

• Functions

• Learn the control statements for manipulating data flow:

• IF – THEN

• ELSE keyword

• DO LOOPS (repetitive and conditional)

• Selection

• Explain arithmetic, text, and conversational expressions for manipulating and gathering data

• Show how to issue CMS and CP commands within a REXX EXEC

• Explain the subcommands and macros used in REXX EXECs

• Introduce REXX subroutines

• REstructured eXtended eXecutor language

• A versatile, easy to use, structured programming language

• A programming language that is easy for both computer professionals and general users to learn and use

• A compiler can be used to translate REXX source programs into compiled programs

• Ease of use

• Free format

• Interpreted

• Built-in functions

• Parsing capabilities

• Powerful debugger

• Relationship with z/VM

• A REXX program is a list of instructions, something like a recipe

• A computer communicates with users through questions displayed and answers typed in

• /* . . . */, this is used for descriptions and explanations

• Comments with special meaning to CMS

• To determine you are writing a REXX program the first line must contain /* . . . */

• Keywords are instructions that describe an action, such as PULL, IF, and SAY.

• REXX reads each individual clause, then processes it before going on to the next (interpreted language).

• A literal string is a set of characters bounded by quotation marks.

• REXX processes a clause containing a variable by substituting the variable name with the stored data.

• REXX programs consist of these types of clauses:

• Instruction

• Assignment

• Label

• Null

• Commands

• Information stored in a variable is called its value.

• It is possible to make variable names anything, but a good idea to create meaningful names.

• An instruction that stores a value in a variable or changes its value is called an assignment.

• In formal terms, the syntax might look like this:

• symbol = expression

• The PULL instruction:

• Pauses the running program to allow the user to enter data

• Can be used to pull in each piece of data or allow the user to enter multiple amounts of data separated by spaces

• The ARG instruction:

• Like PULL, but data items are entered at the command prompt with the program name

• One way to write this EXEC is:

/* SUBMUL1 EXEC */

ARG first second

say first “-” second “=” first-second

say first “*” second “=” first*second

• Another way to write this EXEC is:

/* SUBMUL2 EXEC */

say “Enter two numbers to multiply and subtract.”

pull first second

say first “-” second “=” first-second

say first “*” second “=” first*second

• Operators and terms:

• Operators include +, -, /, %, *, ||

• Operators manipulate numbers, strings in quotes, variables, results from function calls and evaluated expressions

• Parentheses:

• The language processor evaluates the expression inside the parentheses first

• The value of 10 * ( 3 || 4 ) is: 340

• Comparisons:

• > Greater than

• = Equal

• < Less than

• TRUE, the computed result is 1

• say 4 < 7

• /* represents a “1”, which means TRUE */

• FALSE, the computed result is 0

• say “Chalk” = “Cheese”

• /* represents a “0”, which meaning FALSE */

• The equal sign (=) can have two meanings

• Can be an assignment if found at the beginning after the symbol

• An equal sign anywhere else stands for the comparison operator

• Use the AND (&) operator to write an expression that is true when everything else is also true

• Use the OR (|) operator when any part of an expression can be true

• Function calls can be written anywhere in an expression.

• The function performs the computation named by the function and returns the result.

• When the value of the function has been calculated, the result is put back into the expression in place of the function call.

• An example is:

• say 7 + HALF(6) /* becomes 7 + 3 which says “10” */

• The THEN instruction may be an assignment, command, or keyword.

• The NOP instruction can be used when no operations are necessary.

• An important property of the THEN keyword is that is does not need to start a clause, therefore a semicolon is not needed.

• Another example is:

• If answer=‘YES’ then say ‘OK!’; else say ‘Why not?’

• Conditional loops continue to be executed as long as some condition is satisfied.

• The simplest way to code these loops is to use DO FOREVER and LEAVE instructions.

• There are three kinds of Conditional Loops

• The decision is made before processing starts

• Checking occurs before entering the loop and continues after each iteration.

• The decision is made after the first pass through the loop and again after every subsequent pass.

• Data is requested for the user.

• The decision is made during each pass.

• The decision to leave might depend on information obtained during the loop.

SELECT

WHEN morning THEN DO

say “Take shower”

say “Eat breakfast.”

end

WHEN afternoon THEN DO until ans=Y

say “Did you eat lunch? (Y/N)

PARSE UPPER PULL ans

end

otherwise say “It is in the evening -- get ready for bed!!”

end

• The addition, subtraction and multiplication operations are performed in the usual way.

• -  Subtraction

• *  Multiplication

• **  Power function

• The result of a % operation is the whole number portion. The remainder is dropped.

• The result of a // operation is the remainder portion. The whole number is dropped.

• The result of a / operator is a combination of both operations above.

• SUBSTR() Function:

• To select a part of a string to use:

• WORD = “reveal”

• say substr(WORD, 2, 3) /* says “eve” */

• LENGTH() Function:

• To find out the length of a REXX variable:

• WORD = "reveal"

• say length(WORD) /* says "6" */

• COPIES():

• Produces a number of copies of the string. The arguments are:

• The string to be copied

• The number of copies required

• LEFT():

• Obtains a string that is padded or truncated on the right

• RIGHT():

• Obtains a string that is padded or truncated on the left

• The SAY instruction and its expression are computed and the result is displayed as a new line on the screen.

• The PULL instruction is able to collect an answer that has been displayed by the SAY instruction.

• The PARSE PULL instruction brings in the data just as it is, without converting the lowercase letters to uppercase.

• The UPPER instruction translates the value of one or more variables to uppercase.

• PULL can also fetch each word into a different variable

• Using the period as a place holder in this statement (PULL . . lastname .) means to discard the first two words and assign the third word to lastname.

• The language processor can operate in a number of environments.

• Use quotes to avoid errors when writing CMS and CP commands within REXX.

• More examples:

1) access 591 591

DMSACC113S B(591) not attached or invalid device address

2) copyfile profile exec a = = b (for luck

Invalid parameter LUCK in the option FOR field

3) erase junk exec

• Advantages of compiling REXX EXECS

• Source can be hidden from end users

• Compile programs using this CMS command:

• REXXD [source-file-identifier]

• The first word on the command line is assumed to be a subcommand

• Words that are not subcommands are interpreted as macros

• REXX was created as a procedural language that allows programs and algorithms to be written in a clear and structured way.

• Topics in this module:

• Clauses

• Variables

• Expressions

• Control statements:

• IF THEN

• ELSE

• Loops

• Selection

Clause – a line of code or a statement within a REXX program

Parsing – manipulates character strings to let your program read and separate characters, number, and mixed inputs

PL/I – was developed as the universal programming language, where definitions were not needed

• REXX – REstrutured eXtneded eXecutor language, a versatile, easy to use structured programming language that is an integral part of z/VM.

• REXXCompiler – translates REXX source programs into compiled programs. (Compiled programs run much faster than interpreted programs.)

z/VM: REXX/VM User’s Guide –Version 3 Release 1.0  SC24-5962-00

The REXX Language: A Practical Approach to Programming –by Michael Cowlishaw

Website: Rexx Language Association