Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
What is the sixth column? We speak of fields in relation to records. You example shows three fields and the output seems to be sorted on the third field?
[/code] SORT FIELDS=(27,6,CH,A)
Code:
based on the length of the longest third field shown. Adjust the length for the longest field possible.
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
@Vasanth No, the 2nd field in required output is in the order T,K,B,M which is not sorted. however, the 3rd field in in the roder AR,JA,JI,PE, which is sorted. TS hasn't told us how long the field is, though.
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
I still think the sorting is based on the length of the 2nd field on input, which makes sense from TS initial post.
A crude attempt assuming there are no 9 in the second field,
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
I was thinking to swap the bytes around in the field, last first through to first last, appending that key to the record. Sort on the generated key. Drop the generated key.
********************************* TOP OF DATA **********************************
AA 02
QQ 02
REER 04
WWWWWW 06
REREEE 06
ERREERRE 08
REWQERERRE 10
FFFEFRFRFRRRFRF 15
RQEQQQRRRERERRERR 17
******************************** BOTTOM OF DATA ********************************
I did not clean the output record, to show what was going on
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
SYMNAMES, of course. Save a lot of fiddling as well as being self-documenting.
To use, make correct start/len for ORIGINAL-KEY. Make enough of the OK-REV-nn,* fields. Define your ORIGINAL-RECORD correctly. Define GENERATED-KEY at the end of your fixed-length record or the beginning of your variable-lenghth record. OVERLAY-START, when coded like this, will automatically be at the same start position as the start of GENERATED-KEY. Job done. Oh, you can test it fully, of course.
Code:
//SORTLEN EXEC PGM=SORT
//SYMNOUT DD SYSOUT=*
//SYMNAMES DD *
ORIGINAL-KEY,1,5,CH
OK-REV-01,=,1,CH
OK-REV-02,*,1,CH
OK-REV-03,*,1,CH
OK-REV-04,*,1,CH
OK-REV-05,*,1,CH
ORIGINAL-RECORD,1,5,CH
GENERATED-KEY,10,5,CH !!! THESE TWO DEFINITIONS MUST BE CODED
OVERLAY-START,= !!! TOGETHER
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *