[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Everything about COBOL
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
  Sorting in REXX: The Bubble Sort
  REXX Password Generator
  Using REXX to capture displayed output of TSO command
  Count records in REXX
  REXX program to calculate present value of money
  REXX function to format a number in currency format
  REXX function to produce a fixed-length number
  REXX program to produce lottery numbers
  REXX: what does your phone number spell?
  REXX Practice Problems.
  Just Enough REXX Tutorial
  Setting up to Execute REXX Programs on TSO/ISPF
  How to execute a REXX program
  REXX Boolean operators
  Comparison of CLIST language and REXX
  REXX Comparison operators
  REXX Debugging: the TRACE verb
  Using REXX OUTTRAP
  Reserved REXX Variables
  Executing REXX through JCL.
  Writing ISPF Edit Macros in REXX
  REXX program to unload a PDS
  REXX book: The REXX Language on TSO
  REXX Functions Book
  QMF Procedures Written in REXX
  Using REXX Subroutines with the QMF Calc panel
  REXX error codes (RC)
  REXX programming language manuals
  Books on REXX programming
  The REXX Files
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > REXX   > REXX Phone Number

REXX program to show words that may be produced from a phone number

This illustrates the use of REXX arrays/compound variables.
/*phonetso        tso version */
/* Displays the letters corresponding to a telephone number.
    You can see if a phone number spells anything interesting.
      To execute:

     Example of executing with telephone number 5552345 (max 7 digits):

    phonenum 5552345

    Also writes the letters to a file named Nphonenumber TEL
          for example: N5552345 TEL
    You can print, edit or view the file

*/


Select
   When Address() = "TSO" then nop
   When Address() = "ISPEXEC" then nop
   When Address() = "ISREDIT" then nop
Otherwise  signal Not_on_TSO
End

arg phone_number
call init

/* is the number legit?*/
if phone_number = "" ,
  | datatype(phone_number) = "CHAR",
  | length(phone_number)     >  7
then
  do
    Say "Please type in the phone number, 7 digits, no punctuation"
    Pull Phone_number
  end

if Phone_number = "",
  | datatype(phone_number) = "CHAR",
  | length(phone_number)     >  7
then signal no_number

/* create file name to write to */
disk_file = "N"phone_number".TEL"
Say "Phone number was " phone_number
record = "The phone number was " phone_number
push record
Call MSG "OFF"
"delete " disk_file
Call MSG "ON"
"alloc ddn(DISKFILE) dsn(" disk_file ") space(1 1) tracks reuse"
"EXECIO 1 DISKW DISKFILE"
/* break up telephone number into 7 variables, one for each digit*/
pn1 = substr(phone_number,1,1)
pn2 = substr(phone_number,2,1)
pn3 = substr(phone_number,3,1)
pn4 = substr(phone_number,4,1)
pn5 = substr(phone_number,5,1)
pn6 = substr(phone_number,6,1)
pn7 = substr(phone_number,7,1)

/* begin the mighty nested loop, to get all the possibilities*/
Do C1 = 1 to 3
 Do C2 = 1 to 3
  Do C3 = 1 to 3
   Do C4 = 1 to 3
    Do C5 = 1 to 3
     Do C6 = 1 to 3
      Do C7 = 1 to 3

WORD = "" || N.PN1.C1 || N.PN2.C2 || N.PN3.C3 || N.PN4.C4 ||,
     N.PN5.C5 || N.PN6.C6 || N.PN7.C7
/* say word */
call load_array
       End C7
      End C6
     End C5
    End C4
   End C3
  End C2
 End C1


"EXECIO 0 DISKW DISKFILE (FINIS)"
"FREE DDN(DISKFILE)"

Call Credits
EXIT /* the end */

no_number:
Say "no phone number supplied, terminating"
EXIT
init:
load_index = 1
word = ""
line = ""
words_across_page = 8 /* adjust up or down as desired*/
N. = " " /* set default in case something illegal gets thru */

/* load the compound variables.  Take a look at the telephone keypad*/
N.0.1 = "0"
N.0.2 = "0"
N.0.3 = "0"

N.1.1 = "1"
N.1.2 = "1"
N.1.3 = "1"

N.2.1 = "A"
N.2.2 = "B"
N.2.3 = "C"

N.3.1 = "D"
N.3.2 = "E"
N.3.3 = "F"

N.4.1 = "G"
N.4.2 = "H"
N.4.3 = "I"

N.5.1 = "J"
N.5.2 = "K"
N.5.3 = "L"

N.6.1 = "M"
N.6.2 = "N"
N.6.3 = "O"

N.7.1 = "P"
N.7.2 = "R"
N.7.3 = "S"

N.8.1 = "T"
N.8.2 = "U"
N.8.3 = "V"

N.9.1 = "W"
N.9.2 = "X"
N.9.3 = "Y"

return

load_array:
line = line word
load_index = load_index + 1
if load_index >= words_across_page
then
   do
      say line
      record = line
      push record
     "EXECIO 1 DISKW DISKFILE"
      load_index = 0
      line = ""
   end

return

Not_on_TSO:
Say "This program can be run only on MVS/TSO"
Say "it cannot be run on " Address()
Exit


Credits:


Return /* credits */

Learn how to use all the features of REXX: REXX Programming Book for TSO (published 2012)

[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |