Polmax Sp. z o.o; 53-015 Wrocław; Karkonoska 59; tel/fax: (71) 339-9571
Zobacz również:
nasze ośrodki

port jachtowy
Przepraszamy, ale serwis nasz jest w trakcie tworzenia i linki do poszczególnych stron jeszcze nie działają

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:

view dosrexx

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.

Built-In Functions

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              */
'12 PM'

(Return to Text)

Figure 2. REXX Program REGNUM.BAT

/* This REXX program examines a registration number for a product      */
/* and lets you know whether the customer is entitled to Service.      */
/* If position 4 = 1 then SERVICE - special release                    */
/* If position 4 = 2 then SERVICE - special agreement                  */
/* If position 4 = 3 then NO SERVICE - special release w/o service     */
/* If position 4 = 4 then NO SERVICE - special company agreement       */
/* If position 4 = 5 then SERVICE - normal release                     */
/*                                                                     */
/* To run this REXX program, type:                                     */
/* REGNUM nnnnnnnn                                                     */
/* where nnnnnnnn is the registration number (e.g. 00010505)           */
/*                                                                     */
/* This program accepts the number on invocation, or asks the user     */
/* for the number. The inputted Customer Registration Number is        */
/* displayed on the screen. Whether the customer gets SERVICE or NO    */
/* SERVICE will also be displayed on the screen.                       */
arg CUSTREG                       /* Puts the customer reg. number     */
                                  /* from invocation of program into   */
                                  /* CUSTREG variable.                 */
if CUSTREG = '' then              /* If the user didn't input a        */
do until CUSTREG \= ''            /* number, ask for one now.          */
say 'Please input a Customer Registration Number.'
pull CUSTREG                      /* Pull response and put into        */
                                  /* CUSTREG.                          */
end                               /* The DO UNTIL loops until the      */
                                  /* user inputs a number.             */
TESTNUM = substr(CUSTREG,4,1)     /* Puts the 4th character of the     */
                                  /* number into variable TESTNUM.     */
say 'CUSTREG =' CUSTREG           /* Writes the number to the screen.  */
select when 'TESTNUM = '1' then   /* Select when Service Indicator is  */
say 'SERVICE'                     /* 1, and write SERVICE on screen.   */
when TESTNUM = '2' then           /* Select when Service Indicator is  */
say 'SERVICE'                     /* 2, and write SERVICE on screen.   */
when TESTNUM = '3' then           /* Select when Service Indicator is  */
say 'NO SERVICE'                  /* 3, and write NO SERVICE.          */
when TESTNUM = '4' then           /* Select when Service Indicator is  */
say 'NO SERVICE'                  /* 4, and write NO SERVICE.          */
when TESTNUM = '5' then           /* Select when Service Indicator is  */
say 'SERVICE'                     /* 5, and write SERVICE on screen.   */
otherwise                         /* Select when Service Indicator is  */
say 'NOT A VALID CUSTOMER'        /* not a valid number, and write     */
                                  /* NOT A VALID CUSTOMER.             */
end                               /* END the SELECT instruction.       */
exit                              /* EXIT the program.                 */

(Return to Text)

Figure 3. REXX Program ADD2NUM.BAT

/* This REXX program asks the user for two numbers, then adds them     */
/* and display the sum on the screen.                                  */
/*                                                                     */
/* To run this REXX program, type:                                     */
/* ADD2NUM                                                             */
say "Type a number:"              /* Request the user to type a        */
                                  /* number.                           */
pull FIRST                        /* Pull the number inputted by the   */
                                  /* user into the FIRST variable.     */
say "Type another number:"        /* Request the user to type another  */
                                  /* number.                           */
pull SECOND                       /* Pull the number inputted by the   */
                                  /* user into the SECOND variable.    */
SUM = FIRST + SECOND              /* Add FIRST and SECOND variable     */
                                  /* values and put into SUM.          */
say "The sum is" SUM              /* Display 'The sum is' and the SUM  */
                                  /* variable value.                   */
exit                              /* End the program.                  */

(Return to Text)

Figure 4. Some REXX Keyword Instructions

IF ...
THEN ...
ELSE ...
WHEN ... THEN...

(Return to Text)

Figure 5. CALL and LABEL Processing

<NOTE: This figure must be copied over as a picture. >

/* First line MUST be a comment */
CALL MYSUB -----------
Main -----------
Program -----------

(Return to Text)

Figure 6. Some REXX Built-In Functions

DATATYPE         Checks whether the data is valid
SUBSTR           Allows you to select part of a string
LENGTH           Returns the length of a string
DATE             Returns the date
TIME             Returns the time
WORDLENGTH       Returns the length of a specific word in a string

(Return to Text)

Figure 7. Sample REXX Program TTD.BAT

/* This REXX program gives you the date, time, and a list of the       */
/* items in your Things To Do file.                                    */
say DATE()
say TIME()
type c:\mythings.lst'

(Return to Text)

Figure 8. Displaying a File Using REXX Functions


(Return to Text)

Figure 9. Output Displayed by TTD.BAT Program

Assume that your MYTHINGS.LST file contains these items:

1.  Answer mail.
2.  Call airline about trip.
3.  Order REXX User's Guide.

then the displayed output is:

1 Dec 1994
1.  Answer mail.
2.  Call airline about trip.
3.  Order REXX User's Guide.

(Return to Text)

Figure 10. Doing Repetitive Tasks

/* This REXX program handles my repetitive tasks - editing my files,   */
/* then copying them to a server so that others can view them, then    */
/* printing them.                                                      */

                                 /* TO THE SERVER, INTO THE STAT       */
                                 /* DIRECTORY                          */
"PRINT C:\MARIE\*.STA"           /* PRINTS ALL THE FILES I JUST        */
                                 /* UPDATED SO I CAN FILE THEM         */

(Return to Text)

...pisz do nas

© Polmax.
Wszelkie nazwy firm ich znaki towarowe oraz nazwy produktów
jak również opisy zostały użyte w celach informacyjnych i są zastrzeżone przez ich właścicieli.
Informacje na temat PC-DOS to materiały informacyjne firmy IBM i stanowią jej własność.