| REXX Workshop - Part 1 |
/* This is a comment; REXX programs start with comments. */
Address 'CMS' /* Send all non-rexx */
/* instructions to CMS */
/* for processing. */
'RENAME MY FILE A YOUR FILE A' /* Rename the file */
'EXEC FILELIST' /* Invoke FILELIST EXEC */
Exit /* End program */
/* Get two numbers from the keyboard, write out the sum. */
Say "Enter a number" /* Prompt the user. */
Pull n1 /* Receive input. */
Say "Enter another number" /* Prompt again. */
Pull n2 /* Receive second input. */
sum = n1 + n2 /* Calculate the sum. */
Say n1 "+" n2 "=" sum /* Write out the answer. */
Exit /* End program. */
With the introduction of NetRexx and Object Rexx, the original language is now referred to as Classic Rexx.
REXX is available on virtually every computing platform from mainframes to microcomputers, but it is most commonly associated with IBM mainframe operating systems.
The comments in the example below are highlighted in red.
/* My First REXX Exec */
Say "What is your name?" /* Prompt for name. */
Pull name
Say "Hello," name"!" /* Greet the user. */
Exit
The strings in the example below are highlighted in red.
/* My First REXX Exec */
Say 'What is your name?' /* Prompt for name. */
Pull name
Say "Hello," name||"!" /* Greet the user. */
Exit
The variables in the example below are highlighted in red.
/* Add two numbers and report the sum. */
Say "Enter a number"
Pull n1
Say "Enter another number"
Pull n2
sum = n1 + n2
Say n1 "+" n2 "=" sum
Exit
4 + 3 - 1 results in 6
4 * 3 - 1 results in 11
4 * (3 - 1) results in 8
"red" "dog" results in "red dog"
"red" || "dog" results in "reddog"
"red" 4 results in "red 4"
"red" 4+5 results in "red 9"
4 * 2 || 5 results in "85"
4 * 2 5 results in "8 5"
4 * (2 || 5) results in 100
4 * "1.2" results in 4.8
/* Write out the value of expressions. */
Say 4 + 5 / 2
Exit
The REXX keywords in the example below are highlighted in red.
/* Examples of REXX Instructions */
Say "Enter a number"
Pull n
If n = 0 Then Exit
Do n
Say "Hello there!"
End
Exit
n = 5 stores "5" in n
var = 6 + 1 stores "7" in var
var2 = var + 2 stores "9" in var2
name = "Bill" stores "Bill" in name
x = "Bill"||5 + 7 stores "Bill12" in x
Expressions to the right of the equal sign are evaluated and the
result is stored in the variable to the left of the equal sign.
LOOP:
.
.
.
LASTSTEP:
.
.
.
.
.
.
Call LOOP
.
.
.
LOOP:
.
.
.
.
.
.
Call LOOP
.
.
.
LOOP: a = a + 1 /* increment the counter */
.
.
.
EXEC FILELIST
it would
Address 'CMS' /* direct commands to CMS */ 'EXEC FILELIST' /* command is sent to CMS */ Address 'XEDIT' /* direct commands to XEDIT */ 'FILE' /* command is sent to XEDIT */ Address 'CP' /* direct commands to CP */ 'LOGOFF' /* command is send to CP */
Address 'CMS' /* direct commands to CMS */ . . . Address 'CP' 'QUERY USERID' /* send command to CP */ . . .
.
.
.
'EXEC FILELIST'
If rc = 0
Then Say 'All is well.'
Else Say 'Filelist may have erred.'
.
.
.
More information about the IF REXX instruction will be supplied later.
a = 1 ; b = a + c ; Say 'The Answer is' b'.'
a = "This is the first part of the string" ,
strvarname "which will be concatenated" ,
"with several variable names:" b c d e
HELP REXX MENU
HELP CP MENU
HELP CMS MENU
HELP XEDIT MENU
Exercise: invoke HELP for REXX and read a few entries.
The following BookManager books may be consulted for more complete discussions, if REXX is running under VM/CMS.