Thank you for your sort card.
but now I may face some issue like in some case trailer got changed.
for ex if there is no record then the trailer should be 'No record'
so can we we have some thing like in sort where we just copy whatever be the headers and trailers .
for ex: header 3 line and trailer 1 line needs to copied to output file and skipped from sorting.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
You can try this as a start. Works with DFSORT.
It adds a new field as the first in the SORT. For the first three records, it will contain 1,2,3. The contents of the header are irrelevant for the process, it is just the first three records. For all others except the trailer it will contain 99998. For the trailer, identified as "TOTAL NO' in bytes 1 to 8, it contains 99999.
NB, without EQUALS the order of duplicates in the third field is however the SORT wants to write them. If you want them in some other order if equal, you'll need to do something.
Code:
//S1 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTIN DD *
PGMNAME
DATE
HEADER1 HEADER2 HEADER3
12345678 554579 TOTAL AMOUNT SOLD
12365789 559870 ALREADY SOLDOUT
12365786 559873 MIDDLE RECORD
12365784 559873 CLOSED RECORD
12365785 559873 EXISTING RECORD
12365780 559873 MIDDLE RECORD
TOTAL NO OF RECORDS:006
//SYSIN DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(133:SEQNUM,5,ZD)),
IFTHEN=(WHEN=(133,5,ZD,GT,+3),OVERLAY=(133:C'99998'),
HIT=NEXT),
IFTHEN=(WHEN=(1,8,CH,EQ,C'TOTAL NO'),
OVERLAY=(133:C'99999'))
SORT FIELDS=(133,5,CH,A,37,25,CH,A)
OUTREC BUILD=(1,132)
Output is:
Code:
PGMNAME
DATE
HEADER1 HEADER2 HEADER3
12365789 559870 ALREADY SOLDOUT
12365784 559873 CLOSED RECORD
12365785 559873 EXISTING RECORD
12365786 559873 MIDDLE RECORD
12365780 559873 MIDDLE RECORD
12345678 554579 TOTAL AMOUNT SOLD
TOTAL NO OF RECORDS:006
but in sort card SORT FIELDS=(133,5,CH,A,37,25,CH,A)
the TRailer record is coming after all headers.
My output is coming
Code:
PGMNAME
DATE
TOTAL NO OF RECORDS:006
HEADER1 HEADER2 HEADER3
12365789 559870 ALREADY SOLDOUT
12365784 559873 CLOSED RECORD
12365785 559873 EXISTING RECORD
12365786 559873 MIDDLE RECORD
12365780 559873 MIDDLE RECORD
12345678 554579 TOTAL AMOUNT SOLD
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Well, I did this.
I "quoted" your latest post.
I "coded" your output data.
This I had to do because even after this long topic you haven't caught on to how to Code your own data.
I copied your formatted data. Pasted it as SYSIN. Ran my job. Again received the correct output, trailer at the end.
Without you showing the actual JCL, cards and input data and messages from the step, all Coded, I can only suggest you try to investigate it yourself. Either you have bloopered something, or there is a foible in Syncsort with simple control cards like this.
Now, just to give you a hand with the investigation (so this topic can get near to a termination), try running this:
Code:
//S1 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTIN DD *
PGMNAME
DATE
HEADER1 HEADER2 HEADER3
12365789 559870 ALREADY SOLDOUT
12365784 559873 CLOSED RECORD
12365785 559873 EXISTING RECORD
12365786 559873 MIDDLE RECORD
12365780 559873 MIDDLE RECORD
12345678 554579 TOTAL AMOUNT SOLD
TOTAL NO OF RECORDS:006
//SYSIN DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(133:SEQNUM,5,ZD)),
IFTHEN=(WHEN=(133,5,ZD,GT,+3),OVERLAY=(133:C'99998'),
HIT=NEXT),
IFTHEN=(WHEN=(1,8,CH,EQ,C'TOTAL NO'),
OVERLAY=(133:C'99999'))
SORT FIELDS=(133,5,CH,A,37,25,CH,A)
OUTREC BUILD=(1,60,133,5)
All I've done is changed the OUTREC so that some trailing blanks are not shown, but the sequence number which has been appended is.
Gives this output, with the latest data you have shown:
Code:
PGMNAME 00001
DATE 00002
HEADER1 HEADER2 HEADER3 00003
12365789 559870 ALREADY SOLDOUT 99998
12365784 559873 CLOSED RECORD 99998
12365785 559873 EXISTING RECORD 99998
12365786 559873 MIDDLE RECORD 99998
12365780 559873 MIDDLE RECORD 99998
12345678 554579 TOTAL AMOUNT SOLD 99998
TOTAL NO OF RECORDS:006 99999
EDIT: If "TOTAL NO" is not actually in 1,8, try -3nadh's suggestion or use the position where it actually is, if fixed.
To your "sometimes there are no records", what does that look like on the input data? If it does not start "TOTAL NO" then code another IFTHEN in the same style taking the same action as the first for the trailer.
Joined: 05 Jan 2007 Posts: 101 Location: chennai (India)
Apologies, I am the culprit who moved the trailer record one step right unintentionally. Since then TS is referring the input from my first post and ignored the actual input.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Fine words, -3nadh, but I'd not blame you. I used TS's latest data...
Anyway, the request was to leave the first three and the last record undisturbed, and it looks like the last record might have multiple values (possibly different locations), so...
This is entirely untested. I "borrowed" the NUM from -3nadh's first solution, but have restricted it to testing one byte. Check that that is long enough for your known data. Now, assuming it works, the last record, assuming it does not have a numeric in position 2, will be outsorted from the data records whatever the actual content of the last/trailer record.
I have left the OUTREC as the "testing" version.
I have to keep remembering how simple this was with DATASORT :-)
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Code:
PGMNAME
DATE
HEADER1 HEADER2 HEADER3
12365784 559873 CLOSED RECORD
12365780 559873 MIDDLE RECORD
12365785 559873 EXISTING RECORD
12345678 554579 TOTAL AMOUNT SOLD
12365786 559873 MIDDLE RECORD
12365789 559870 ALREADY SOLDOUT
A PILE OF PIES
Gives:
Code:
PGMNAME 00001
DATE 00002
HEADER1 HEADER2 HEADER3 00003
12365789 559870 ALREADY SOLDOUT 99998
12365784 559873 CLOSED RECORD 99998
12365785 559873 EXISTING RECORD 99998
12365786 559873 MIDDLE RECORD 99998
12365780 559873 MIDDLE RECORD 99998
12345678 554579 TOTAL AMOUNT SOLD 99998
A PILE OF PIES 99999