OS/2 Procedures Language 2/REXX


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Instructions


An instruction tells the system to do something.  Instructions can contain 
one or more assignments, labels, or commands and they usually start on a 
new line.  The following are explanations of some of the more common 
instructions. 
SAY Instruction - The format for the SAY instruction is: 

SAY expression

The expression can be something you want displayed on the screen or 
something to be computed, such as an equation: 

SAY 5 + 6 "= eleven"

This displays 

11 = eleven

With the SAY instruction, anything not in quotation marks is changed to 
uppercase or is processed.  If you want something to appear exactly as it 
is typed, enclose it in quotation marks. 
PULL and PARSE PULL Instructions - 
In a procedure, the usual sequence of instructions is to use SAY to ask a 
question and PULL to receive the answer.  The response typed by the user 
is put into system memory.  The following procedure does not work 
correctly if the PULL instruction comes before the SAY instruction. 
Question:   What do you think happens when the following procedure, 
NAME.CMD, is run? 

/* Using the PULL Instruction */
SAY "Enter your name"
PULL name          /* Puts response
from user into memory */
SAY "Hello" name
EXIT

Answer:   NAME.CMD puts a name in memory and then displays that name 
anywhere in the file that the word name appears without the protection of 
single or double quotation marks. 
If you tried the NAME procedure, you probably noticed that your name was 
changed to uppercase.  To keep the characters as you type them, use the 
PARSE PULL instruction.  Here is an example called CHITCHAT.CMD that uses 
the PARSE PULL instruction: 

/* Using the PARSE PULL Instruction */
SAY "Hello! Are you still there?"
SAY "I forgot your name.  What is it?"
PARSE PULL name
SAY name "Are you going to Richard's seminar?"
PULL answer
IF answer = "YES"
 THEN
 SAY "Good.  See you there!"
IF answer = "NO"
 THEN
 SAY "Sorry,  We will miss your input."
EXIT
The PARSE PULL instruction reads everything from the keyboard exactly as 
it is typed, in uppercase or lowercase.  In this procedure, the name is 
displayed just as you type it.  However, answer is changed to uppercase 
characters because the PULL instruction was used.  This ensures that if 
yes, Yes, or YES is typed, the same action is taken. 
EXIT Instruction 
The EXIT instruction tells the procedure to end.  The EXIT instruction 
should be used in a procedure that contains subroutines.  Although the 
EXIT instruction is optional in some procedures, it is good programming 
practice to use it at the end of every procedure.   

Inf-HTML End Run - Successful