This code, developed to run under TSO/E REXX, was designed as a further demonstration of STEM variable processing, by using a STEM variable to hold a short list of names which require sorting. (This is also a REXX development of an Assembler Workshop exercise.)

/* ---- REXX Routine to sort a short list of names ---- */
Drop name.                             /* Clear STEM variable before read */
names = " ";
"ALLOC DA(cobol.cntl(demo1d)) F(ut1) SHR"  /* Assign input file */ 
"EXECIO * DISKR UT1 (FINIS STEM  name."    /* Phase 1 - Read all the names */
"FREE F(ut1)"                              /* De-allocate the data set */
Say name.0 " names read."; Say " ";
x = name.0 + 1
name.x = "ZZZZZZZZ"                        /* Set end of name list */
Do Forever                                 /* Phase 2 - Sort the names */
   If sorted = 'Y' Then Leave;
      sorted = 'Y'; x = 1; y = 2;
      Do z = 1 To name.0 By 1
         Select
           When SUBSTR(name.x,1,8) > SUBSTR(name.y,1,8) Then
             Do
                saven = name.y
                name.y = name.x
                name.x = saven 
                sorted = 'N'
             End
           Otherwise
             Nop
         End
      x = x + 1; y = y + 1;
      End;
End;
Do n = 1 To name.0 By 1                    /* Phase 3 - Output the names. */
   names = names || SUBSTR(name.n,1,8) || " "
End;
Say names
Exit 0                                     /* leave program */

To compare with the Windows for REXX version click here.

Copyright © KMS-IT Limited 2002