Problem:
When using MFSORT to sort a file how can a record number be added to each record of the Input or Output file
Resolution:
When sorting a file using MFSORT it is possible to add a record number to each record on either the input or resulting output file using the parameter SEQNUM.
Option A
To add to each record on the input file, prior to the sort, specify the parameter on the MFSORT INREC declaration as below:-
inrec fields=(4,13,seqnum,8,zd,start=0,incr=1)
sort fields (2,2,ch,a,4,13,ch,a) use unsortedfile.txt org ls record v,1,20
give sortedfile.txt org ls record (f 30)
Option B
To add to each record on the output file, after the sort, specify the parameter on the MFSORT OUTREC declaration as below:-
outrec fields=(4,13,seqnum,8,zd,start=1,incr=1)
sort fields (2,2,ch,a,4,13,ch,a) use unsortedfile.txt org ls record v,1,20
give sortedfile.txt org ls record (f 30)
In both examples, the record number will be added as an 8 digit zoned decimal sequence number, placed at the end of each record and starting at a value of 1.
Note: When using SEQNUM on INREC, specify start=0 (start being the initial value of the record number) and when on OUTREC specify start=1.
Example Input file prior to MFSORT run using Option A
XZDEFGGHHTTTEERRFFJD XCDEFGGHHTTTEERRFFJD XBDEFGGHHTTTEERRFFJD XHDEFGGHHTTTEERRFFJD XEDEFGGHHTTTEERRFFJD XZAEFGGHHTTTEERRFFJD
Result of MFSORT command using Option B
XBDEFGGHHTTTEERRFFJD00000003 XCDEFGGHHTTTEERRFFJD00000002 XEDEFGGHHTTTEERRFFJD00000005 XHDEFGGHHTTTEERRFFJD00000004 XZAEFGGHHTTTEERRFFJD00000006 XZDEFGGHHTTTEERRFFJD00000001
Incident#3179196
#MFSORTDFSORTSORT
#EnterpriseDeveloper
#MFDS
