If youve never seen REXX code, this is the section for you. Well write a simple program to exercise some of the most common REXX functions and then turn you loose to create your own programs.
Start with your editor of choice. If you have no preference, use the OS/2 System Editor. In an OS/2 window, simply type the following:
e RexxProg.cmd All REXX programs must have .CMD as their extension. Type the code shown in Figure 1 into the editor window. This code prompts you to enter your name, then displays a message telling you the number of letters in your name.
The program starts by prompting you to enter some data, using the SAY terminal output keyword. PULL waits for you to enter data. After typing data and pressing the Enter key, the variable NAME is set to the value you typed. The variable Y is set to 0. (REXX doesnt require variables to be explicitly defined. It determines their type by their assignment.) We then enter a DO loop to iterate once for each letter in the NAME you entered. We use the LENGTH function to determine the number of characters in the value of NAME. Inside the loop, we use the SUBSTR function to echo the selected letter of NAME for a length of 1. We then increment Y. When we exit the loop, we build a report string. The double-bar characters tell REXX to concatenate strings. The final SAY command connects two variables and a literal.
Save the program and exit the editor. In fact, not only save the program, but guard it carefully; many of the larger software development companies would kill to get their hands on complex code like this. :-)
From the OS/2 prompt (REXX will not run in a DOS environment), type REXXPROG (the name we assigned when we first edited the file) and compare the screen display with the code you typed.
Having gained the status of a REXX expert, youre now ready for EHLLAPI programming.
/* REXX */
say Enter your name:
pull name
y = 0
do i = 1 to length(name)
say substr(name,i,1)
y = y + 1
end i
str_1 = You
str_2 = str_1||entered
say str_2 y letter(s).
Figure 1: REXX Code for Sample Program
LATEST COMMENTS
MC Press Online