PC DOS 2000 REXX Programming Language
PC DOS 2000 comes with the REstructured eXtended eXecutor language (REXX), a programming language that is easy to use for most users - especially users who are not programmers - yet flexible enough for computer professionals. REXX has been part of IBM's System/370 Virtual Machine/System Product (VM/SP) since 1983. Because of its ease of use and adaptability, REXX has since been included in VM, MVS, OS/400, OS/2, and now PC DOS.
Why Use REXX?
Here are several reasons for using REXX:
- It's easy to use by everyone.
- It helps speed up your repetitive, everyday tasks.
- Your program can interact with the user of the program.
- REXX enables you to write short programs with a minimum of overhead. The programs you write are portable to other platforms that have REXX, thus reducing overall programming effort.
- REXX helps you develop prototype applications and products.
Why is REXX Easy to Use?
REXX is easy to learn and use because it consists of meaningful English words. Anyone who has a command of the English language also has a command of the REXX language. REXX uses common English words such as SAY, PULL, IF ... THEN ... ELSE, DO ... END, and EXIT.
REXX has several kinds of components, detailed below.
A comment states what a program does, what kind of input it requires, and what output it produces.
A comment begins with /* and ends with */. For example:
/* This is a comment */
You can use comments any place, but the first line of a REXX program must be a comment.
A string is a group of characters inside single or double quotes (' or "). The characters inside the quotes always remain as they were typed in (whether upper- or lower-case letters). Otherwise, REXX converts all characters that are not within strings to uppercase letters. Be sure to complete a string with the same type of quote (single or double) that you began it with. Figure 1 gives examples of strings.
Variables, also called symbols, are groups of characters that give names to data whose value might be changed during the course of executing a REXX program.
For example, in Figure 2, CUSTREG is a variable used in the REGNUM.BAT program. CUSTREG represents the customer registration number (for example, 00010505) given to the program by the user. TESTNUM represents the fourth character of the customer registration number (for example, the 1 in 00010505).
The REXX program in Figure 3, ADD2NUM.BAT, asks the user to type in two numbers, and then displays the sum on the screen. In Figure 3, the variable FIRST represents the first number the user typed, and SECOND is used to represent the second number the user typed. The variable SUM holds the sum of the numbers in FIRST + SECOND.
Instructions: Instructions tell REXX to do something. Some REXX instructions are:
- CALL, which calls a label, thereby causing the program to continue processing beginning at that label. (See Figure 5.)
- EXIT, which causes the program to stop or end.
- SAY, which displays a string on the screen.
- PULL, which receives the user's response.
For example, the following SAY instruction tells REXX to display the word HELLO on the screen:
There are also REXX keyword instructions. Keyword instructions consist of one or more clauses that start with a identifying keyword. Figure 4 gives examples of REXX keyword instructions.
For more details about REXX instructions and built-in functions, you can use the on-line REXX Command Reference that comes with PC DOS 2000. Simply type:
at the PC DOS command prompt C:\.
E Editor Accommodates REXX: PC DOS 2000's E Editor has an optional syntax-directed editing feature for REXX- language files. This feature furnishes the correct program syntax for files that have either a .BAT or .CMD file extension. Syntax-directed editing is automatically provided when you use a specific REXX keyword followed by a particular key.
For example, if you are using the E Editor to edit a REXX-language file in which the language keyword IF is followed by the space-bar key, then the Editor automatically puts in the associated THEN and ELSE keywords in the file for you.
As another example, when the keyword SELECT is followed by the Enter key, the E Editor automatically puts in the associated WHEN, THEN, OTHERWISE, and END keywords.
Labels mark the start of a subroutine (a separate program within your program), and are used to identify targets for CALL instructions. Labels must end with a colon (:).
Figure 5 illustrates use of a REXX label MYSUB. When the main program comes to the statement CALL MYSUB, it transfers control to the subroutine whose label is MYSUB. When the subroutine finishes, it returns control to the main program, to the statement following CALL MYSUB.
Assignments enable you to give values to variables. For example:
NAME = "Marie E. Wolfe"
assigns the string value "Marie E. Wolfe" (without the quote marks) to the NAME variable. The variable NAME then retains the value "Marie E. Wolfe" until (and if) another value is assigned to NAME.
A clause can be:
- An instruction
- An assignment
- A label
- A null clause (a blank line)
- A platform-specific command (see the next subject)
Normally, one clause occupies one line. To have multiple clauses on one line, separate them by a semicolon (;). If one clause spans more than one line, put a comma (,) at the end of the first line and at the ends of all subsequent lines except the last. Note: You can use blank spaces to make the program easy to read.
Commands are platform-dependent (not part of the REXX language), and therefore must be placed in quotes - either single or double quotes - so that REXX does not change the information within the quotes. Examples of PC DOS commands are COPY, XCOPY, DIR, and TYPE.
REXX comes with more than 50 built-in functions. These functions perform character manipulation and conversion, and provide specific information about variables. Figure 6 lists some REXX built-in functions.
Writing Your First REXX Program
To show you how easy it is to write a REXX program, let's write a simple program. The problem to be solved is: What is today's date and time, and what items are in my to-do list?
To accomplish this task, we need to:
- Identify and describe the REXX program.
- Print the date.
- Print the time.
- Print a "THINGS TO DO TODAY" header or title.
- Print the items in your to-do list.
- Tell REXX the program is finished.
Next, we write REXX instructions for each step. Figure 7 lists the complete program that we write. A REXX program name in PC DOS 2000 must have the file extension .BAT. Therefore, the REXX program in Figure 7 is saved in a file named TTD.BAT (short for Things To Do).
In Figure 7: Recall that a REXX program is identified by a comment on the first line. In our case, the comment is long enough to require two lines.
The SAY function writes simple messages to the screen. Use the on-line REXX Command Reference to see what the DATE and TIME built-in functions do. The words within the string "THINGS TO DO TODAY" are displayed as-is. To display the to-do list, we assume that you have a file named C:\MYTHINGS.LST, and we use the PC DOS command TYPE, placed inside quotes.
Another way to display the to-do list using only REXX functions is shown in Figure 8.
In Figure 8, the program loops while the number of lines in the C:\MYTHINGS.LST file is greater than zero. It reads each line in the file into the LINE variable and then uses the SAY instruction to print the line to the screen.
Finally, the EXIT instruction tells REXX that the program is done.
Figure 9 shows what the REXX program TTD.BAT displays on the screen.
Repetitive Everyday Tasks
You can use REXX to do everyday tasks that occur in the same sequence day after day. Figure 10 lists the REXX program MY.BAT, which does my repetitive tasks.
In Figure 10, the platform-specific commands are placed inside either single or double quotes. To be safe, anytime you use a PC DOS 2000 command in a REXX program, put it in quotes.
REXX Program Portability
REXX programs are portable between operating-system platforms. If you create a REXX program on one platform, such as PC DOS 2000, it is portable (that is, executable) on another platform that also comes with the REXX language (for example, OS/2, OS/400, VM, and MVS).
If you don't use platform-specific commands in your REXX program, the program is executable on any other platform without change. Specific commands for a platform include:
- Operating-system commands (for example, COPY and DIR)
- REXX platform-specific, built-in functions (for example, B2X and X2B)
- REXX platform-specific utilities (for example, RXCHDIR and RXCLS)
Also, make sure you use the appropriate filetype or extension for a platform (for example, OS/2's file extension for executable programs is .CMD, whereas VM's executable programs have a filetype of EXEC).
The program in Figure 2 is executable without change on all platforms that have REXX, because it contains only REXX instructions and built-in functions.
The program in Figure 1 contains the specific PC DOS 2000 command E, which you would have to change to an editor that is available on the new platform. Similarly, DOS commands such as
COPY, PRINT, and TYPE must also change to their equivalents on the new platform.
REXX Programs that Interact with the User
Figure 2 also shows how REXX can interact with the user. It's very easy to SAY (display) a question to the screen and then PULL (get) the response (or input) from the user. Depending on the response (or input) from the user, you could ask more questions or do different work.
Using REXX to Prototype Applications
Because REXX can be highly interactive and is easy to use, it facilitates rapid program development for modeling applications and products. I once used REXX to develop a program that read in customer surveys, analyzed the data, and created reports. I also used REXX to help prototype the first PC/VM File Transfer program. This prototype effort was the conception of
the 3270 PC File Transfer Program. When quick efforts are needed, look to REXX to help you get there fast.
REXX was the first language I learned when I was a secretary, and I'm still using it today as a release manager. REXX makes my jobs easier and faster. REXX is the language for everyone.
Figure 1. REXX Strings
"You can only type a letter, not a number."/* Double quotes are */
/* used to delimit */
/* this string */
'E C:\MARIE\DESIGN.STA' /* Single quotes are */
/* used to delimit */
/* this string */
(Return to Text)