This code, developed to run under Windows REXX, was designed as to demonstrate simple array processing using various REXX Built-In functions to aid the process. the premise is to update an array of bird names. It is assumed that the new names to be entered are in collating sequence, i.e. sorted.

/* ---- REXX Demonstration of POS, SUBSTR, WORD and WORDS ---- */
birds = "Albatross Kittiwake Osprey Wren"
no_birds = WORDS(birds) + 9                 /* Establish new entry maximum */
Say "Bird name array prior to update - "    /* List current array */
Say birds; Say " ";
Say "Enter up to 10 birds names"            /* Get the new names */
Parse Pull b.1 b.2 b.3 b.4 b.5 b.6 b.7 b.8 b.9 b.10 dump
If dump \= "" Then Do                       /* Ensure only 10 new names */
                      Say "too many bird names entered!" 
                      Say "These names ignored " dump
                   End
k = 1                                       /* Set new bird index to 1 */
Do i = 1 To no_birds Until b.k = ""
   If WORD(birds,i)  \> b.k Then Iterate
      Else Call Insert                      /* Update array via sub-routine */
   k = k + 1                                /* Update new bird index */
End i
Say "Bird name array after update - "
Say birds
Exit 0                                      /* leave program */
/*
   ---- Routine to perform the insertion of new names ----
*/
Insert:
  array_loc = POS(WORD(birds,i),birds)      /* Locate Insert Point */
  length = array_loc - 1                    /* Calculate length to insert */
  birds = SUBSTR(birds,1,length)||b.k||" "||SUBSTR(birds,array_loc)
  no_birds = no_birds + 1
Return                                      /* Return to DO loop */

End of Topic.

Copyright © KMS-IT Limited 2002