IBM zVM Module 6 The REXX Programming Language
IBM ^ z/VM Module 6: The REXX Programming Language © 2004 IBM Corporation
IBM ^ Module Objectives § Data structures 4 IF-THEN-ELSE 4 SELECT 4 LOOPS § Data formats 4 An example of formatting numbers and strings are: – FORMAT( ) numerical – SUBSTR( ) string manipulation § Input/Output (I/O) functions 4 STREAM( ) function 4 CHARIN, LINEIN, CHAROUT, LINEOUT instructions § Parameters 4 To retrieve parameters use: – ARG, PULL, etc. © 2004 IBM Corporation
IBM ^ Objectives § Describe REXX and how it works with z/VM § Describe how to write REXX programs using: 4 Comments 4 Keywords and literal strings 4 Clauses 4 Syntax error messages § Explain the use of REXX variables with names, values, and assignments © 2004 IBM Corporation
IBM ^ Objectives continued § Understand which expressions can be used within a REXX clause: 4 Operators and terms 4 Comparisons (equal, and, or) 4 Functions § Learn the control statements for manipulating data flow: 4 IF – THEN 4 ELSE keyword 4 DO LOOPS (repetitive and conditional) 4 Selection © 2004 IBM Corporation
IBM ^ Objectives continued § Explain arithmetic, text, and conversational expressions for manipulating and gathering data § Show to issue CMS and CP commands within a REXX EXEC § Explain the subcommands and macros used in REXX EXECs § Introduce REXX subroutines © 2004 IBM Corporation
IBM ^ What is REXX? § REstructured e. Xtended e. Xecutor 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 © 2004 IBM Corporation
IBM ^ Features of REXX § Ease of use § Free format § Interpreted § Built-in functions § Parsing capabilities § Powerful debugger § Relationship with z/VM © 2004 IBM Corporation
IBM ^ How a Program Works § A REXX program is a list of instructions, something like a recipe § A computer communicates with users through questions displayed answers typed in © 2004 IBM Corporation
IBM ^ Comments in REXX Programs § Comments in programs: • /*. . . */, 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 /*. . . */ © 2004 IBM Corporation
IBM ^ Keywords and Literal Strings § 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. © 2004 IBM Corporation
IBM ^ REXX Clauses § REXX programs consist of these types of clauses: • Instruction • Assignment • Label • Null • Commands © 2004 IBM Corporation
IBM ^ REXX Syntax Errors © 2004 IBM Corporation
IBM ^ REXX Variables © 2004 IBM Corporation
IBM ^ Names, Values, and Assignments § 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 © 2004 IBM Corporation
IBM ^ Other Assignments § The PULL instruction: 4 Pauses the running program to allow the user to enter data 4 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: 4 Like PULL, but data items are entered at the command prompt with the program name © 2004 IBM Corporation
IBM ^ Assignments and Instructions § One way to write this EXEC is: /* SUBMUL 1 EXEC */ ARG first second say first “-” second “=” first-second say first “*” second “=” first*second § Another way to write this EXEC is: /* SUBMUL 2 EXEC */ say “Enter two numbers to multiply and subtract. ” pull first second say first “-” second “=” first-second say first “*” second “=” first*second © 2004 IBM Corporation
IBM ^ REXX Expressions § Operators and terms: 4 Operators include +, -, /, %, *, || 4 Operators manipulate numbers, strings in quotes, variables, results from function calls and evaluated expressions § Parentheses: 4 The language processor evaluates the expression inside the parentheses first • The value of 10 * ( 3 || 4 ) is: 340 © 2004 IBM Corporation
IBM ^ REXX Expressions (Comparison, True, and False) § 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 */ © 2004 IBM Corporation
IBM ^ REXX Expressions ( =, &, | ) § 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 © 2004 IBM Corporation
IBM ^ REXX Functions § 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” */ © 2004 IBM Corporation
IBM ^ Control Statements: IF – THEN © 2004 IBM Corporation
IBM ^ Examples and Notes: IF - THEN § 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: 4 If answer=‘YES’ then say ‘OK!’; else say ‘Why not? ’ © 2004 IBM Corporation
IBM ^ Control Statements: ELSE Keyword © 2004 IBM Corporation
IBM ^ REXX Loops © 2004 IBM Corporation
IBM ^ Repetitive DO Loops © 2004 IBM Corporation
IBM ^ Conditional DO Loops § 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. © 2004 IBM Corporation
IBM ^ Conditional Loops: The Choice § There are three kinds of Conditional Loops 4 The decision is made before processing starts – Checking occurs before entering the loop and continues after each iteration. 4 The decision is made after the first pass through the loop and again after every subsequent pass. – Data is requested for the user. 4 The decision is made during each pass. – The decision to leave might depend on information obtained during the loop. © 2004 IBM Corporation
IBM ^ The SELECT Instruction © 2004 IBM Corporation
IBM ^ A SELECT Instruction SELECT WHEN morning THEN DO say “Take shower” say “Eat breakfast. ” say “Get ready for work. ” 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 © 2004 IBM Corporation
IBM ^ Arithmetic § The addition, subtraction and multiplication operations are performed in the usual way. – – + Addition - 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. © 2004 IBM Corporation
IBM ^ Text - Concatenation © 2004 IBM Corporation
IBM ^ Text – String Manipulation § SUBSTR() Function: 4 To select a part of a string to use: – WORD = “reveal” – say substr(WORD, 2, 3) /* says “eve” */ § LENGTH() Function: 4 To find out the length of a REXX variable: – WORD = "reveal" – say length(WORD) /* says "6" */ © 2004 IBM Corporation
IBM ^ Text – String Manipulation continued § COPIES(): 4 Produces a number of copies of the string. The arguments are: § LEFT(): 4 • The string to be copied • The number of copies required Obtains a string that is padded or truncated on the right § RIGHT(): 4 Obtains a string that is padded or truncated on the left © 2004 IBM Corporation
IBM ^ Conversations – SAY and PULL § 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. © 2004 IBM Corporation
IBM ^ Conversation – Parsing Words § 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. © 2004 IBM Corporation
IBM ^ Issuing Commands to CMS and CP § The language processor can operate in a number of environments. § Use quotes to avoid errors when writing CMS and CP commands within REXX. © 2004 IBM Corporation
IBM ^ Issuing Commands – Return Codes § More examples: 1) 2) 3) access 591 DMSACC 113 S B(591) not attached or invalid device address Ready (00100); copyfile profile exec a = = b (for luck Invalid parameter LUCK in the option FOR field Ready (00024); erase junk exec File JUNK EXEC A not found Ready (00028) © 2004 IBM Corporation
IBM ^ Why Use a Compiler? § Advantages of compiling REXX EXECS 4 Source 4 Load can be hidden from end users modules are loaded into memory faster § Compile programs using this CMS command: 4 REXXD [source-file-identifier] © 2004 IBM Corporation
IBM ^ How to Use the Compiler © 2004 IBM Corporation
IBM ^ XEDIT Subcommands and Macros § The first word on the command line is assumed to be a subcommand § Words that are not subcommands are interpreted as macros © 2004 IBM Corporation
IBM ^ Subroutines © 2004 IBM Corporation
IBM ^ Conclusion § 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: 4 Comments 4 Clauses 4 Variables 4 Expressions 4 Control statements: – – IF THEN ELSE Loops Selection © 2004 IBM Corporation
IBM ^ Glossary 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 © 2004 IBM Corporation
IBM ^ Glossary § REXX – REstrutured e. Xtneded e. Xecutor 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. ) © 2004 IBM Corporation
IBM ^ References z/VM: REXX/VM User’s Guide –Version 3 Release 1. 0 SC 245962 -00 The REXX Language: A Practical Approach to Programming –by Michael Cowlishaw Website: Rexx Language Association © 2004 IBM Corporation
- Slides: 45