Discussion:
An evil though? Sorting a REXX array "in place" using UNIX
(too old to reply)
John McKown
2016-10-25 18:56:51 UTC
Permalink
Raw Message
OK, this is likely weird, but may be of some interest. I know there are
times when I'd like to sort the contents of a REXX array. That is, a stem
variable where .0 contains the number of entries, which are in .1 through
.??? with no missing numbers. Like a FORTRAN array. This can be a bother to
write your own sorting routine in REXX or even some other REXX compatible
callable program. UNIX to the rescue! An example:

/* REXX */
XX=SYSCALLS('ON')
If xx > 3 Then Do
Say "SYSCALLS('ON') Failed. RC="xx
exit
End
a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
a.10=6 ; a.11=8 ; a.12='a';
stdout.0=0
stderr.0=0
call bpxwunix "/bin/sort -n",a.,a.,stderr.
say 'a.0='a.0
do i=1 to a.0
say "a."i"="a.i
end
say 'stderr.0='stderr.0
do i=1 to stderr.0
say "stderr."i"="stderr.i
end

Note that in order to sort numerically, I had to include the "-n" switch on
the UNIX sort command. Otherwise the data sorts as character strings. But,
as you will notice, I the sort will accommodate string data. That is the
"-n" doesn't require numeric only data. Note that the "key" for sorting is
the entire record, but you can use "fields" (blank delimited data) by using
the "-k" switch. For more information on the UNIX sort command, see:
http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxa500/sort.htm


--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Itschak Mugzach
2016-10-25 19:05:31 UTC
Permalink
Raw Message
Been There, Done That, never got a tshirt ;-)

ITschak

ITschak Mugzach
Z/OS, ISV Products and Application Security & Risk Assessments Professional

On Tue, Oct 25, 2016 at 9:56 PM, John McKown <***@gmail.com>
wrote:

> OK, this is likely weird, but may be of some interest. I know there are
> times when I'd like to sort the contents of a REXX array. That is, a stem
> variable where .0 contains the number of entries, which are in .1 through
> .??? with no missing numbers. Like a FORTRAN array. This can be a bother to
> write your own sorting routine in REXX or even some other REXX compatible
> callable program. UNIX to the rescue! An example:
>
> /* REXX */
> XX=SYSCALLS('ON')
> If xx > 3 Then Do
> Say "SYSCALLS('ON') Failed. RC="xx
> exit
> End
> a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> a.10=6 ; a.11=8 ; a.12='a';
> stdout.0=0
> stderr.0=0
> call bpxwunix "/bin/sort -n",a.,a.,stderr.
> say 'a.0='a.0
> do i=1 to a.0
> say "a."i"="a.i
> end
> say 'stderr.0='stderr.0
> do i=1 to stderr.0
> say "stderr."i"="stderr.i
> end
>
> Note that in order to sort numerically, I had to include the "-n" switch on
> the UNIX sort command. Otherwise the data sorts as character strings. But,
> as you will notice, I the sort will accommodate string data. That is the
> "-n" doesn't require numeric only data. Note that the "key" for sorting is
> the entire record, but you can use "fields" (blank delimited data) by using
> the "-k" switch. For more information on the UNIX sort command, see:
> http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> com.ibm.zos.v2r1.bpxa500/sort.htm
>
>
> --
> Heisenberg may have been here.
>
> Unicode: http://xkcd.com/1726/
>
> Maranatha! <><
> John McKown
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
John McKown
2016-10-25 19:10:19 UTC
Permalink
Raw Message
On Tue, Oct 25, 2016 at 2:05 PM, Itschak Mugzach <***@gmail.com> wrote:

> Been There, Done That, never got a tshirt ;-)
>

​Oh, was this already generally known? If so, colour me embarrassed. ​



>
> ITschak
>
> ITschak Mugzach
> Z/OS, ISV Products and Application Security & Risk Assessments Professional
>
>
--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Dyck, Lionel B. , TRA
2016-10-25 19:14:21 UTC
Permalink
Raw Message
This is a routine I found years ago on either the cbttape or online somewhere:

/* rexx command to sort a stem variable
Simple bubble sort of "stem' by stem.1
Ken Singer, Shell Oil, Houston
********************************************************/
if stem.0 = 1 then return /* simple sort !*/
ctr = stem.0
do y = 1 to ctr - 1
do x = y+1 to ctr
if stem.x = null then leave
if stem.x < stem.y then do
/* swap these 2 entries */
t1 = stem.y ;
stem.y = stem.x
stem.x = t1
end
end x
end y


--------------------------------------------------------------------------
Lionel B. Dyck (TRA Contractor)
Mainframe Systems Programmer <AITC Mainframe Support>
Enterprise Infrastructure Support (Station 200) (005OP6.3.10)
VA OI&T Service Delivery & Engineering

-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of John McKown
Sent: Tuesday, October 25, 2016 1:56 PM
To: TSO-***@VM.MARIST.EDU
Subject: [EXTERNAL] [TSO-REXX] An evil though? Sorting a REXX array "in place" using UNIX

OK, this is likely weird, but may be of some interest. I know there are times when I'd like to sort the contents of a REXX array. That is, a stem variable where .0 contains the number of entries, which are in .1 through .??? with no missing numbers. Like a FORTRAN array. This can be a bother to write your own sorting routine in REXX or even some other REXX compatible callable program. UNIX to the rescue! An example:

/* REXX */
XX=SYSCALLS('ON')
If xx > 3 Then Do
Say "SYSCALLS('ON') Failed. RC="xx
exit
End
a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
a.10=6 ; a.11=8 ; a.12='a';
stdout.0=0
stderr.0=0
call bpxwunix "/bin/sort -n",a.,a.,stderr.
say 'a.0='a.0
do i=1 to a.0
say "a."i"="a.i
end
say 'stderr.0='stderr.0
do i=1 to stderr.0
say "stderr."i"="stderr.i
end

Note that in order to sort numerically, I had to include the "-n" switch on the UNIX sort command. Otherwise the data sorts as character strings. But, as you will notice, I the sort will accommodate string data. That is the "-n" doesn't require numeric only data. Note that the "key" for sorting is the entire record, but you can use "fields" (blank delimited data) by using the "-k" switch. For more information on the UNIX sort command, see:
http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxa500/sort.htm


--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions, send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Itschak Mugzach
2016-10-25 19:17:35 UTC
Permalink
Raw Message
Its a bubble sort. Works but takes lot of cpu.

בתאריך 25 באוק 2016 22:15,‏ "Dyck, Lionel B. (TRA)" <***@va.gov>
כתב:

> This is a routine I found years ago on either the cbttape or online
> somewhere:
>
> /* rexx command to sort a stem variable
> Simple bubble sort of "stem' by stem.1
> Ken Singer, Shell Oil, Houston
> ********************************************************/
> if stem.0 = 1 then return /* simple sort !*/
> ctr = stem.0
> do y = 1 to ctr - 1
> do x = y+1 to ctr
> if stem.x = null then leave
> if stem.x < stem.y then do
> /* swap these 2 entries */
> t1 = stem.y ;
> stem.y = stem.x
> stem.x = t1
> end
> end x
> end y
>
>
> --------------------------------------------------------------------------
> Lionel B. Dyck (TRA Contractor)
> Mainframe Systems Programmer <AITC Mainframe Support>
> Enterprise Infrastructure Support (Station 200) (005OP6.3.10)
> VA OI&T Service Delivery & Engineering
>
> -----Original Message-----
> From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf
> Of John McKown
> Sent: Tuesday, October 25, 2016 1:56 PM
> To: TSO-***@VM.MARIST.EDU
> Subject: [EXTERNAL] [TSO-REXX] An evil though? Sorting a REXX array "in
> place" using UNIX
>
> OK, this is likely weird, but may be of some interest. I know there are
> times when I'd like to sort the contents of a REXX array. That is, a stem
> variable where .0 contains the number of entries, which are in .1 through
> .??? with no missing numbers. Like a FORTRAN array. This can be a bother to
> write your own sorting routine in REXX or even some other REXX compatible
> callable program. UNIX to the rescue! An example:
>
> /* REXX */
> XX=SYSCALLS('ON')
> If xx > 3 Then Do
> Say "SYSCALLS('ON') Failed. RC="xx
> exit
> End
> a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> a.10=6 ; a.11=8 ; a.12='a';
> stdout.0=0
> stderr.0=0
> call bpxwunix "/bin/sort -n",a.,a.,stderr.
> say 'a.0='a.0
> do i=1 to a.0
> say "a."i"="a.i
> end
> say 'stderr.0='stderr.0
> do i=1 to stderr.0
> say "stderr."i"="stderr.i
> end
>
> Note that in order to sort numerically, I had to include the "-n" switch
> on the UNIX sort command. Otherwise the data sorts as character strings.
> But, as you will notice, I the sort will accommodate string data. That is
> the "-n" doesn't require numeric only data. Note that the "key" for sorting
> is the entire record, but you can use "fields" (blank delimited data) by
> using the "-k" switch. For more information on the UNIX sort command, see:
> http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> com.ibm.zos.v2r1.bpxa500/sort.htm
>
>
> --
> Heisenberg may have been here.
>
> Unicode: http://xkcd.com/1726/
>
> Maranatha! <><
> John McKown
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions, send email
> to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Mickey Bee
2016-10-25 19:44:52 UTC
Permalink
Raw Message
Not sure of the origin of this, as I have had it around for 2 decades or
there abouts.


/*Rexx Allsorts */
Heapsort: PROCEDURE EXPOSE array. num switches sHeight tests
/*****************************************************************************/
/* Heapsort(low high)
*/
/* Heapsort sorts the array ARRAY. It is called with the indexes of the
*/
/* low and high bounds (defining the sub-array) to be sorted.
*/
/*****************************************************************************/
ARG low, high .
l=trunc(high/2)+1
r=high
do while l > low
l=l-1
call sift
end
do while r > low
temp=array.low
array.low=array.r
array.r=temp
r=r-1
call sift
end
RETURN tests switches Format(Time("Elapsed"), , 1) "Heap Sort"

sift: procedure expose array. l r tests switches sHeight num
i=l
j=2*i
temp=array.i
do while j <= r
if j < r then do
jplus1=j+1
if array.j < array.jplus1 then j=j+1
end
if temp >= array.j then leave
array.i=array.j
i=j
j=2*i
end
array.i=temp
return /* from sift */

BinInsert: PROCEDURE EXPOSE array. num switches sHeight tests
/*****************************************************************************/
/* BinInsert(low high)
*/
/* BinInsert sorts the array ARRAY. It is called with the indexes of the
*/
/* low and high bounds (defining the sub-array) to be sorted.
*/
/*****************************************************************************/
ARG low, high .
DO i = low+1 TO high
temp=array.i
l=1
r=i-1
do while l <= r
m=trunc((l+r)/2)
if temp < array.m then r=m-1
else l=m+1
end
do j=i-1 to l by -1
jplus1=j+1
array.jplus1=array.j
end
array.l=temp
end
RETURN tests switches Format(Time("Elapsed"), , 1) "Binary Insertion Sort"

StrInsert: PROCEDURE EXPOSE array. num switches sHeight tests
/*****************************************************************************/
/* StrInsert(low high)
*/
/* StrInsert sorts the array ARRAY. It is called with the indexes of the
*/
/* low and high bounds (defining the sub-array) to be sorted.
*/
/*****************************************************************************/
ARG low, high .
DO i = low+1 TO high
temp=array.i
array.0=temp
j=i-1
do while temp < array.j
jplus1=j+1
array.jplus1=array.j
j=j-1
end
jplus1=j+1
array.jplus1=temp
end
RETURN tests switches Format(Time("Elapsed"), , 1) "Straight Insertion Sort"

Shakersort: PROCEDURE EXPOSE array. num switches sHeight tests
/*****************************************************************************/
/* Shakersort(low high)
*/
/* BUBBLESORT sorts the array ARRAY. It is called with the indexes of the
*/
/* low and high bounds (defining the sub-array) to be sorted.
*/
/*****************************************************************************/
ARG low, high .
l=low+1
r=high
k=high
do until l > r
do j=r to l by -1
jminus1=j-1
if array.jminus1 > array.j then do
temp=array.jminus1
array.jminus1=array.j
array.j=temp
k=j
end
end
l=k+1
do j=l to r
jminus1=j-1
if array.jminus1 > array.j then do
temp=array.jminus1
array.jminus1=array.j
array.j=temp
k=j
end
end
r=k-1
end
RETURN tests switches Format(Time("Elapsed"), , 1) "Shaker Sort"

PrBblesort: PROCEDURE EXPOSE array. num switches sHeight tests
/*****************************************************************************/
/* PrBblesort(low high) Progressive
*/
/* BUBBLESORT sorts the array ARRAY. It is called with the indexes of the
*/
/* low and high bounds (defining the sub-array) to be sorted.
*/
/*****************************************************************************/
ARG low, high .
i=low
st1: j=i+1
if array.i > array.j THEN DO /* make an exchange
*/
temp = array.i
array.i = array.j
array.j = temp
if i >=2 then do /* can we back up and bubble? */
i=i-1
signal st1
END
END
i=i+1 /* proceed down the list */
if i < high then signal st1
RETURN tests switches Format(Time("Elapsed"), , 1) "Progressive Bubble Sort"

Bubblesort: PROCEDURE EXPOSE array. num switches sHeight tests
/*****************************************************************************/
/* BUBBLESORT(low high)
*/
/* BUBBLESORT sorts the array ARRAY. It is called with the indexes of the
*/
/* low and high bounds (defining the sub-array) to be sorted.
*/
/*****************************************************************************/
ARG low, high .
last = high - 1
DO i = low TO last
j = i + 1
IF array.i > array.j THEN DO /* make an exchange
*/
temp = array.i
array.i = array.j
array.j = temp
END
END
last = last - 1
RETURN tests switches Format(Time("Elapsed"), , 1) "Bubble Sort"


Quicksort: PROCEDURE EXPOSE array. switches sHeight tests
/*****************************************************************************/
/* QUICKSORT(low high)
*/
/* QUICKSORT sorts the array ARRAY. It is called with the indexes of the low
*/
/* and high bounds (defining the sub-array) to be sorted.
*/
/*****************************************************************************/
ARG low, high .
CALL QSort low, high
RETURN tests switches Format(Time("Elapsed"), , 1) "Quick Sort"

QSort: PROCEDURE EXPOSE array. switches sHeight tests
/*---------------------------------------------------------------------------*/
/* C. A. R. Hoare's Quicksort algorithm.
*/
/*---------------------------------------------------------------------------*/
ARG bottom, top
center = QSortIt(bottom, top)
IF center - 1 > bottom THEN CALL QSort bottom, center - 1
IF center + 1 < top THEN CALL QSort center + 1, top
RETURN

QSortIt: PROCEDURE EXPOSE array. switches sHeight tests
/*---------------------------------------------------------------------------*/
/* Heart of Quicksort.
*/
/*---------------------------------------------------------------------------*/
ARG bottom, top
choose = array.bottom
small = bottom
large = top + 1
DO WHILE (Small + 1 < large)
next = small + 1
IF array.next <= choose THEN DO
array.small = array.next
small = small + 1
array.next = choose
END
ELSE DO
large = large - 1
temp = array.large
array.large = array.next
array.next = temp
END
END
RETURN small

Shellsort: PROCEDURE EXPOSE array. switches sHeight tests
/*****************************************************************************/
/* SHELLSORT(low high)
*/
/* SHELLSORT sorts the array ARRAY. It is called with the indexes of the low
*/
/* and high bounds (defining the sub-array) to be sorted.
*/
/*****************************************************************************/
ARG low, high .

gap = low; DO WHILE (gap < high); gap = gap * 2; END /* set sublist size
*/

DO WHILE (gap > low) /* loop through the sublists, sorting them
*/
gap = gap % 2
limit = high - gap
DO scan = low TO limit /* ordinary bubble sort
*/
nextHigher = scan + gap
IF array.scan > array.nextHigher THEN DO
temp = array.nextHigher
array.nextHigher = array.scan
DO bubble = scan - gap TO low BY -gap WHILE(temp < array.bubble)
nextHigher = bubble + gap
array.nextHigher = array.bubble
END bubble
bubble = bubble + gap
array.bubble = temp
END
END scan /* end of ordinary bubble sort
*/
END
RETURN tests switches Format(Time("Elapsed"), , 1) "Shell Sort"

-----Original Message-----
From: Itschak Mugzach
Sent: Tuesday, October 25, 2016 3:17 PM
To: TSO-***@VM.MARIST.EDU
Subject: Re: [TSO-REXX] [EXTERNAL] [TSO-REXX] An evil though? Sorting a REXX
array "in place" using UNIX

Its a bubble sort. Works but takes lot of cpu.

בתאריך 25 באוק 2016 22:15,‏ "Dyck, Lionel B. (TRA)" <***@va.gov>
כתב:

> This is a routine I found years ago on either the cbttape or online
> somewhere:
>
> /* rexx command to sort a stem variable
> Simple bubble sort of "stem' by stem.1
> Ken Singer, Shell Oil, Houston
> ********************************************************/
> if stem.0 = 1 then return /* simple sort !*/
> ctr = stem.0
> do y = 1 to ctr - 1
> do x = y+1 to ctr
> if stem.x = null then leave
> if stem.x < stem.y then do
> /* swap these 2 entries */
> t1 = stem.y ;
> stem.y = stem.x
> stem.x = t1
> end
> end x
> end y
>
>
> --------------------------------------------------------------------------
> Lionel B. Dyck (TRA Contractor)
> Mainframe Systems Programmer <AITC Mainframe Support>
> Enterprise Infrastructure Support (Station 200) (005OP6.3.10)
> VA OI&T Service Delivery & Engineering
>
> -----Original Message-----
> From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf
> Of John McKown
> Sent: Tuesday, October 25, 2016 1:56 PM
> To: TSO-***@VM.MARIST.EDU
> Subject: [EXTERNAL] [TSO-REXX] An evil though? Sorting a REXX array "in
> place" using UNIX
>
> OK, this is likely weird, but may be of some interest. I know there are
> times when I'd like to sort the contents of a REXX array. That is, a stem
> variable where .0 contains the number of entries, which are in .1 through
> .??? with no missing numbers. Like a FORTRAN array. This can be a bother
> to
> write your own sorting routine in REXX or even some other REXX compatible
> callable program. UNIX to the rescue! An example:
>
> /* REXX */
> XX=SYSCALLS('ON')
> If xx > 3 Then Do
> Say "SYSCALLS('ON') Failed. RC="xx
> exit
> End
> a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> a.10=6 ; a.11=8 ; a.12='a';
> stdout.0=0
> stderr.0=0
> call bpxwunix "/bin/sort -n",a.,a.,stderr.
> say 'a.0='a.0
> do i=1 to a.0
> say "a."i"="a.i
> end
> say 'stderr.0='stderr.0
> do i=1 to stderr.0
> say "stderr."i"="stderr.i
> end
>
> Note that in order to sort numerically, I had to include the "-n" switch
> on the UNIX sort command. Otherwise the data sorts as character strings.
> But, as you will notice, I the sort will accommodate string data. That is
> the "-n" doesn't require numeric only data. Note that the "key" for
> sorting
> is the entire record, but you can use "fields" (blank delimited data) by
> using the "-k" switch. For more information on the UNIX sort command, see:
> http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> com.ibm.zos.v2r1.bpxa500/sort.htm
>
>
> --
> Heisenberg may have been here.
>
> Unicode: http://xkcd.com/1726/
>
> Maranatha! <><
> John McKown
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions, send email
> to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Bill Schoen
2016-10-25 20:02:26 UTC
Permalink
Raw Message
I tried this once but didn't like it.
It sorts ascii: numbers lower than letters, uppercase lower than
lowercase. For numbers, it would probably fine.
I prefer either a sort similar to that in other posts or if I'm in an
ispf environment, I'm likely to use tables with its sort function.

Bill Schoen


On 10/25/2016 2:56 PM, John McKown wrote:
> OK, this is likely weird, but may be of some interest. I know there are
> times when I'd like to sort the contents of a REXX array. That is, a stem
> variable where .0 contains the number of entries, which are in .1 through
> .??? with no missing numbers. Like a FORTRAN array. This can be a bother to
> write your own sorting routine in REXX or even some other REXX compatible
> callable program. UNIX to the rescue! An example:
>
> /* REXX */
> XX=SYSCALLS('ON')
> If xx > 3 Then Do
> Say "SYSCALLS('ON') Failed. RC="xx
> exit
> End
> a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> a.10=6 ; a.11=8 ; a.12='a';
> stdout.0=0
> stderr.0=0
> call bpxwunix "/bin/sort -n",a.,a.,stderr.
> say 'a.0='a.0
> do i=1 to a.0
> say "a."i"="a.i
> end
> say 'stderr.0='stderr.0
> do i=1 to stderr.0
> say "stderr."i"="stderr.i
> end
>
> Note that in order to sort numerically, I had to include the "-n" switch on
> the UNIX sort command. Otherwise the data sorts as character strings. But,
> as you will notice, I the sort will accommodate string data. That is the
> "-n" doesn't require numeric only data. Note that the "key" for sorting is
> the entire record, but you can use "fields" (blank delimited data) by using
> the "-k" switch. For more information on the UNIX sort command, see:
> http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxa500/sort.htm
>
>
> --
> Heisenberg may have been here.
>
> Unicode: http://xkcd.com/1726/
>
> Maranatha! <><
> John McKown
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX


----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-10-25 22:56:26 UTC
Permalink
Raw Message
On 2016-10-25 14:02, Bill Schoen wrote:
> I tried this once but didn't like it.
> It sorts ascii: numbers lower than letters, uppercase lower than
> lowercase. For numbers, it would probably fine.
> I prefer either a sort similar to that in other posts or if I'm in an
> ispf environment, I'm likely to use tables with its sort function.
>
Can you control this with LC_COLLATE?

Thereby hangs a tale. The results for EN_US are radically different from
EN_CA. EN_US is more like C which wjs dislikes. I went to SR on this,
several years ago, but I made the strategic blunder of using Linux for
comparison. Support said I shouldn't expect agreement because of ASCII-
EBCDIC differences. But lately I discover I can reproduce my result with
Enhanced ASCII in XL C/C++. I'm tempted to redrive my SR. I suspect
it's a historic design error institutionalized by use; IBM may have trouble
repairing it even at a release boundary.

> On 10/25/2016 2:56 PM, John McKown wrote:
>> OK, this is likely weird, but may be of some interest. I know there are
>> times when I'd like to sort the contents of a REXX array. That is, a stem
>> variable where .0 contains the number of entries, which are in .1 through
>> .??? with no missing numbers. Like a FORTRAN array. This can be a bother to
>> write your own sorting routine in REXX or even some other REXX compatible
>> callable program. UNIX to the rescue! An example:
>>
>> /* REXX */
>> XX=SYSCALLS('ON')
>> If xx > 3 Then Do
>> Say "SYSCALLS('ON') Failed. RC="xx
>> exit
>>
How often does that happen? Perhaps if OMVS hasn't started?

>> stdout.0=0
>>
Where do you use this?

>> stderr.0=0
>>
Is this not set if never used? Ugh!

>> call bpxwunix "/bin/sort -n",a.,a.,stderr.
>>
In what order are the compound symbols accessed? I know that
if the descriptors are DDNAMEs it's highly concurrent -- I can
watch them updating with SDSF if they're SYSOUT. I'd feel safer
using different symbols for input and output.

>> Note that in order to sort numerically, I had to include the "-n" switch on

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-10-26 03:52:40 UTC
Permalink
Raw Message
On 2016-10-25 14:02, Bill Schoen wrote:
> I tried this once but didn't like it.
> It sorts ascii: numbers lower than letters, uppercase lower than
> lowercase. For numbers, it would probably fine.
> I prefer either a sort similar to that in other posts or if I'm in an
> ispf environment, I'm likely to use tables with its sort function.
>
Here's my implementation, after John M's idea, with output.

o Why is En_US so radically different from En_CA?

o Which is correct? Either? Both?

o (Grrr... why does BPXWDYN use the EXECCOMM direct interface when
most utilities use the symbolic?)

/* Rexx */ signal on novalue; /* ************* *
Doc: Sort via BPXWUNIX with LC_COLLATE
*/
S = 'cat canary camel 137.036 CAT CANARY CAMEL 3.14159 Cat Canary Camel'
do I = 1 until S=''
parse value S with A.I S; end I
A.0 = I

Titles = ' '
call SortIt 'En_US.IBM-1047'
call SortIt 'En_CA.IBM-1047'

say; say Titles
do I = 1 to B.N.0
say right( I, 4 )' ' left( B.1.I, 14 ) B.2.I; end
return( RC )

SortIt:
Titles = Titles arg( 1 )
N = words( Titles )
RC = BPXWUNIX( 'set -x; LC_ALL='arg( 1 ) '/bin/sort -n', ,
'A.', 'B.'N'.', 'stderr.' )
return( RC )
/* ******************************************** */

En_US.IBM-1047 En_CA.IBM-1047
1 CAMEL camel
2 CANARY Camel
3 CAT CAMEL
4 Camel canary
5 Canary Canary
6 Cat CANARY
7 camel cat
8 canary Cat
9 cat CAT
10 3.14159 3.14159
11 137.036 137.036

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Robin
2016-10-26 00:58:00 UTC
Permalink
Raw Message
When I was working, I wrote (in assembler) a rexx function to invoke the system's Sort routine. My function accepted: all SORT commands via reserved variable names e.g sort.fields=
Input "file" being a named stem variable. Absent a such named stem then ddname SORTIN
Output "file" being a named stem variable. Absent such a named stem ten ddname SORTOUT
I believe SCXSORT is still out on the CBTAPE


-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of John McKown
Sent: October 25, 2016 2:56 PM
To: TSO-***@VM.MARIST.EDU
Subject: [TSO-REXX] An evil though? Sorting a REXX array "in place" using UNIX

OK, this is likely weird, but may be of some interest. I know there are times when I'd like to sort the contents of a REXX array. That is, a stem variable where .0 contains the number of entries, which are in .1 through .??? with no missing numbers. Like a FORTRAN array. This can be a bother to write your own sorting routine in REXX or even some other REXX compatible callable program. UNIX to the rescue! An example:

/* REXX */
XX=SYSCALLS('ON')
If xx > 3 Then Do
Say "SYSCALLS('ON') Failed. RC="xx
exit
End
a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
a.10=6 ; a.11=8 ; a.12='a';
stdout.0=0
stderr.0=0
call bpxwunix "/bin/sort -n",a.,a.,stderr.
say 'a.0='a.0
do i=1 to a.0
say "a."i"="a.i
end
say 'stderr.0='stderr.0
do i=1 to stderr.0
say "stderr."i"="stderr.i
end

Note that in order to sort numerically, I had to include the "-n" switch on the UNIX sort command. Otherwise the data sorts as character strings. But, as you will notice, I the sort will accommodate string data. That is the "-n" doesn't require numeric only data. Note that the "key" for sorting is the entire record, but you can use "fields" (blank delimited data) by using the "-k" switch. For more information on the UNIX sort command, see:
http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxa500/sort.htm


--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions, send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Thom Stone
2016-10-26 02:34:34 UTC
Permalink
Raw Message
Here is a routine I picked up off this list somewhere along the way. I cannot remember who the author was, but I did find it useful at times and I found the interpret a rather interesting method to pull code into an existing program.

/********************************************************************/
/* SORTSTEM USING COMBSORT METHOD */
/* CALLING PROGRAM CALLS SORTSTEM AS FOLLOWS: */
/* internally */
/* 1) CALL SORTSTEM 'STEMNAME 'DIR */
/* 1A)INTERPRET RESULT */
/* OR */
/* externally */
/* 2) INTERPRET SORTSTEM('STEMNAME 'DIR) */
/* DIR CAN BE ASCENDING OR DESCENDING AND CAN BE ABREVIATED A OR D. */
ARG NAME DIRECTION
IF ABBREV("DESCENDING", TRANSLATE(DIRECTION), 1) THEN,
COMPARISON = "<"
ELSE
COMPARISON = ">"
/* RETURN INSTRUCTION RETURNS A STRING OF CODE TO CALLING PROGRAM. */
/* THE CALLING PROGRAM USES 'INTERPRET RESULT' TO PROCESS THE */
/* RETURNED STRING OF CODE. */
RETURN "IF "NAME".0 > 1 THEN ;",
"DO ;",
"$$_GAP = "NAME".0 ;",
"DO UNTIL \$$_SWAPPED & ($$_GAP = 1) ;",
"$$_GAP = MAX(($$_GAP / 1.3) % 1, 1) ;",
"$$_SWAPPED = (1=0) ;",
"DO $$_I = 1 TO "NAME".0 - $$_GAP ;",
"$$_J = $$_I + $$_GAP ;",
"IF" NAME".$$_I" COMPARISON NAME".$$_J THEN ;",
"DO ;",
"$$_HOLD = "NAME".$$_I ;",
NAME".$$_I = "NAME".$$_J ;",
NAME".$$_J = $$_HOLD ;",
"$$_SWAPPED = (1=1) ;",
"END ;",
"END ;",
"END ;",
"DROP $$_GAP $$_SWAPPED $$_I $$_J $$_HOLD ;",
"END"
/********************************************************************/


-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of John McKown
Sent: Tuesday, October 25, 2016 1:56 PM
To: TSO-***@VM.MARIST.EDU
Subject: [TSO-REXX] An evil though? Sorting a REXX array "in place" using UNIX

OK, this is likely weird, but may be of some interest. I know there are times when I'd like to sort the contents of a REXX array. That is, a stem variable where .0 contains the number of entries, which are in .1 through .??? with no missing numbers. Like a FORTRAN array. This can be a bother to write your own sorting routine in REXX or even some other REXX compatible callable program. UNIX to the rescue! An example:

/* REXX */
XX=SYSCALLS('ON')
If xx > 3 Then Do
Say "SYSCALLS('ON') Failed. RC="xx
exit
End
a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
a.10=6 ; a.11=8 ; a.12='a';
stdout.0=0
stderr.0=0
call bpxwunix "/bin/sort -n",a.,a.,stderr.
say 'a.0='a.0
do i=1 to a.0
say "a."i"="a.i
end
say 'stderr.0='stderr.0
do i=1 to stderr.0
say "stderr."i"="stderr.i
end

Note that in order to sort numerically, I had to include the "-n" switch on the UNIX sort command. Otherwise the data sorts as character strings. But, as you will notice, I the sort will accommodate string data. That is the "-n" doesn't require numeric only data. Note that the "key" for sorting is the entire record, but you can use "fields" (blank delimited data) by using the "-k" switch. For more information on the UNIX sort command, see:
http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxa500/sort.htm


--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions, send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Bob Bridges
2016-11-01 03:21:39 UTC
Permalink
Raw Message
Ok, I don't get it. I have an external subroutine that sorts the queue by calling the local SORT routine (SYNCSORT or DFSORT, whichever is present). When that's available, with all SORT's capabilities, why write one to sort a stem variable?

I probably sound like I'm trying to be a spoilsport, but mostly I figure I'll just find out I'm ignorantly missing something obvious.

And thanks, John, for tossing me over the side into a sea of XKCD cartoons. It's been a while since I've been there and I'm 'way behind. Another half hour gone, and I'm nowhere near caught up.

---
Bob Bridges
***@gmail.com, cell 336 382-7313
***@InfoSecInc.com

/* I think what happens to toddlers is that they suddenly realize their parents have essentially been lying to them their whole lives. We represent the world as this wonderful place where you are free to do as you please, not even stopping to use the bathroom if you don’t feel like it, and everyone keeps bringing you toys and your food comes from breasts. We keep it up until you are far too big to climb back in the womb, and then, surprise! Broccoli! -W Bruce Cameron on the Terrible Twos, May 2006 */


-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of John McKown
Sent: Tuesday, October 25, 2016 14:56

OK, this is likely weird, but may be of some interest. I know there are times when I'd like to sort the contents of a REXX array. That is, a stem variable where .0 contains the number of entries, which are in .1 through .??? with no missing numbers. Like a FORTRAN array. This can be a bother to write your own sorting routine in REXX or even some other REXX compatible callable program. UNIX to the rescue! An example:

/* REXX */
XX=SYSCALLS('ON')
If xx > 3 Then Do
Say "SYSCALLS('ON') Failed. RC="xx
exit
End
a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
a.10=6 ; a.11=8 ; a.12='a';
stdout.0=0
stderr.0=0
call bpxwunix "/bin/sort -n",a.,a.,stderr.
say 'a.0='a.0
do i=1 to a.0
say "a."i"="a.i
end
say 'stderr.0='stderr.0
do i=1 to stderr.0
say "stderr."i"="stderr.i
end

Note that in order to sort numerically, I had to include the "-n" switch on the UNIX sort command. Otherwise the data sorts as character strings. But, as you will notice, I the sort will accommodate string data. That is the "-n" doesn't require numeric only data. Note that the "key" for sorting is the entire record, but you can use "fields" (blank delimited data) by using the "-k" switch. For more information on the UNIX sort command, see:
http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxa500/sort.htm


--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Bill Ashton
2016-11-01 11:40:26 UTC
Permalink
Raw Message
Bob, this has me a little curious - how do you use SORT to sort a stem
variable collection? Could you give an example? Or do you mean (by external
routine) that you call some assembler program that links to SORT?

Billy

On Mon, Oct 31, 2016 at 11:21 PM, Bob Bridges <***@gmail.com> wrote:

> Ok, I don't get it. I have an external subroutine that sorts the queue by
> calling the local SORT routine (SYNCSORT or DFSORT, whichever is present).
> When that's available, with all SORT's capabilities, why write one to sort
> a stem variable?
>
> I probably sound like I'm trying to be a spoilsport, but mostly I figure
> I'll just find out I'm ignorantly missing something obvious.
>
> And thanks, John, for tossing me over the side into a sea of XKCD
> cartoons. It's been a while since I've been there and I'm 'way behind.
> Another half hour gone, and I'm nowhere near caught up.
>
> ---
> Bob Bridges
> ***@gmail.com, cell 336 382-7313
> ***@InfoSecInc.com
>
> /* I think what happens to toddlers is that they suddenly realize their
> parents have essentially been lying to them their whole lives. We
> represent the world as this wonderful place where you are free to do as you
> please, not even stopping to use the bathroom if you don’t feel like it,
> and everyone keeps bringing you toys and your food comes from breasts. We
> keep it up until you are far too big to climb back in the womb, and then,
> surprise! Broccoli! -W Bruce Cameron on the Terrible Twos, May 2006 */
>
>
> -----Original Message-----
> From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf
> Of John McKown
> Sent: Tuesday, October 25, 2016 14:56
>
> OK, this is likely weird, but may be of some interest. I know there are
> times when I'd like to sort the contents of a REXX array. That is, a stem
> variable where .0 contains the number of entries, which are in .1 through
> .??? with no missing numbers. Like a FORTRAN array. This can be a bother to
> write your own sorting routine in REXX or even some other REXX compatible
> callable program. UNIX to the rescue! An example:
>
> /* REXX */
> XX=SYSCALLS('ON')
> If xx > 3 Then Do
> Say "SYSCALLS('ON') Failed. RC="xx
> exit
> End
> a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> a.10=6 ; a.11=8 ; a.12='a';
> stdout.0=0
> stderr.0=0
> call bpxwunix "/bin/sort -n",a.,a.,stderr.
> say 'a.0='a.0
> do i=1 to a.0
> say "a."i"="a.i
> end
> say 'stderr.0='stderr.0
> do i=1 to stderr.0
> say "stderr."i"="stderr.i
> end
>
> Note that in order to sort numerically, I had to include the "-n" switch
> on the UNIX sort command. Otherwise the data sorts as character strings.
> But, as you will notice, I the sort will accommodate string data. That is
> the "-n" doesn't require numeric only data. Note that the "key" for sorting
> is the entire record, but you can use "fields" (blank delimited data) by
> using the "-k" switch. For more information on the UNIX sort command, see:
> http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> com.ibm.zos.v2r1.bpxa500/sort.htm
>
>
> --
> Heisenberg may have been here.
>
> Unicode: http://xkcd.com/1726/
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>



--
Thank you and best regards,
*Billy Ashton*

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Hobart Spitz
2016-11-01 13:09:32 UTC
Permalink
Raw Message
Billy, et al:

Here's my view:

First, commercial sort software is highly tuned for speed and efficiency,
under a very wide range of data set sizes and resource availability.
Unless the data you are sorting is on the very small side, you won't be
able to to do better.

Second, REXX has a garbage collection routine that get invoked anytime free
storage is exhausted. It takes a lot of resources in both CPU and working
set. The faster free storage is allocated, the more often garbage
collection takes place. Each assignment to a non-constant chews up some of
the free storage. A swap of two variables using 3 assignments chews free
storage quickly. (There are sort variations that do the first and last
assignment outside of the inner-most loop, saving about two-thirds.) Once
the size of your sort file is so large that it triggers garbage collection,
it's like trying to run with casts on both legs and both arms. (You can
try sorting just the keys, but that is even more work and you can't beat a
external sort in most cases.) The bottom line is: As great a language as
REXX is and as much as you might think otherwise, writing a fully general
sort routine that can handle all expected and unexpected cases is just not
a good idea.

Finally are the issue of maintenance and reinventing-the-wheel. Using an
external sort means the next guy doesn't have to understand your sort, and
can't mess it up when he doesn't get it. Why reinvent the wheel when your
site has paid good money for someone else to worry about all the various
cases and changes that can come up? E.g., should I use dataspaces, VIO,
disk, tape? Are the keys too long to sort separately?

I hope this helps.

On Tue, Nov 1, 2016 at 7:40 AM, Bill Ashton <***@gmail.com> wrote:

> Bob, this has me a little curious - how do you use SORT to sort a stem
> variable collection? Could you give an example? Or do you mean (by external
> routine) that you call some assembler program that links to SORT?
>
> Billy
>
> On Mon, Oct 31, 2016 at 11:21 PM, Bob Bridges <***@gmail.com>
> wrote:
>
> > Ok, I don't get it. I have an external subroutine that sorts the queue
> by
> > calling the local SORT routine (SYNCSORT or DFSORT, whichever is
> present).
> > When that's available, with all SORT's capabilities, why write one to
> sort
> > a stem variable?
> >
> > I probably sound like I'm trying to be a spoilsport, but mostly I figure
> > I'll just find out I'm ignorantly missing something obvious.
> >
> > And thanks, John, for tossing me over the side into a sea of XKCD
> > cartoons. It's been a while since I've been there and I'm 'way behind.
> > Another half hour gone, and I'm nowhere near caught up.
> >
> > ---
> > Bob Bridges
> > ***@gmail.com, cell 336 382-7313
> > ***@InfoSecInc.com
> >
> > /* I think what happens to toddlers is that they suddenly realize their
> > parents have essentially been lying to them their whole lives. We
> > represent the world as this wonderful place where you are free to do as
> you
> > please, not even stopping to use the bathroom if you don’t feel like it,
> > and everyone keeps bringing you toys and your food comes from breasts.
> We
> > keep it up until you are far too big to climb back in the womb, and then,
> > surprise! Broccoli! -W Bruce Cameron on the Terrible Twos, May 2006 */
> >
> >
> > -----Original Message-----
> > From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf
> > Of John McKown
> > Sent: Tuesday, October 25, 2016 14:56
> >
> > OK, this is likely weird, but may be of some interest. I know there are
> > times when I'd like to sort the contents of a REXX array. That is, a stem
> > variable where .0 contains the number of entries, which are in .1 through
> > .??? with no missing numbers. Like a FORTRAN array. This can be a bother
> to
> > write your own sorting routine in REXX or even some other REXX compatible
> > callable program. UNIX to the rescue! An example:
> >
> > /* REXX */
> > XX=SYSCALLS('ON')
> > If xx > 3 Then Do
> > Say "SYSCALLS('ON') Failed. RC="xx
> > exit
> > End
> > a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> > a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> > a.10=6 ; a.11=8 ; a.12='a';
> > stdout.0=0
> > stderr.0=0
> > call bpxwunix "/bin/sort -n",a.,a.,stderr.
> > say 'a.0='a.0
> > do i=1 to a.0
> > say "a."i"="a.i
> > end
> > say 'stderr.0='stderr.0
> > do i=1 to stderr.0
> > say "stderr."i"="stderr.i
> > end
> >
> > Note that in order to sort numerically, I had to include the "-n" switch
> > on the UNIX sort command. Otherwise the data sorts as character strings.
> > But, as you will notice, I the sort will accommodate string data. That is
> > the "-n" doesn't require numeric only data. Note that the "key" for
> sorting
> > is the entire record, but you can use "fields" (blank delimited data) by
> > using the "-k" switch. For more information on the UNIX sort command,
> see:
> > http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> > com.ibm.zos.v2r1.bpxa500/sort.htm
> >
> >
> > --
> > Heisenberg may have been here.
> >
> > Unicode: http://xkcd.com/1726/
> >
> > ----------------------------------------------------------------------
> > For TSO-REXX subscribe / signoff / archive access instructions,
> > send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
> >
>
>
>
> --
> Thank you and best regards,
> *Billy Ashton*
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>



--
OREXXMan

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Ze'ev Atlas
2016-11-01 15:20:24 UTC
Permalink
Raw Message
I am conviced that the external sort (whether th z/OS or the Unix) would be better then anything we could code and I would definitly use that option any time.  The question was how to use it to sort a stem... I second this question since I admit that I do not know how to do it with either Dfsort or SyncsortZA

Sent from Yahoo Mail on Android

On Tue, Nov 1, 2016 at 9:09 AM, Hobart Spitz<***@GMAIL.COM> wrote: Billy, et al:

Here's my view:

First, commercial sort software is highly tuned for speed and efficiency,
under a very wide range of data set sizes and resource availability.
Unless the data you are sorting is on the very small side, you won't be
able to to do better.

Second, REXX has a garbage collection routine that get invoked anytime free
storage is exhausted.  It takes a lot of resources in both CPU and working
set.  The faster free storage is allocated, the more often garbage
collection takes place.  Each assignment to a non-constant chews up some of
the free storage.  A swap of two variables using 3 assignments chews free
storage quickly.  (There are sort variations that do the first and last
assignment outside of the inner-most loop, saving about two-thirds.)  Once
the size of your sort file is so large that it triggers garbage collection,
it's like trying to run with casts on both legs and both arms.  (You can
try sorting just the keys, but that is even more work and you can't beat a
external sort in most cases.)  The bottom line is:  As great a language as
REXX is and as much as you might think otherwise, writing a fully general
sort routine that can handle all expected and unexpected cases is just not
a good idea.

Finally are the issue of maintenance and reinventing-the-wheel.  Using an
external sort means the next guy doesn't have to understand your sort, and
can't mess it up when he doesn't get it.  Why reinvent the wheel when your
site has paid good money for someone else to worry about all the various
cases and changes that can come up?  E.g., should I use dataspaces, VIO,
disk, tape?  Are the keys too long to sort separately?

I hope this helps.

On Tue, Nov 1, 2016 at 7:40 AM, Bill Ashton <***@gmail.com> wrote:

> Bob, this has me a little curious - how do you use SORT to sort a stem
> variable collection? Could you give an example? Or do you mean (by external
> routine) that you call some assembler program that links to SORT?
>
> Billy
>
> On Mon, Oct 31, 2016 at 11:21 PM, Bob Bridges <***@gmail.com>
> wrote:
>
> > Ok, I don't get it.  I have an external subroutine that sorts the queue
> by
> > calling the local SORT routine (SYNCSORT or DFSORT, whichever is
> present).
> > When that's available, with all SORT's capabilities, why write one to
> sort
> > a stem variable?
> >
> > I probably sound like I'm trying to be a spoilsport, but mostly I figure
> > I'll just find out I'm ignorantly missing something obvious.
> >
> > And thanks, John, for tossing me over the side into a sea of XKCD
> > cartoons.  It's been a while since I've been there and I'm 'way behind.
> > Another half hour gone, and I'm nowhere near caught up.
> >
> > ---
> > Bob Bridges
> >  ***@gmail.com, cell 336 382-7313
> >  ***@InfoSecInc.com
> >
> > /* I think what happens to toddlers is that they suddenly realize their
> > parents have essentially been lying to them their whole lives.  We
> > represent the world as this wonderful place where you are free to do as
> you
> > please, not even stopping to use the bathroom if you don’t feel like it,
> > and everyone keeps bringing you toys and your food comes from breasts.
> We
> > keep it up until you are far too big to climb back in the womb, and then,
> > surprise!  Broccoli!  -W Bruce Cameron on the Terrible Twos, May 2006 */
> >
> >
> > -----Original Message-----
> > From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf
> > Of John McKown
> > Sent: Tuesday, October 25, 2016 14:56
> >
> > OK, this is likely weird, but may be of some interest. I know there are
> > times when I'd like to sort the contents of a REXX array. That is, a stem
> > variable where .0 contains the number of entries, which are in .1 through
> > .??? with no missing numbers. Like a FORTRAN array. This can be a bother
> to
> > write your own sorting routine in REXX or even some other REXX compatible
> > callable program. UNIX to the rescue! An example:
> >
> > /* REXX */
> > XX=SYSCALLS('ON')
> > If xx > 3 Then Do
> >    Say "SYSCALLS('ON') Failed. RC="xx
> >    exit
> > End
> > a.0=12  ; a.1=11  ; a.2=5  ; a.3=7  ; a.4=2  ;
> > a.5=10  ; a.6=9  ; a.7=3  ; a.8=1  ; a.9=4  ;
> > a.10=6  ; a.11=8  ; a.12='a';
> > stdout.0=0
> > stderr.0=0
> > call bpxwunix "/bin/sort -n",a.,a.,stderr.
> > say 'a.0='a.0
> > do  i=1 to a.0
> >    say "a."i"="a.i
> > end
> > say 'stderr.0='stderr.0
> > do  i=1 to stderr.0
> >    say "stderr."i"="stderr.i
> > end
> >
> > Note that in order to sort numerically, I had to include the "-n" switch
> > on the UNIX sort command. Otherwise the data sorts as character strings.
> > But, as you will notice, I the sort will accommodate string data. That is
> > the "-n" doesn't require numeric only data. Note that the "key" for
> sorting
> > is the entire record, but you can use "fields" (blank delimited data) by
> > using the "-k" switch. For more information on the UNIX sort command,
> see:
> > http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> > com.ibm.zos.v2r1.bpxa500/sort.htm
> >
> >
> > --
> > Heisenberg may have been here.
> >
> > Unicode: http://xkcd.com/1726/
> >
> > ----------------------------------------------------------------------
> > For TSO-REXX subscribe / signoff / archive access instructions,
> > send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
> >
>
>
>
> --
> Thank you and best regards,
> *Billy Ashton*
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>



--
OREXXMan

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Farley, Peter x23353
2016-11-01 15:28:58 UTC
Permalink
Raw Message
PMFJI here, but I think the key point is the size of the data to be sorted. Very small or even only somewhat small sort record volume (count of STEM entries) would (IMHO) make it highly inefficient to sort using the external system SORT program. As far as I can tell, to use an external SORT you have to EXECIO write the data to be sorted to a temporary SORTIN file and EXECIO read back the results from a temporary SORTOUT file. Very expensive processing involved all around there, ALLOC's and FREE's plus EXECIO's plus ADDRESS LINKMVS, etc. Not cheap at all.

Even using the z/OS Unix "sort" interface would not necessarily be less expensive than a Rexx sort routine. The SYSCALL environment has costs as well.

Again IMHO, Rexx stems with only a few hundred or even a few thousand members are not going to chew up that much storage being sorted by Rexx code. Besides, using PROFILE VARSTORAGE HIGH for IKJEFTxx environments provides more than sufficient storage to the Rexx interpreter not to cause garbage collection in most reasonable Rexx application situations. I regularly use REGION=200M or more for batch Rexx programs with no problem. Using Rexx to process millions or more of entities of any kind is not really a "reasonable" Rexx application situation.

Besides that, any programmer who messes around with a pre-written (and therefore presumably pre-tested) Rexx sort routine will get what they asked for -- trouble.

HTH

Peter

-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of Hobart Spitz
Sent: Tuesday, November 01, 2016 9:10 AM
To: TSO-***@VM.MARIST.EDU
Subject: Re: An evil though? Sorting a REXX array "in place" using UNIX

Billy, et al:

Here's my view:

First, commercial sort software is highly tuned for speed and efficiency,
under a very wide range of data set sizes and resource availability.
Unless the data you are sorting is on the very small side, you won't be
able to to do better.

Second, REXX has a garbage collection routine that get invoked anytime free
storage is exhausted. It takes a lot of resources in both CPU and working
set. The faster free storage is allocated, the more often garbage
collection takes place. Each assignment to a non-constant chews up some of
the free storage. A swap of two variables using 3 assignments chews free
storage quickly. (There are sort variations that do the first and last
assignment outside of the inner-most loop, saving about two-thirds.) Once
the size of your sort file is so large that it triggers garbage collection,
it's like trying to run with casts on both legs and both arms. (You can
try sorting just the keys, but that is even more work and you can't beat a
external sort in most cases.) The bottom line is: As great a language as
REXX is and as much as you might think otherwise, writing a fully general
sort routine that can handle all expected and unexpected cases is just not
a good idea.

Finally are the issue of maintenance and reinventing-the-wheel. Using an
external sort means the next guy doesn't have to understand your sort, and
can't mess it up when he doesn't get it. Why reinvent the wheel when your
site has paid good money for someone else to worry about all the various
cases and changes that can come up? E.g., should I use dataspaces, VIO,
disk, tape? Are the keys too long to sort separately?

I hope this helps.

On Tue, Nov 1, 2016 at 7:40 AM, Bill Ashton <***@gmail.com> wrote:

> Bob, this has me a little curious - how do you use SORT to sort a stem
> variable collection? Could you give an example? Or do you mean (by external
> routine) that you call some assembler program that links to SORT?
>
> Billy
>
> On Mon, Oct 31, 2016 at 11:21 PM, Bob Bridges <***@gmail.com>
> wrote:
>
> > Ok, I don't get it. I have an external subroutine that sorts the queue
> by
> > calling the local SORT routine (SYNCSORT or DFSORT, whichever is
> present).
> > When that's available, with all SORT's capabilities, why write one to
> sort
> > a stem variable?
> >
> > I probably sound like I'm trying to be a spoilsport, but mostly I figure
> > I'll just find out I'm ignorantly missing something obvious.
> >
> > And thanks, John, for tossing me over the side into a sea of XKCD
> > cartoons. It's been a while since I've been there and I'm 'way behind.
> > Another half hour gone, and I'm nowhere near caught up.
> >
> > ---
> > Bob Bridges
> > ***@gmail.com, cell 336 382-7313
> > ***@InfoSecInc.com
> >
> > /* I think what happens to toddlers is that they suddenly realize their
> > parents have essentially been lying to them their whole lives. We
> > represent the world as this wonderful place where you are free to do as
> you
> > please, not even stopping to use the bathroom if you don’t feel like it,
> > and everyone keeps bringing you toys and your food comes from breasts.
> We
> > keep it up until you are far too big to climb back in the womb, and then,
> > surprise! Broccoli! -W Bruce Cameron on the Terrible Twos, May 2006 */
> >
> >
> > -----Original Message-----
> > From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf
> > Of John McKown
> > Sent: Tuesday, October 25, 2016 14:56
> >
> > OK, this is likely weird, but may be of some interest. I know there are
> > times when I'd like to sort the contents of a REXX array. That is, a stem
> > variable where .0 contains the number of entries, which are in .1 through
> > .??? with no missing numbers. Like a FORTRAN array. This can be a bother
> to
> > write your own sorting routine in REXX or even some other REXX compatible
> > callable program. UNIX to the rescue! An example:
> >
> > /* REXX */
> > XX=SYSCALLS('ON')
> > If xx > 3 Then Do
> > Say "SYSCALLS('ON') Failed. RC="xx
> > exit
> > End
> > a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> > a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> > a.10=6 ; a.11=8 ; a.12='a';
> > stdout.0=0
> > stderr.0=0
> > call bpxwunix "/bin/sort -n",a.,a.,stderr.
> > say 'a.0='a.0
> > do i=1 to a.0
> > say "a."i"="a.i
> > end
> > say 'stderr.0='stderr.0
> > do i=1 to stderr.0
> > say "stderr."i"="stderr.i
> > end
> >
> > Note that in order to sort numerically, I had to include the "-n" switch
> > on the UNIX sort command. Otherwise the data sorts as character strings.
> > But, as you will notice, I the sort will accommodate string data. That is
> > the "-n" doesn't require numeric only data. Note that the "key" for
> sorting
> > is the entire record, but you can use "fields" (blank delimited data) by
> > using the "-k" switch. For more information on the UNIX sort command,
> see:
> > http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> > com.ibm.zos.v2r1.bpxa500/sort.htm
> >
> >
> > --
> > Heisenberg may have been here.
> >
> > Unicode: http://xkcd.com/1726/
> >
> > ----------------------------------------------------------------------
> > For TSO-REXX subscribe / signoff / archive access instructions,
> > send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
> >
>
>
>
> --
> Thank you and best regards,
> *Billy Ashton*
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>



--
OREXXMan

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.
Kopischke, David G.
2016-11-01 16:04:33 UTC
Permalink
Raw Message
Here is a clip of an external sort. I deleted a lot of the extraneous code not related to the sort and you'll have to do your own FREE's.

You should be able to get the general idea though. As was already stated, lots of code for a seemingly simple task. And if your stem is 10 records, it seems wasteful.

But it's flexible and fast.



"ALLOC F(SORTIN),
RECFM(F,B) LRECL(80) BLKSIZE(27920),
SPACE(5) CYLINDERS CATALOG"
RetCode=RC
IF RetCode /= 0 THEN DO
SAY "************************************************************"
SAY "An ERROR was detected allocating the SORTIN file"
SAY " The return code from ALLOCate is: " RetCode
SAY "************************************************************"
MaxRC=12
SIGNAL EXIT
END /* IF */

"EXECIO * DISKW SORTIN(FINIS STEM YourStem."
RetCode=RC
IF RetCode /= 0 THEN DO
SAY "************************************************************"
SAY "An ERROR was detected loading the SORTIN file"
SAY " The return code from DISKW is: " RetCode
SAY "************************************************************"
maxRC=12
SIGNAL EXIT
END /* IF */

/* ------------------------------------------------------------------------- */
/* Allocate the SORTWK files. */
/* ------------------------------------------------------------------------- */
"ALLOC F(SYSOUT) SYSOUT(R) HOLD"
maxRC=MAX(rc,maxRC)
"ALLOC F(SORTWK01) SPACE(5) CYLINDERS NEW"
maxRC=MAX(rc,maxRC)
"ALLOC F(SORTWK02) SPACE(5) CYLINDERS NEW"
maxRC=MAX(rc,maxRC)
"ALLOC F(SORTWK03) SPACE(5) CYLINDERS NEW"
maxRC=MAX(rc,maxRC)
"ALLOC F(SORTWK04) SPACE(5) CYLINDERS NEW"
maxRC=MAX(rc,maxRC)
"ALLOC F(SORTWK05) SPACE(5) CYLINDERS NEW"
maxRC=MAX(rc,maxRC)
"ALLOC F(SORTWK06) SPACE(5) CYLINDERS NEW"
maxRC=MAX(rc,maxRC)

IF maxRC \= 0 THEN DO
SAY "************************************************************"
SAY "An ERROR was detected ALLOCating the SORTWK files"
SAY " The highest return code from ALLOCate is: " maxRC
SAY "************************************************************"
maxRC=12
SIGNAL EXIT
END /* IF */

/* ------------------------------------------------------------------------- */
/* Allocate and load the SORT control statements. */
/* ------------------------------------------------------------------------- */
"ALLOC F(SYSIN),
RECFM(F,B) LRECL(80) BLKSIZE(27920),
SPACE(1) TRACKS CATALOG"
RetCode=RC

IF RetCode /= 0 THEN DO
SAY "************************************************************"
SAY "An ERROR was detected allocating the SYSIN file"
SAY " The return code from ALLOCate is: " RetCode
SAY "************************************************************"
maxRC=12
SIGNAL EXIT
END /* IF */

QUEUE " SORT FIELDS=(77,6,CH,A,"
QUEUE " 69,2,CH,A),"
QUEUE " EQUALS"
QUEUE " END"

"EXECIO * DISKW SYSIN(FINIS"
RetCode=RC
IF RetCode /= 0 THEN DO
SAY "************************************************************"
SAY "An ERROR was detected loading the SYSIN SORT Control file"
SAY " The return code from DISKW is: " RetCode
SAY "************************************************************"
maxRC=12
SIGNAL EXIT
END /* IF */

/* ------------------------------------------------------------------------- */
/* Allocate the SORTOUT file. */
/* ------------------------------------------------------------------------- */
"ALLOC F(SORTOUT),
RECFM(F,B) LRECL(111) BLKSIZE(27972),
SPACE(5) CYLINDERS CATALOG"
RetCode=RC
IF RetCode /= 0 THEN DO
SAY "************************************************************"
SAY "An ERROR was detected allocating the SORTOUT file"
SAY " The return code from ALLOCATE is: " RetCode
SAY "************************************************************"
maxRC=12
SIGNAL EXIT

/* ------------------------------------------------------------------------- */
/* SORT the File. */
/* ------------------------------------------------------------------------- */
"SORT"
RetCode=RC
IF RetCode /= 0 THEN DO
SAY "************************************************************"
SAY "An ERROR was detected in the SORT program"
SAY " The return code from SORT is: " RetCode
SAY "************************************************************"
maxRC=12
SIGNAL EXIT
END /* IF */

/* ------------------------------------------------------------------------- */
/* Reload the STEM from the SORTOUT file. */
/* ------------------------------------------------------------------------- */
"EXECIO * DISKR SORTOUT(FINIS STEM YourStem."
RetCode=RC
IF RetCode /= 0 THEN DO
SAY "************************************************************"
SAY "An ERROR was detected reloading the STEM"
SAY " The return code from DISKR is: " RetCode
SAY "************************************************************"
maxRC=12
SIGNAL EXIT
END /* IF */




-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of Farley, Peter x23353
Sent: Tuesday, November 01, 2016 9:29 AM
To: TSO-***@VM.MARIST.EDU
Subject: Re: [TSO-REXX] An evil though? Sorting a REXX array "in place" using UNIX [ EXTERNAL ]

PMFJI here, but I think the key point is the size of the data to be sorted. Very small or even only somewhat small sort record volume (count of STEM entries) would (IMHO) make it highly inefficient to sort using the external system SORT program. As far as I can tell, to use an external SORT you have to EXECIO write the data to be sorted to a temporary SORTIN file and EXECIO read back the results from a temporary SORTOUT file. Very expensive processing involved all around there, ALLOC's and FREE's plus EXECIO's plus ADDRESS LINKMVS, etc. Not cheap at all.

Even using the z/OS Unix "sort" interface would not necessarily be less expensive than a Rexx sort routine. The SYSCALL environment has costs as well.

Again IMHO, Rexx stems with only a few hundred or even a few thousand members are not going to chew up that much storage being sorted by Rexx code. Besides, using PROFILE VARSTORAGE HIGH for IKJEFTxx environments provides more than sufficient storage to the Rexx interpreter not to cause garbage collection in most reasonable Rexx application situations. I regularly use REGION=200M or more for batch Rexx programs with no problem. Using Rexx to process millions or more of entities of any kind is not really a "reasonable" Rexx application situation.

Besides that, any programmer who messes around with a pre-written (and therefore presumably pre-tested) Rexx sort routine will get what they asked for -- trouble.

HTH

Peter

-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of Hobart Spitz
Sent: Tuesday, November 01, 2016 9:10 AM
To: TSO-***@VM.MARIST.EDU
Subject: Re: An evil though? Sorting a REXX array "in place" using UNIX

Billy, et al:

Here's my view:

First, commercial sort software is highly tuned for speed and efficiency, under a very wide range of data set sizes and resource availability.
Unless the data you are sorting is on the very small side, you won't be able to to do better.

Second, REXX has a garbage collection routine that get invoked anytime free storage is exhausted. It takes a lot of resources in both CPU and working set. The faster free storage is allocated, the more often garbage collection takes place. Each assignment to a non-constant chews up some of the free storage. A swap of two variables using 3 assignments chews free storage quickly. (There are sort variations that do the first and last assignment outside of the inner-most loop, saving about two-thirds.) Once the size of your sort file is so large that it triggers garbage collection, it's like trying to run with casts on both legs and both arms. (You can try sorting just the keys, but that is even more work and you can't beat a external sort in most cases.) The bottom line is: As great a language as REXX is and as much as you might think otherwise, writing a fully general sort routine that can handle all expected and unexpected cases is just not a good idea.

Finally are the issue of maintenance and reinventing-the-wheel. Using an external sort means the next guy doesn't have to understand your sort, and can't mess it up when he doesn't get it. Why reinvent the wheel when your site has paid good money for someone else to worry about all the various cases and changes that can come up? E.g., should I use dataspaces, VIO, disk, tape? Are the keys too long to sort separately?

I hope this helps.

On Tue, Nov 1, 2016 at 7:40 AM, Bill Ashton <***@gmail.com> wrote:

> Bob, this has me a little curious - how do you use SORT to sort a stem
> variable collection? Could you give an example? Or do you mean (by
> external
> routine) that you call some assembler program that links to SORT?
>
> Billy
>
> On Mon, Oct 31, 2016 at 11:21 PM, Bob Bridges <***@gmail.com>
> wrote:
>
> > Ok, I don't get it. I have an external subroutine that sorts the
> > queue
> by
> > calling the local SORT routine (SYNCSORT or DFSORT, whichever is
> present).
> > When that's available, with all SORT's capabilities, why write one
> > to
> sort
> > a stem variable?
> >
> > I probably sound like I'm trying to be a spoilsport, but mostly I
> > figure I'll just find out I'm ignorantly missing something obvious.
> >
> > And thanks, John, for tossing me over the side into a sea of XKCD
> > cartoons. It's been a while since I've been there and I'm 'way behind.
> > Another half hour gone, and I'm nowhere near caught up.
> >
> > ---
> > Bob Bridges
> > ***@gmail.com, cell 336 382-7313
> > ***@InfoSecInc.com
> >
> > /* I think what happens to toddlers is that they suddenly realize
> > their parents have essentially been lying to them their whole lives.
> > We represent the world as this wonderful place where you are free to
> > do as
> you
> > please, not even stopping to use the bathroom if you don’t feel like
> > it, and everyone keeps bringing you toys and your food comes from breasts.
> We
> > keep it up until you are far too big to climb back in the womb, and
> > then, surprise! Broccoli! -W Bruce Cameron on the Terrible Twos,
> > May 2006 */
> >
> >
> > -----Original Message-----
> > From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On
> > Behalf Of John McKown
> > Sent: Tuesday, October 25, 2016 14:56
> >
> > OK, this is likely weird, but may be of some interest. I know there
> > are times when I'd like to sort the contents of a REXX array. That
> > is, a stem variable where .0 contains the number of entries, which
> > are in .1 through .??? with no missing numbers. Like a FORTRAN
> > array. This can be a bother
> to
> > write your own sorting routine in REXX or even some other REXX
> > compatible callable program. UNIX to the rescue! An example:
> >
> > /* REXX */
> > XX=SYSCALLS('ON')
> > If xx > 3 Then Do
> > Say "SYSCALLS('ON') Failed. RC="xx
> > exit
> > End
> > a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> > a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> > a.10=6 ; a.11=8 ; a.12='a';
> > stdout.0=0
> > stderr.0=0
> > call bpxwunix "/bin/sort -n",a.,a.,stderr.
> > say 'a.0='a.0
> > do i=1 to a.0
> > say "a."i"="a.i
> > end
> > say 'stderr.0='stderr.0
> > do i=1 to stderr.0
> > say "stderr."i"="stderr.i
> > end
> >
> > Note that in order to sort numerically, I had to include the "-n"
> > switch on the UNIX sort command. Otherwise the data sorts as character strings.
> > But, as you will notice, I the sort will accommodate string data.
> > That is the "-n" doesn't require numeric only data. Note that the
> > "key" for
> sorting
> > is the entire record, but you can use "fields" (blank delimited
> > data) by using the "-k" switch. For more information on the UNIX
> > sort command,
> see:
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__www.ibm.com_supp
> > ort_knowledgecenter_SSLTBW-5F2.1.0_&d=CwIGaQ&c=huW-Z3760n7oNORvLCN2e
> > JBo4X7nIGCr9Ffht-z0f4k&r=7y2-aoC1glAeawrOzHv8FarGRVHFsFSXoree4-WqQwA
> > &m=DHroR0HHrNhMlCJUI67ZrihoaY6uhBklWcmZ09yGaug&s=4fX-SVRd2bhm2eB_DNc
> > 2HzGvrhaMFw9OizS6YsPv6lw&e=
> > com.ibm.zos.v2r1.bpxa500/sort.htm
> >
> >
> > --
> > Heisenberg may have been here.
> >
> > Unicode:
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__xkcd.com_1726_&d
> > =CwIGaQ&c=huW-Z3760n7oNORvLCN2eJBo4X7nIGCr9Ffht-z0f4k&r=7y2-aoC1glAe
> > awrOzHv8FarGRVHFsFSXoree4-WqQwA&m=DHroR0HHrNhMlCJUI67ZrihoaY6uhBklWc
> > mZ09yGaug&s=U7-jE-6-PVsyKyUp2tXorDQMS2lQwt1UCC7LS6q4UWU&e=
> >
> > --------------------------------------------------------------------
> > -- For TSO-REXX subscribe / signoff / archive access instructions,
> > send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
> >
>
>
>
> --
> Thank you and best regards,
> *Billy Ashton*
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions, send
> email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>



--
OREXXMan

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions, send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

This e-mail transmission may contain information that is proprietary, privileged and/or confidential and is intended exclusively for the person(s) to whom it is addressed. Any use, copying, retention or disclosure by any person other than the intended recipient or the intended recipient's designees is strictly prohibited. If you are not the intended recipient or their designee, please notify the sender immediately by return e-mail and delete all copies. OppenheimerFunds may, at its sole discretion, monitor, review, retain and/or disclose the content of all email communications.
Paul Gilmartin
2016-11-03 16:58:10 UTC
Permalink
Raw Message
On 2016-11-01, at 10:04, Kopischke, David G. wrote:
>
> Here is a clip of an external sort. I deleted a lot of the extraneous code not related to the sort and you'll have to do your own FREE's.
>
Over a large range, the BPXWUNIX approach wins in simplicity.

And with BPX_SHAREAS='NO' the FREEs are free. I rely on this
routinely. Shame on me!

<SNIP; SNIP; SNIP; ...!\>

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-11-03 16:50:20 UTC
Permalink
Raw Message
No more evil thoughts! It's past Hallowe'en!

On 2016-11-01, at 09:28, Farley, Peter x23353 wrote:

> PMFJI here, but I think the key point is the size of the data to be sorted. Very small or even only somewhat small sort record volume (count of STEM entries) would (IMHO) make it highly inefficient to sort using the external system SORT program. As far as I can tell, to use an external SORT you have to EXECIO write the data to be sorted to a temporary SORTIN file and EXECIO read back the results from a temporary SORTOUT file. Very expensive processing involved all around there, ALLOC's and FREE's plus EXECIO's plus ADDRESS LINKMVS, etc. Not cheap at all.
>
> Even using the z/OS Unix "sort" interface would not necessarily be less expensive than a Rexx sort routine. The SYSCALL environment has costs as well.
>
POSIX pipes eliminate the need for ALLOC and EXECIO. Surely BPXWUNX does a couple
spawn(); I don't know how BPXWUNIX converts a stem to a descriptor nor whether
there's a hazard of overflowing a file buffer (131,072 bytes, IIRC; I could test
that). I don't know the resource cost of spawn(). But when free storage is
critical, spawn() will fork a new address space. BPXAS is expensive.

> Again IMHO, Rexx stems with only a few hundred or even a few thousand members are not going to chew up that much storage being sorted by Rexx code. Besides, using PROFILE VARSTORAGE HIGH for IKJEFTxx environments provides more than sufficient storage to the Rexx interpreter not to cause garbage collection in most reasonable Rexx application situations. I regularly use REGION=200M or more for batch Rexx programs with no problem. Using Rexx to process millions or more of entities of any kind is not really a "reasonable" Rexx application situation.
>
> Besides that, any programmer who messes around with a pre-written (and therefore presumably pre-tested) Rexx sort routine will get what they asked for -- trouble.
>
Beware of quadratic behavior of naive sort techniques.


> -----Original Message-----
> From: Hobart Spitz
> Sent: Tuesday, November 01, 2016 9:10 AM
>
> First, commercial sort software is highly tuned for speed and efficiency,
> under a very wide range of data set sizes and resource availability.
> Unless the data you are sorting is on the very small side, you won't be
> able to to do better.
>
The OP's core suggestion was of a method to interface to an
external sort. If it comes from IBM, it's "commercial".

> Second, REXX has a garbage collection routine that get invoked anytime free
> storage is exhausted.
>
Is this documented? (And is it true for non-IBM Rexxen?) I'm
interested because I've toyed with the idea of a variant of ATTACH
that would run the subtask concurrently, but I suspect that all
arguments would need to be passed by copy-restore to obtained
storage lest garbage collection move them.

Might LINKMVS be invoked when free storage is critically low,
leaving little available for the LINKed program? Or does
Rexx recognize this and force a garbage collection rather
than LINKMVS with insufficient free storage?

Hmmm... CMS Pipelines routinely runs concurrent Rexx stages.
I wonder how it avoids garbage collection contention? I
should ask there.

I once worked with a language where the progrmmer could:
o Electively call the garbage collector.
o Disable-enable garbage collection over critical sections
where native-interface might hold pointers to managed
storage.
o Create pointers to external, non-managed storage.

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Ed Long
2016-11-01 15:36:03 UTC
Permalink
Raw Message
PMFJI? What does that mean?

Edward Long

--------------------------------------------
On Tue, 11/1/16, Farley, Peter x23353 <***@BROADRIDGE.COM> wrote:

Subject: Re: [TSO-REXX] An evil though? Sorting a REXX array "in place" using UNIX
To: TSO-***@VM.MARIST.EDU
Date: Tuesday, November 1, 2016, 11:28 AM

PMFJI here, but I think
the key point is the size of the data to be sorted.  Very
small or even only somewhat small sort record volume (count
of STEM entries) would (IMHO) make it highly inefficient to
sort using the external system SORT program.  As far as I
can tell, to use an external SORT you have to EXECIO write
the data to be sorted to a temporary SORTIN file and EXECIO
read back the results from a temporary SORTOUT file.  Very
expensive processing involved all around there, ALLOC's
and FREE's plus EXECIO's plus ADDRESS LINKMVS,
etc.  Not cheap at all.

Even using the z/OS Unix "sort"
interface would not necessarily be less expensive than a
Rexx sort routine.  The SYSCALL environment has costs as
well.

Again IMHO, Rexx
stems with only a few hundred or even a few thousand members
are not going to chew up that much storage being sorted by
Rexx code.  Besides, using PROFILE VARSTORAGE HIGH for
IKJEFTxx environments provides more than sufficient storage
to the Rexx interpreter not to cause garbage collection in
most reasonable Rexx application situations.  I regularly
use REGION=200M or more for batch Rexx programs with no
problem.  Using Rexx to process millions or more of
entities of any kind is not really a "reasonable"
Rexx application situation.

Besides that, any programmer who messes around
with a pre-written (and therefore presumably pre-tested)
Rexx sort routine will get what they asked for --
trouble.

HTH

Peter

-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU]
On Behalf Of Hobart Spitz
Sent: Tuesday,
November 01, 2016 9:10 AM
To: TSO-***@VM.MARIST.EDU
Subject: Re: An evil though? Sorting a REXX
array "in place" using UNIX

Billy, et al:

Here's my view:

First, commercial sort software is highly tuned
for speed and efficiency,
under a very wide
range of data set sizes and resource availability.
Unless the data you are sorting is on the very
small side, you won't be
able to to do
better.

Second, REXX has a
garbage collection routine that get invoked anytime free
storage is exhausted.  It takes a lot of
resources in both CPU and working
set.  The
faster free storage is allocated, the more often garbage
collection takes place.  Each assignment to a
non-constant chews up some of
the free
storage.  A swap of two variables using 3 assignments chews
free
storage quickly.  (There are sort
variations that do the first and last
assignment outside of the inner-most loop,
saving about two-thirds.)  Once
the size of
your sort file is so large that it triggers garbage
collection,
it's like trying to run with
casts on both legs and both arms.  (You can
try sorting just the keys, but that is even
more work and you can't beat a
external
sort in most cases.)  The bottom line is:  As great a
language as
REXX is and as much as you might
think otherwise, writing a fully general
sort routine that can handle all expected and
unexpected cases is just not
a good idea.

Finally are the issue of
maintenance and reinventing-the-wheel.  Using an
external sort means the next guy doesn't
have to understand your sort, and
can't
mess it up when he doesn't get it.  Why reinvent the
wheel when your
site has paid good money for
someone else to worry about all the various
cases and changes that can come up?  E.g.,
should I use dataspaces, VIO,
disk, tape? 
Are the keys too long to sort separately?

I hope this helps.

On Tue, Nov 1, 2016 at 7:40
AM, Bill Ashton <***@gmail.com>
wrote:

> Bob, this has
me a little curious - how do you use SORT to sort a stem
> variable collection? Could you give an
example? Or do you mean (by external
>
routine) that you call some assembler program that links to
SORT?
>
> Billy
>
> On Mon, Oct 31, 2016
at 11:21 PM, Bob Bridges <***@gmail.com>
> wrote:
>
> > Ok, I don't get it.  I have an
external subroutine that sorts the queue
> by
> > calling the
local SORT routine (SYNCSORT or DFSORT, whichever is
> present).
> > When
that's available, with all SORT's capabilities, why
write one to
> sort
>
> a stem variable?
> >
> > I probably sound like I'm trying
to be a spoilsport, but mostly I figure
>
> I'll just find out I'm ignorantly missing
something obvious.
> >
> > And thanks, John, for tossing me over
the side into a sea of XKCD
> >
cartoons.  It's been a while since I've been there
and I'm 'way behind.
> >
Another half hour gone, and I'm nowhere near caught
up.
> >
> >
---
> > Bob Bridges
> >   ***@gmail.com,
cell 336 382-7313
> >   ***@InfoSecInc.com
> >
> > /* I think
what happens to toddlers is that they suddenly realize
their
> > parents have essentially
been lying to them their whole lives.  We
> > represent the world as this wonderful
place where you are free to do as
>
you
> > please, not even stopping to
use the bathroom if you don’t feel like it,
> > and everyone keeps bringing you toys
and your food comes from breasts.
> We
> > keep it up until you are far too big
to climb back in the womb, and then,
>
> surprise!  Broccoli!  -W Bruce Cameron on the
Terrible Twos, May 2006 */
> >
> >
> >
-----Original Message-----
> > From:
TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU]
On Behalf
> > Of John McKown
> > Sent: Tuesday, October 25, 2016
14:56
> >
> >
OK, this is likely weird, but may be of some interest. I
know there are
> > times when I'd
like to sort the contents of a REXX array. That is, a
stem
> > variable where .0 contains
the number of entries, which are in .1 through
> > .??? with no missing numbers. Like a
FORTRAN array. This can be a bother
>
to
> > write your own sorting routine
in REXX or even some other REXX compatible
> > callable program. UNIX to the rescue!
An example:
> >
>
> /* REXX */
> >
XX=SYSCALLS('ON')
> > If xx
> 3 Then Do
> >    Say
"SYSCALLS('ON') Failed. RC="xx
> >    exit
> >
End
> > a.0=12  ; a.1=11  ;
a.2=5   ; a.3=7   ;
a.4=2   ;
> > a.5=10  ;
a.6=9   ; a.7=3   ;
a.8=1   ; a.9=4   ;
> > a.10=6  ; a.11=8  ;
a.12='a';
> > stdout.0=0
> > stderr.0=0
> >
call bpxwunix "/bin/sort -n",a.,a.,stderr.
> > say 'a.0='a.0
> > do  i=1 to a.0
>
>     say "a."i"="a.i
> > end
> > say
'stderr.0='stderr.0
> > do 
i=1 to stderr.0
> > 
   say
"stderr."i"="stderr.i
> > end
> >
> > Note that in order to sort
numerically, I had to include the "-n" switch
> > on the UNIX sort command. Otherwise
the data sorts as character strings.
>
> But, as you will notice, I the sort will accommodate
string data. That is
> > the
"-n" doesn't require numeric only data. Note
that the "key" for
> sorting
> > is the entire record, but you can use
"fields" (blank delimited data) by
> > using the "-k" switch. For
more information on the UNIX sort command,
> see:
> > http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> > com.ibm.zos.v2r1.bpxa500/sort.htm
> >
> >
> > --
> >
Heisenberg may have been here.
> >
> > Unicode: http://xkcd.com/1726/
> >
> >
----------------------------------------------------------------------
> > For TSO-REXX subscribe / signoff /
archive access instructions,
> > send
email to ***@VM.MARIST.EDU
with the message: INFO TSO-REXX
> >
>
>
>
> --
> Thank you and best regards,
> *Billy Ashton*
>
>
----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive
access instructions,
> send email to ***@VM.MARIST.EDU
with the message: INFO TSO-REXX
>



--
OREXXMan

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive
access instructions,
send email to ***@VM.MARIST.EDU
with the message: INFO TSO-REXX

This message and any attachments are intended
only for the use of the addressee and may contain
information that is privileged and confidential. If the
reader of the message is not the intended recipient or an
authorized representative of the intended recipient, you are
hereby notified that any dissemination of this communication
is strictly prohibited. If you have received this
communication in error, please notify us immediately by
e-mail and delete the message and any attachments from your
system.


----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
John McKown
2016-11-01 15:39:00 UTC
Permalink
Raw Message
On Tue, Nov 1, 2016 at 10:33 AM, Ed Long <***@prodigy.net> wrote:

> PMFJI? What does that mean?
>

​Pardon Me For Jumping In​



>
> Edward Long
>
>

--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Andreas Fischer
2016-11-03 11:44:46 UTC
Permalink
Raw Message
funny thing. i tried that with the -k parameter but don't get the expected
result (or maybe i misunderstand that parameter?). i wanted to sort just
from second to third position and used:

firc = bpxwunix('sort -n -k 1.2,1.3', string., string., stderr.)

but it will still sort ABC4 and ABC1 to ABC1 and ABC4. any idea why it
does so with -k 1.2,1.3?

besides that, i would not like to take care of blanks or something in the
record, so i would like to consider the whole record as one field. but
considering the description that's not possible except for finding an
unmatched character in the string that can be used with -t option?

regards,
andi


TSO REXX Discussion List <TSO-***@VM.MARIST.EDU> schrieb am 25.10.2016
20:56:15:

> Von: John McKown <***@GMAIL.COM>
> An: TSO-***@VM.MARIST.EDU,
> Datum: 25.10.2016 20:57
> Betreff: [TSO-REXX] An evil though? Sorting a REXX array "in place"
using UNIX
> Gesendet von: TSO REXX Discussion List <TSO-***@VM.MARIST.EDU>
>
> OK, this is likely weird, but may be of some interest. I know there are
> times when I'd like to sort the contents of a REXX array. That is, a
stem
> variable where .0 contains the number of entries, which are in .1
through
> .??? with no missing numbers. Like a FORTRAN array. This can be a bother
to
> write your own sorting routine in REXX or even some other REXX
compatible
> callable program. UNIX to the rescue! An example:
>
> /* REXX */
> XX=SYSCALLS('ON')
> If xx > 3 Then Do
> Say "SYSCALLS('ON') Failed. RC="xx
> exit
> End
> a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> a.10=6 ; a.11=8 ; a.12='a';
> stdout.0=0
> stderr.0=0
> call bpxwunix "/bin/sort -n",a.,a.,stderr.
> say 'a.0='a.0
> do i=1 to a.0
> say "a."i"="a.i
> end
> say 'stderr.0='stderr.0
> do i=1 to stderr.0
> say "stderr."i"="stderr.i
> end
>
> Note that in order to sort numerically, I had to include the "-n" switch
on
> the UNIX sort command. Otherwise the data sorts as character strings.
But,
> as you will notice, I the sort will accommodate string data. That is the
> "-n" doesn't require numeric only data. Note that the "key" for sorting
is
> the entire record, but you can use "fields" (blank delimited data) by
using
> the "-k" switch. For more information on the UNIX sort command, see:
> http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/
> com.ibm.zos.v2r1.bpxa500/sort.htm
>
>
> --
> Heisenberg may have been here.
>
> Unicode: http://xkcd.com/1726/
>
> Maranatha! <><
> John McKown
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
John McKown
2016-11-03 13:02:37 UTC
Permalink
Raw Message
On Thu, Nov 3, 2016 at 6:45 AM, Andreas Fischer <
***@generali.com> wrote:

> funny thing. i tried that with the -k parameter but don't get the expected
> result (or maybe i misunderstand that parameter?). i wanted to sort just
> from second to third position and used:
>
> firc = bpxwunix('sort -n -k 1.2,1.3', string., string., stderr.)
>
> but it will still sort ABC4 and ABC1 to ABC1 and ABC4. any idea why it
> does so with -k 1.2,1.3?
>

​I am assuming:
string.0=2
string.1='ABC4'
string.2='ABC1'

So, you're trying to sort on the 2nd through 3rd character of the first
field. I.e. the "BC" in both strings. The "sort" command is not a stable
sort. That is, it does not retain the relative positioning of equal keys.​
Also, as was pointed out by another in this thread, you need to remember
that UNIX sort is not a "sort by the binary encoding" like DFSORT. It is a
_lexicographical_ sort. That is the sort order for something like
alphabetic characters is not "abc...zABC...Z", but is instead
"AaBbCc...Zz". Even worse the ordering is sensitive to the UNIX locale
setting.



>
> besides that, i would not like to take care of blanks or something in the
> record, so i would like to consider the whole record as one field. but
> considering the description that's not possible except for finding an
> unmatched character in the string that can be used with -t option?
>

​If you want to sort by the entire record as the key, then simply don't
specify a key. In that case the UNIX sort assumes that the entire record is
the key (blanks and all)​. But, thinking about it a bit more, I am guessing
you want to sort more like DFSORT, which uses the "column numbers" in the
"record" as the start and end. In that case, then you do need to find some
"special value" to use as the field delimiter with the -t parameter. A
short example which worked for me:

/* REXX */
DELIM='01'X
STRING.0=2
STRING.1='aB C F E F'
STRING.2='zB C E F'
SORTCMD="sort -k 1.4,1.6 -t '"DELIM"'"
CALL BPXWUNIX SORTCMD,STRING.,STRING.,STDERR.
DO I=1 TO STRING.0
SAY STRING.I
END
SAY '=== STDERR ==='
DO I=1 TO STDERR.0
SAY STDERR.I
END


Notice that I used a non-printable binary value of x'01' as the "field
separator" value to be used with the -t parameter. The output that I got:

zB C E F
aB C F E F
=== STDERR ===



>
> regards,
> andi
>
>

--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Mickey Bee
2016-11-03 14:51:17 UTC
Permalink
Raw Message
For many eons, since before the comet took out the dinosaurs, I have tried
to find an elegant way to do this in Rexx, and really found nothing that
works better than pushing the stem to a temp file, building a SYSIN on the
fly, and calling SYNCSORT to do the dirty work.

Mickey

-----Original Message-----
From: John McKown
Sent: Thursday, November 03, 2016 9:03 AM
To: TSO-***@VM.MARIST.EDU
Subject: Re: [TSO-REXX] Antwort: [TSO-REXX] An evil though? Sorting a REXX
array "in place" using UNIX

On Thu, Nov 3, 2016 at 6:45 AM, Andreas Fischer <
***@generali.com> wrote:

> funny thing. i tried that with the -k parameter but don't get the expected
> result (or maybe i misunderstand that parameter?). i wanted to sort just
> from second to third position and used:
>
> firc = bpxwunix('sort -n -k 1.2,1.3', string., string., stderr.)
>
> but it will still sort ABC4 and ABC1 to ABC1 and ABC4. any idea why it
> does so with -k 1.2,1.3?
>

​I am assuming:
string.0=2
string.1='ABC4'
string.2='ABC1'

So, you're trying to sort on the 2nd through 3rd character of the first
field. I.e. the "BC" in both strings. The "sort" command is not a stable
sort. That is, it does not retain the relative positioning of equal keys.Also,
as was pointed out by another in this thread, you need to remember
that UNIX sort is not a "sort by the binary encoding" like DFSORT. It is a
_lexicographical_ sort. That is the sort order for something like
alphabetic characters is not "abc...zABC...Z", but is instead
"AaBbCc...Zz". Even worse the ordering is sensitive to the UNIX locale
setting.



>
> besides that, i would not like to take care of blanks or something in the
> record, so i would like to consider the whole record as one field. but
> considering the description that's not possible except for finding an
> unmatched character in the string that can be used with -t option?
>

​If you want to sort by the entire record as the key, then simply don't
specify a key. In that case the UNIX sort assumes that the entire record is
the key (blanks and all)​. But, thinking about it a bit more, I am guessing
you want to sort more like DFSORT, which uses the "column numbers" in the
"record" as the start and end. In that case, then you do need to find some
"special value" to use as the field delimiter with the -t parameter. A
short example which worked for me:

/* REXX */
DELIM='01'X
STRING.0=2
STRING.1='aB C F E F'
STRING.2='zB C E F'
SORTCMD="sort -k 1.4,1.6 -t '"DELIM"'"
CALL BPXWUNIX SORTCMD,STRING.,STRING.,STDERR.
DO I=1 TO STRING.0
SAY STRING.I
END
SAY '=== STDERR ==='
DO I=1 TO STDERR.0
SAY STDERR.I
END


Notice that I used a non-printable binary value of x'01' as the "field
separator" value to be used with the -t parameter. The output that I got:

zB C E F
aB C F E F
=== STDERR ===



>
> regards,
> andi
>
>

--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
John McKown
2016-11-03 15:02:02 UTC
Permalink
Raw Message
On Thu, Nov 3, 2016 at 9:51 AM, Mickey Bee <***@comcast.net> wrote:

> For many eons, since before the comet took out the dinosaurs, I have tried
> to find an elegant way to do this in Rexx, and really found nothing that
> works better than pushing the stem to a temp file, building a SYSIN on the
> fly, and calling SYNCSORT to do the dirty work.
>
> Mickey
>
>
​Well, I did say it was "evil" [grin]. The only thing that I don't really
like about using the standard system sort (DFSORT or SyncSORT) is the
necessity of allocating the temporary sort control, sort input & sort
output data sets, writing the data to the sort input DSN, the control cards
to the sort control DSN, then reading the sort output DSN. Yes, it is
undoubtedly a "better" solution on z/OS. Due not only to the, uh,
"peculiarities" of the UNIX sort command but also to the fact that those
sorts are most likely far more efficient. From my (perverted?) viewpoint,
it's too bad the vendors don't supply a UNIX command interface to them.
I.e. a "dfsort", "syncsort", or many "sysort" command so that it is _easy_
to invoke them from a UNIX environment. Hum, another thing to put in my
z/OS Utilities grab bag, I guess.


--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-11-03 17:10:57 UTC
Permalink
Raw Message
On 2016-11-03, at 09:02, John McKown wrote:
>>
> ​Well, I did say it was "evil" [grin]. The only thing that I don't really
> like about using the standard system sort (DFSORT or SyncSORT) is the
> necessity of allocating the temporary sort control, sort input & sort
> output data sets, writing the data to the sort input DSN, the control cards
> to the sort control DSN, then reading the sort output DSN. Yes, it is
> undoubtedly a "better" solution on z/OS. Due not only to the, uh,
> "peculiarities" of the UNIX sort command but also to the fact that those
> sorts are most likely far more efficient. From my (perverted?) viewpoint,
> it's too bad the vendors don't supply a UNIX command interface to them.
> I.e. a "dfsort", "syncsort", or many "sysort" command so that it is _easy_
> to invoke them from a UNIX environment. Hum, another thing to put in my
> z/OS Utilities grab bag, I guess.
>
CMS Pipelines SORT stage will defect to DFSORT (which the customer must
license) for large data. I could imagine a customized alternative
to /bin/sort which is a wrapper to *SORT. Hmmm. Didn't someone
very lately post one in this thread, written in Rexx?

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-11-03 17:02:07 UTC
Permalink
Raw Message
On 2016-11-03, at 08:51, Mickey Bee wrote:

> For many eons, since before the comet took out the dinosaurs, I have tried to find an elegant way to do this in Rexx, and really found nothing that works better than pushing the stem to a temp file, building a SYSIN on the fly, and calling SYNCSORT to do the dirty work.
>
I believe (subject to rebuttal) that DFSORT will accept ALLOCated POSIX
pipes as SORTIN and SORTOUT. Don't know about $YNC$ORT.

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Andreas Fischer
2016-11-04 07:30:03 UTC
Permalink
Raw Message
sure, but i think it's nice to have an alternative, and, as it has been
already stated, the approach with unix sort might be fine for smaller
amount of data. and my usual rexx case deals with manageable amount of
data, for bigger amounts of data i will try to avoid rexx and use sort and
other tools anyway.

regards,
andi


TSO REXX Discussion List <TSO-***@VM.MARIST.EDU> schrieb am 03.11.2016
15:51:00:

> Von: Mickey Bee <***@COMCAST.NET>
> An: TSO-***@VM.MARIST.EDU,
> Datum: 03.11.2016 15:52
> Betreff: Re: [TSO-REXX] Antwort: [TSO-REXX] An evil though? Sorting
> a REXX array "in place" using UNIX
> Gesendet von: TSO REXX Discussion List <TSO-***@VM.MARIST.EDU>
>
> For many eons, since before the comet took out the dinosaurs, I have
tried
> to find an elegant way to do this in Rexx, and really found nothing that

> works better than pushing the stem to a temp file, building a SYSIN on
the
> fly, and calling SYNCSORT to do the dirty work.
>
> Mickey
>
> -----Original Message-----
> From: John McKown
> Sent: Thursday, November 03, 2016 9:03 AM
> To: TSO-***@VM.MARIST.EDU
> Subject: Re: [TSO-REXX] Antwort: [TSO-REXX] An evil though? Sorting a
REXX
> array "in place" using UNIX
>
> On Thu, Nov 3, 2016 at 6:45 AM, Andreas Fischer <
> ***@generali.com> wrote:
>
> > funny thing. i tried that with the -k parameter but don't get the
expected
> > result (or maybe i misunderstand that parameter?). i wanted to sort
just
> > from second to third position and used:
> >
> > firc = bpxwunix('sort -n -k 1.2,1.3', string., string., stderr.)
> >
> > but it will still sort ABC4 and ABC1 to ABC1 and ABC4. any idea why it
> > does so with -k 1.2,1.3?
> >
>
> ​I am assuming:
> string.0=2
> string.1='ABC4'
> string.2='ABC1'
>
> So, you're trying to sort on the 2nd through 3rd character of the first
> field. I.e. the "BC" in both strings. The "sort" command is not a
stable
> sort. That is, it does not retain the relative positioning of equal
> keys.Also,
> as was pointed out by another in this thread, you need to remember
> that UNIX sort is not a "sort by the binary encoding" like DFSORT. It is
a
> _lexicographical_ sort. That is the sort order for something like
> alphabetic characters is not "abc...zABC...Z", but is instead
> "AaBbCc...Zz". Even worse the ordering is sensitive to the UNIX locale
> setting.
>
>
>
> >
> > besides that, i would not like to take care of blanks or something in
the
> > record, so i would like to consider the whole record as one field. but
> > considering the description that's not possible except for finding an
> > unmatched character in the string that can be used with -t option?
> >
>
> ​If you want to sort by the entire record as the key, then simply don't
> specify a key. In that case the UNIX sort assumes that the entire record
is
> the key (blanks and all)​. But, thinking about it a bit more, I am
guessing
> you want to sort more like DFSORT, which uses the "column numbers" in
the
> "record" as the start and end. In that case, then you do need to find
some
> "special value" to use as the field delimiter with the -t parameter. A
> short example which worked for me:
>
> /* REXX */
> DELIM='01'X
> STRING.0=2
> STRING.1='aB C F E F'
> STRING.2='zB C E F'
> SORTCMD="sort -k 1.4,1.6 -t '"DELIM"'"
> CALL BPXWUNIX SORTCMD,STRING.,STRING.,STDERR.
> DO I=1 TO STRING.0
> SAY STRING.I
> END
> SAY '=== STDERR ==='
> DO I=1 TO STDERR.0
> SAY STDERR.I
> END
>
>
> Notice that I used a non-printable binary value of x'01' as the "field
> separator" value to be used with the -t parameter. The output that I
got:
>
> zB C E F
> aB C F E F
> === STDERR ===
>
>
>
> >
> > regards,
> > andi
> >
> >
>
> --
> Heisenberg may have been here.
>
> Unicode: http://xkcd.com/1726/
>
> Maranatha! <><
> John McKown
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-11-03 16:59:11 UTC
Permalink
Raw Message
On 2016-11-03, at 05:45, Andreas Fischer wrote:

> funny thing. i tried that with the -k parameter but don't get the expected
> result (or maybe i misunderstand that parameter?). i wanted to sort just
> from second to third position and used:
>
> firc = bpxwunix('sort -n -k 1.2,1.3', string., string., stderr.)
>
> but it will still sort ABC4 and ABC1 to ABC1 and ABC4. any idea why it
> does so with -k 1.2,1.3?
>
> besides that, i would not like to take care of blanks or something in the
> record, so i would like to consider the whole record as one field. but
> considering the description that's not possible except for finding an
> unmatched character in the string that can be used with -t option?
>
Sorting the entire record is default behaior.

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Andreas Fischer
2016-11-04 07:31:03 UTC
Permalink
Raw Message
if sorting the entire record is default behaviour, why would i code an end
position then at all?

regards,
andi


TSO REXX Discussion List <TSO-***@VM.MARIST.EDU> schrieb am 03.11.2016
17:58:43:

> Von: Paul Gilmartin <***@AIM.COM>
> An: TSO-***@VM.MARIST.EDU,
> Datum: 03.11.2016 18:00
> Betreff: Re: [TSO-REXX] Antwort: [TSO-REXX] An evil though? Sorting
> a REXX array "in place" using UNIX
> Gesendet von: TSO REXX Discussion List <TSO-***@VM.MARIST.EDU>
>
> On 2016-11-03, at 05:45, Andreas Fischer wrote:
>
> > funny thing. i tried that with the -k parameter but don't get the
expected
> > result (or maybe i misunderstand that parameter?). i wanted to sort
just
> > from second to third position and used:
> >
> > firc = bpxwunix('sort -n -k 1.2,1.3', string., string., stderr.)
> >
> > but it will still sort ABC4 and ABC1 to ABC1 and ABC4. any idea why it
> > does so with -k 1.2,1.3?
> >
> > besides that, i would not like to take care of blanks or something in
the
> > record, so i would like to consider the whole record as one field. but
> > considering the description that's not possible except for finding an
> > unmatched character in the string that can be used with -t option?
> >
> Sorting the entire record is default behaior.
>
> -- gil
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
John McKown
2016-11-04 11:58:59 UTC
Permalink
Raw Message
On Fri, Nov 4, 2016 at 2:31 AM, Andreas Fischer <
***@generali.com> wrote:

> if sorting the entire record is default behaviour, why would i code an end
> position then at all?
>

​Good question. Too bad I don't have a good answer. :-) ​



>
> regards,
> andi
>


--
Heisenberg may have been here.

Unicode: http://xkcd.com/1726/

Maranatha! <><
John McKown

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-11-04 16:53:42 UTC
Permalink
Raw Message
On 2016-10-25, at 12:56, John McKown wrote:
>
> OK, this is likely weird, ...
>
Definitely. Another:
The ISPF Edit manual notes that metacharacters in regular expressions
entered at the command line are interpreted according to the terminal
code page. By disappointing experiment, I discover that this applies
likewise to regexen in macros. Means such macros are hardly portable
through a multicultural society. Don't know what happens to macros
called in batch.

> UNIX to the rescue!
>
***@OS/390.25.00: cat bin/FINDIT2
/* Rexx */ signal on novalue; /*
Doc: Demo of page-sensitive regular expressions.
*/
trace Err
address 'ISREDIT'
'macro (X)'
address 'ISPEXEC' 'vget ( ZTERMCP5 ) shared'
CP = ZTERMCP5

P.1 = 'find rc''[xYz€]'''; P.0 = 1

RC= bpxwunix( "set -x; /bin/iconv -f IBM-1047 -t ISO8859-1 |" ,
"/bin/iconv -f UTF-8 -t" CP, "P.", "R.", "stderr." )
if RC<>0 then do
do I = 1 to stderr.0
say stderr.I; end
exit( RC ); end

Cmd = R.1; Cmd
exit RC

Performance is abysmal

I hate EBCDIC!

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-11-08 22:46:40 UTC
Permalink
Raw Message
(A synthesized reply. The original fell out of my inbox,
and the web interface doesn't thread replies.)

> Date: Tue, 25 Oct 2016 13:56:15 -0500
> From: John McKown
>
> OK, this is likely weird, but may be of some interest. I know there are
> times when I'd like to sort the contents of a REXX array. ...
> UNIX to the rescue! An example:
>
> call bpxwunix "/bin/sort -n",a.,a.,stderr.
>
Great minds think alike:
https://www.ibm.com/developerworks/community/blogs/MartinPacker/entry/bpxwunix_z_os_best_kept_secret10?lang=en

But what's interesting and disturbing here is the hostility to UNIX
the subject evinced. There were replies with bubble sorts in Rexx
(well, I guess it is a Rexx forum) and elaborate interfaces to DFSORT
with fistfuls of ALLOCATEs (not even BPXWDYN); EXECIO DISKW;
LINKMVS ICEMAN; EXECIO DISKR; FREE; FREE; ...

But for a small chore and a one-off, Simpler is Better.

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Hamilton, Robert
2016-11-09 16:38:44 UTC
Permalink
Raw Message
So, I wonder if it would solve the problem if you change the LOCALE, or the LC_COLLATE environment variable, so that the OMVS SORT sorts in EBCDIC instead of ASCII?

R;


Rob Hamilton
Sr. System Engineer
Chemical Abstracts Service

>-----Original Message-----
>From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On
>Behalf Of Paul Gilmartin
>Sent: Tuesday, November 8, 2016 5:47 PM
>To: TSO-***@VM.MARIST.EDU
>Subject: Re: An evil though? Sorting a REXX array "in place" using UNIX
>
>(A synthesized reply. The original fell out of my inbox, and the web interface
>doesn't thread replies.)
>
>> Date: Tue, 25 Oct 2016 13:56:15 -0500
>> From: John McKown
>>
>> OK, this is likely weird, but may be of some interest. I know there
>> are times when I'd like to sort the contents of a REXX array. ...
>> UNIX to the rescue! An example:
>>
>> call bpxwunix "/bin/sort -n",a.,a.,stderr.
>>
>Great minds think alike:
>
>https://www.ibm.com/developerworks/community/blogs/MartinPacker/entry/bp
>xwunix_z_os_best_kept_secret10?lang=en
>
>But what's interesting and disturbing here is the hostility to UNIX the subject
>evinced. There were replies with bubble sorts in Rexx (well, I guess it is a
>Rexx forum) and elaborate interfaces to DFSORT with fistfuls of
>ALLOCATEs (not even BPXWDYN); EXECIO DISKW; LINKMVS ICEMAN;
>EXECIO DISKR; FREE; FREE; ...
>
>But for a small chore and a one-off, Simpler is Better.
>
>-- gil
>
>----------------------------------------------------------------------
>For TSO-REXX subscribe / signoff / archive access instructions, send email
>to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

Confidentiality Notice: This electronic message transmission, including any attachment(s), may contain confidential, proprietary, or privileged information from Chemical Abstracts Service ("CAS"), a division of the American Chemical Society ("ACS"). If you have received this transmission in error, be advised that any disclosure, copying, distribution, or use of the contents of this information is strictly prohibited. Please destroy all copies of the message and contact the sender immediately by either replying to this message or calling 614-447-3600.
Paul Gilmartin
2016-11-09 17:55:55 UTC
Permalink
Raw Message
On 2016-11-09, at 09:17, Hamilton, Robert wrote:

> So, I wonder if it would solve the problem if you change the LOCALE, or the LC_COLLATE environment variable, so that the OMVS SORT sorts in EBCDIC instead of ASCII?
>
OMVS sort sorts uses EBCDIC by default, like most of the rest of OMVS.
Welcome to OMVS. OMVS sort is locale-sensitive and uses the same LE
facilities as DFSORT. Both strike me as grossly wrong (and disagreeing
with other platforms) in the En_US locale:

***@OS/390.25.00: ./sortit
3 *-* trace R
4 *-* parse value '9 cat Cat CAT camel Camel CAMEL canary Canary CANARY' ,
with a.0 a.1 a.2 a.3 a.4 a.5 a.6 a.7 a.8 a.9 .

7 *-* call bpxwunix "LC_COLLATE=En_US /bin/sort", "a."
CAMEL
CANARY
CAT
Camel
Canary
Cat
camel
canary
cat

9 *-* say 'Rather than what seems more reasonable:'
10 *-* call bpxwunix "LC_COLLATE=En_CA /bin/sort", "a."
camel
Camel
CAMEL
canary
Canary
CANARY
cat
Cat
CAT
***@OS/390.25.00:

You seem to be familiar with LC_COLLATE. Can you explain these behaviors?

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Hamilton, Robert
2016-11-09 20:33:17 UTC
Permalink
Raw Message
I hate to use the words......z/OS XL C/C++ Programming Guide, chapter 63. That's where the LOCALE info is described. IT SAYS that the default collation for the SAA C locale is EBCDIC, but the default collation for the POSIX C locale is more-or-less-ASCII.

From looking at your sort attempts....your first looks like it's ASCII, so I'm thinking the POSIX C locale. Your second looks like it was just case-insensitive.

I see from this programmer's guide that it is possible to build your own LOCALE/LC_COLLATE....but who wants to use that when you're running an EXEC???

AHA! Appendix F shows a "...typical locale definition file that represents the cultural and language conventions in the United States of America. For this example (LC_COLLATE), note the following:
- The digits (0...9) sort before the letters
- Upper case and lowercase letters have the same primary sorting weight.
- For each letter, the uppercase letter sorts before the equivalent lowercase letter."

That sounds like your latter instance.

Anyway, from one of the earlier appendices...there are a large number of compiled EBCDIC locales; you might want En_US.IBM-037 or En_US.IBM-1047.


I'm not sure what data you are sorting; your camel/canary/cat scenario is good, but you might toss in a digit just to see where it gets sorted.


Dunno whether I've helped any, but...definitely, YGYBYF.

R;


Rob Hamilton
Sr. System Engineer
Chemical Abstracts Service



>-----Original Message-----
>From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On
>Behalf Of Paul Gilmartin
>Sent: Wednesday, November 9, 2016 12:55 PM
>To: TSO-***@VM.MARIST.EDU
>Subject: Re: An evil though? Sorting a REXX array "in place" using UNIX
>
>On 2016-11-09, at 09:17, Hamilton, Robert wrote:
>
>> So, I wonder if it would solve the problem if you change the LOCALE, or
>the LC_COLLATE environment variable, so that the OMVS SORT sorts in
>EBCDIC instead of ASCII?
>>
>OMVS sort sorts uses EBCDIC by default, like most of the rest of OMVS.
>Welcome to OMVS. OMVS sort is locale-sensitive and uses the same LE
>facilities as DFSORT. Both strike me as grossly wrong (and disagreeing with
>other platforms) in the En_US locale:
>
>***@OS/390.25.00: ./sortit
> 3 *-* trace R
> 4 *-* parse value '9 cat Cat CAT camel Camel CAMEL canary Canary
>CANARY' ,
> with a.0 a.1 a.2 a.3 a.4 a.5 a.6 a.7 a.8 a.9 .
>
> 7 *-* call bpxwunix "LC_COLLATE=En_US /bin/sort", "a."
>CAMEL
>CANARY
>CAT
>Camel
>Canary
>Cat
>camel
>canary
>cat
>
> 9 *-* say 'Rather than what seems more reasonable:'
> 10 *-* call bpxwunix "LC_COLLATE=En_CA /bin/sort", "a."
>camel
>Camel
>CAMEL
>canary
>Canary
>CANARY
>cat
>Cat
>CAT
>***@OS/390.25.00:
>
>You seem to be familiar with LC_COLLATE. Can you explain these
>behaviors?
>
>-- gil
>
>----------------------------------------------------------------------
>For TSO-REXX subscribe / signoff / archive access instructions, send email
>to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

Confidentiality Notice: This electronic message transmission, including any attachment(s), may contain confidential, proprietary, or privileged information from Chemical Abstracts Service ("CAS"), a division of the American Chemical Society ("ACS"). If you have received this transmission in error, be advised that any disclosure, copying, distribution, or use of the contents of this information is strictly prohibited. Please destroy all copies of the message and contact the sender immediately by either replying to this message or calling 614-447-3600.

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Bass, Walter W
2016-11-09 20:34:29 UTC
Permalink
Raw Message
> You seem to be familiar with LC_COLLATE. Can you explain these behaviors?

Well, it's WAD based on the binary values of the EBCDIC characters, but if
you want to see something astonishingly non-intuitive, toss in a zebra:

list = '12 cat Cat CAT camel Camel CAMEL ',
'canary Canary CANARY zebra Zebra ZEBRA'
parse value list,
with a.0 a.1 a.2 a.3 a.4 a.5 a.6 a.7 a.8 a.9 a.10 a.11 a.12 .

En_US collating sequence:
CAMEL
CANARY
CAT
Camel
Canary
Cat
ZEBRA
Zebra
camel
canary
cat
zebra

En_CA collating sequence:
camel
Camel
CAMEL
canary
Canary
CANARY
cat
Cat
CAT
zebra
Zebra
ZEBRA

Walter (Bill) Bass
United HealthCare - Optum

This e-mail, including attachments, may include confidential and/or
proprietary information, and may be used only by the person or entity
to which it is addressed. If the reader of this e-mail is not the intended
recipient or his or her authorized agent, the reader is hereby notified
that any dissemination, distribution or copying of this e-mail is
prohibited. If you have received this e-mail in error, please notify the
sender by replying to this message and delete this e-mail immediately.

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Hamilton, Robert
2016-11-09 20:38:28 UTC
Permalink
Raw Message
Yep, that first one is striking, but definitely what I would expect...the En_US sequence puts uppercase letters before lowercase, so Z would precede c. Of course, in EBCDIC, z precedes C. X-ceptional.

R; B-)

>-----Original Message-----
>From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On
>Behalf Of Bass, Walter W
>Sent: Wednesday, November 9, 2016 3:33 PM
>To: TSO-***@VM.MARIST.EDU
>Subject: Re: An evil though? Sorting a REXX array "in place" using UNIX
>
>> You seem to be familiar with LC_COLLATE. Can you explain these
>behaviors?
>
>Well, it's WAD based on the binary values of the EBCDIC characters, but if
>you want to see something astonishingly non-intuitive, toss in a zebra:
>
>list = '12 cat Cat CAT camel Camel CAMEL ',
> 'canary Canary CANARY zebra Zebra ZEBRA'
>parse value list,
> with a.0 a.1 a.2 a.3 a.4 a.5 a.6 a.7 a.8 a.9 a.10 a.11 a.12 .
>
>En_US collating sequence:
>CAMEL
>CANARY
>CAT
>Camel
>Canary
>Cat
>ZEBRA
>Zebra
>camel
>canary
>cat
>zebra
>
>En_CA collating sequence:
>camel
>Camel
>CAMEL
>canary
>Canary
>CANARY
>cat
>Cat
>CAT
>zebra
>Zebra
>ZEBRA
>
>Walter (Bill) Bass
>United HealthCare - Optum
>
>This e-mail, including attachments, may include confidential and/or
>proprietary information, and may be used only by the person or entity to
>which it is addressed. If the reader of this e-mail is not the intended recipient
>or his or her authorized agent, the reader is hereby notified that any
>dissemination, distribution or copying of this e-mail is prohibited. If you have
>received this e-mail in error, please notify the sender by replying to this
>message and delete this e-mail immediately.
>
>----------------------------------------------------------------------
>For TSO-REXX subscribe / signoff / archive access instructions, send email
>to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

Confidentiality Notice: This electronic message transmission, including any attachment(s), may contain confidential, proprietary, or privileged information from Chemical Abstracts Service ("CAS"), a division of the American Chemical Society ("ACS"). If you have received this transmission in error, be advised that any disclosure, copying, distribution, or use of the contents of this information is strictly prohibited. Please destroy all copies of the message and contact the sender immediately by either replying to this message or calling 614-447-3600.

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2016-11-11 00:34:24 UTC
Permalink
Raw Message
On 2016-11-09 13:33, Bass, Walter W wrote:
>> You seem to be familiar with LC_COLLATE. Can you explain these behaviors?
>
> Well, it's WAD based on the binary values of the EBCDIC characters, but if
> you want to see something astonishingly non-intuitive, toss in a zebra:
>
Actually, no. In EBCDIC the minuscule letters sort before the majuscule.

On 2016-11-09 13:33, Hamilton, Robert wrote:> I hate to use the words......z/OS XL C/C++ Programming Guide, chapter 63. That's where the LOCALE info is described. IT SAYS that the default collation for the SAA C locale is EBCDIC, but the default collation for the POSIX C locale is more-or-less-ASCII.
>
I don't mind the hated words, "RTFM".

> From looking at your sort attempts....your first looks like it's ASCII, so I'm thinking the POSIX C locale. Your second looks like it was just case-insensitive.
> ...
> AHA! Appendix F shows a "...typical locale definition file that represents the cultural and language conventions in the United States of America. For this example (LC_COLLATE), note the following:
> - The digits (0...9) sort before the letters
> - Upper case and lowercase letters have the same primary sorting weight.
> - For each letter, the uppercase letter sorts before the equivalent lowercase letter."
>
> That sounds like your latter instance.
>
Thanks. That can be basis for an SR. But they're likely to argue with
me that "En_US" is not intended to be an LC_COLLATE "that represents the
cultural and language conventions in the United States of America."

> I'm not sure what data you are sorting; your camel/canary/cat scenario is good, but you might toss in a digit just to see where it gets sorted.
>
Done. And the zebra. It's a test.

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Bernd Oppolzer
2016-11-10 09:14:16 UTC
Permalink
Raw Message
Sorry for jumping into this thread very late.

I once had to sort a larger REXX stem, and from earlier experience I knew,
that using bubble sort is a very bad idea; it can stop your application
for minutes,
even if only thousand elements have to be sorted, for example ... the
number of
comparisons goes into the millions. When I changed it to Quicksort
(C.A.R. Hoare,
see Wikipedia), the sort ended in sub-second time.

The problem was, that Quicksort needs recursive procedure calls, and in my
OS/2 implementation of REXX, the number of call levels was limited to 45
ca.,
and that was far too low, so Quicksort had problems already with 60
elements.

So I had to find a non-recursive variant of Quicksort; in fact, you need
to do
some stack management yourself.

Another trick to speed up things: because the records to be sorted are
large,
I extract the keys and build key-index-records; then I sort those
key-index-records
and leave the data records untouched until the last step; only in the
end I read the
records in the sequence of the ordered key-index-table.

You can find the REXX code here:

http://bernd-oppolzer.de/blog_20150115_151000.htm

unfortunately, the variables and the comments are in German.
But if you lookup Quicksort at Wikipedia and compare it with my coding,
you will get the idea, even if you don't speak German.

https://en.wikipedia.org/wiki/Quicksort

Kind regards

Bernd


Am 25.10.2016 um 20:56 schrieb John McKown:
> OK, this is likely weird, but may be of some interest. I know there are
> times when I'd like to sort the contents of a REXX array. That is, a stem
> variable where .0 contains the number of entries, which are in .1 through
> .??? with no missing numbers. Like a FORTRAN array. This can be a bother to
> write your own sorting routine in REXX or even some other REXX compatible
> callable program. UNIX to the rescue! An example:
>
> /* REXX */
> XX=SYSCALLS('ON')
> If xx > 3 Then Do
> Say "SYSCALLS('ON') Failed. RC="xx
> exit
> End
> a.0=12 ; a.1=11 ; a.2=5 ; a.3=7 ; a.4=2 ;
> a.5=10 ; a.6=9 ; a.7=3 ; a.8=1 ; a.9=4 ;
> a.10=6 ; a.11=8 ; a.12='a';
> stdout.0=0
> stderr.0=0
> call bpxwunix "/bin/sort -n",a.,a.,stderr.
> say 'a.0='a.0
> do i=1 to a.0
> say "a."i"="a.i
> end
> say 'stderr.0='stderr.0
> do i=1 to stderr.0
> say "stderr."i"="stderr.i
> end
>
> Note that in order to sort numerically, I had to include the "-n" switch on
> the UNIX sort command. Otherwise the data sorts as character strings. But,
> as you will notice, I the sort will accommodate string data. That is the
> "-n" doesn't require numeric only data. Note that the "key" for sorting is
> the entire record, but you can use "fields" (blank delimited data) by using
> the "-k" switch. For more information on the UNIX sort command, see:
> http://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxa500/sort.htm
>
>
> --
> Heisenberg may have been here.
>
> Unicode: http://xkcd.com/1726/
>
> Maranatha! <><
> John McKown
>
> ----------------------------------------------------------------------
> For TSO-REXX subscribe / signoff / archive access instructions,
> send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
>

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Gerard Schildberger
2016-11-11 23:57:27 UTC
Permalink
Raw Message
On Thursday, November 10, 2016 at 3:14:53 AM UTC-6, Bernd Oppolzer wrote:
> Sorry for jumping into this thread very late.
>
> I once had to sort a larger REXX stem, and from earlier experience I knew,
> that using bubble sort is a very bad idea; it can stop your application
> for minutes,
> even if only thousand elements have to be sorted, for example ... the
> number of
> comparisons goes into the millions. When I changed it to Quicksort
> (C.A.R. Hoare,
> see Wikipedia), the sort ended in sub-second time.
>
> The problem was, that Quicksort needs recursive procedure calls, and in my
> OS/2 implementation of REXX, the number of call levels was limited to 45
> ca.,
> and that was far too low, so Quicksort had problems already with 60
> elements.
----- snipped -----

Here is my version of a non-recursive quicksort (using an array of
random numbers). Using Regina 3.9.1 on a modest PC (in DOS under
Windows), it sorts an array of over 72,000 elements in sub-second
time. I'd be very interested how well it executes on a modern IBM
main-frame.

As usual, the sort subroutine could've used more comments. I hope
the lines don't wrap that bad. If anybody wants, I could re-write
the whole she-bang for a narrower margin.



/*REXX program sorts a stemmed array (of random numbers) using the quick sort algorithm.*/
parse arg # seed . /*obtain optional arguments from the CL*/
if #=='' | #="," then #=100000 /*maybe use the default of 100K numbers*/
if datatype(seed, 'W') then call random ,,seed /*maybe use a seed for the RANDOM BIF*/
do j=1 for #; @.j=random(, 100000); end /*j*/ /*fill array.*/
call time 'R'
call qSort # /*invoke the quicksort subroutine. */
say # 'random numbers took' format(time("E"),,2) 'seconds using Qsort.'
exit /*stick a fork in it, we're all done. */
/*--------------------------------------------------------------------------------------*/
qSort: procedure expose @.; a.1=1; parse arg b.1 /*access the caller's local variable. */
$=1
do while $\==0; L=a.$; t=b.$; $=$-1; if t<2 then iterate
h=L+t-1; ?=L+t%2
if @.h<@.L then if @.?<@.h then do; p=@.h; @.h=@.L; end
else if @.?>@.L then p=@.L
else do; p=@.?; @.?=@.L; end
else if @.?<@.l then p=@.L
else if @.?>@.h then do; p=@.h; @.h=@.L; end
else do; p=@.?; @.?=@.L; end
j=L+1; k=h
do forever
do j=j while j<=k & @.j<=p; end /*a tinie-tiny loop.*/
do k=k by -1 while j <k & @.k>=p; end /*another " " */
if j>=k then leave /*segment finished? */
_=@.j; @.j=@.k; @.k=_ /*swap J&K elements.*/
end /*forever*/
$=$+1
k=j-1; @.L=@.k; @.k=p
if j<=? then do; a.$=j; b.$=h-j+1; $=$+1; a.$=L; b.$=k-L; end
eLse do; a.$=L; b.$=k-L; $=$+1; a.$=j; b.$=h-j+1; end
end /*while $¬==0*/
return

_____________________________________________ Gerard Schildberger
Loading...