Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Question 1

Status
Not open for further replies.

MarcLodge

Programmer
Feb 26, 2002
1,886
GB
Hi All,
Not a Cobol question, but I don't know where else to ask, and I'm sure somebody on this forum will know the answer....

I have a file:
field1 field2 field3 Other fields
AAAAAAAAAAAAAAAA 101010 12345678 blah1
AAAAAAAAAAAAAAAA 101010 12345678 blah2
AAAAAAAAAAAAAAAA 101010 12345678 blah3
BBBBBBBBBBBBBBBB 111010 23456789 more blah

The file is sorted in field1 order, but the values are unique as is shown above eg if field1 is all A's then field2 and field3 will always be the same.

If I subsequently re-sort the file in field2, field3, field1 order, can I GUARANTEE that the order will remain the same ie in the example above will on re-sort, the records ALWAYS be in the same order as shown, or is there a possibility of the sort swapping record 1 for record 2 or 3?

If I've not made this clear, then please say.

Marc

 
Oh and the SORT is an EXEC PGM=SORT from JCL on a OS390
 
There is a high likelihood that some of the records will wind up rearranged. To avoid that, specify the EQUALS option on your SORT statement. Using this option will slow the sort down some, but it preserves the initial record order for records with equal keys. (This works for SYNCSORT on VSE; I assume it's the same on OS/390.).

Glenn

PS - Use the [ignore]
Code:
 [\code] [\ignore]tags around any code or data in your post.  This will force use of a fixed width font and make things line up nicely.
 
Some BINARY SORT routines almost guarantee that the order will change.

If you are not using a SORT utility with features as described in a preview post, try specifying another non-unique (hopefully) field as the secondary key for each sort session.

Dimandja
 
Marc,

The term for the type of sort you are seeking is stable sort. Since this is a COBOL forum [smarty], I will supply a COBOL answer:
Code:
SORT ... WITH DUPLICATES IN ORDER...
Tom Morrison
 
Cheers all, I will have an investigate and a good fiddle on Monday.
Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top