Not the question you asked, but...
sort_stem = 'index.' call sort 6, ??? (see comments after code) /* Sort sort_stem using combsort */ sort: procedure, expose (sort_stem) arg key_start, key_length size = value(sort_stem'0') gap = size do until switches = 0 & gap = 1 gap = gap % 1.3 select when gap = 0 then gap = 1 when gap = 9 then gap = 11 when gap = 10 then gap = 11 otherwise end switches = 0 do i = 1 to (size - gap) j = i + gap if substr(value(sort_stem'i'), key_start, key_length) >, substr(value(sort_stem'j'), key_start, key_length) then do /* swap the entries */ hold = value(sort_stem'i') /* hold = stem.i */ x = value(sort_stem'i', value(sort_stem'j')) /* stem.i = stem.j */ x = value(sort_stem'j', hold) /* stem.j = hold */ switches = switches + 1 end end end return The problem is that as written, the code expects the key_length to be the same across all elements of the stem. If yours are variable length then the code will need to be adjusted. Maybe in your case it would need to be comparing subwords instead of substr. -----Original Message----- From: IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU> On Behalf Of Charles Mills Sent: Wednesday, March 6, 2024 6:10 PM To: IBM-MAIN@LISTSERV.UA.EDU Subject: What am I doing wrong with BPXWUNIX sort? I am trying to sort a Rexx "array" starting with the second "word" of the variables. My "array" is in Index.n and contains records of the form <nnnn some descriptive string> where nnnn is 0001, 0002, 0003, etc. and string is 2 to 5 Rexx "words." Here's my Rexx code: Say "Before sort" Index.0 Index.1 Index.2 Index.3 stdout.0 = 0 stderr.0 = 0 Call BPXWUNIX "/bin/sort -k2",Index.,Index.,stderr. Do i = 1 to stderr.0 Say "Sort error:" stderr.i End i Say "After sort" Index.0 Index.1 Index.2 Index.3 And here is the output: Before sort 8 0001 Main Check 0002 OMVS (FTP Session) 0003 C Validation After sort 8 0001 Main Check 0002 OMVS (FTP Session) 0003 C Validation My expectation is that -k2 would have caused sort to sort on the "descriptive strings" (ignoring the nnnn) but obviously that is not what has happened. What am I doing wrong? (I have tried both -k2 and -k 2, and also -k1 and +1 -- all with the same results.) Thanks, Charles ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN