Hi,
I have a comma delimited file having 35 fields with each field value is separated by a comma.Depending upon the value of the field the position occupied by a particular field differs.For example,
Rec # 1 - 3,10.1.2.45,sxcd,34566........
Rec # 2 - 3,10.22.33.456,sxcd,34566..........
Here i need sort the second field and fourth field.Is there any way to accomplish this?
Thanks,
Perumal.N.K.
Sorting comma delimited file?
Moderators: Frank Yaeger, Moderator Group
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
You can use DFSORT's PARSE function to do this. However, in order to sort correctly, you need to "normalize" the timestamp in your second field. For example, if you had:
4.12.20.452
11.3.18.32
4.12.5.3
it wouldn't sort correctly unless you treated it as:
04.12.20.452
11.03.18.320
04.12.05.300
The DFSORT job below will do what you want. It will extract the fields you want to sort on and normalize them for sorting. I used a better set of test data in SORTIN. I assumed your input file has RECFM=FB and LRECL=80, but you can change the job appropriately for other attributes.
SORTOUT would have the following (if you check it carefully, you'll see that it's sorted correctly):
4.12.20.452
11.3.18.32
4.12.5.3
it wouldn't sort correctly unless you treated it as:
04.12.20.452
11.03.18.320
04.12.05.300
The DFSORT job below will do what you want. It will extract the fields you want to sort on and normalize them for sorting. I used a better set of test data in SORTIN. I assumed your input file has RECFM=FB and LRECL=80, but you can change the job appropriately for other attributes.
Code: Select all
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD *
3,10.1.2.45,sxcd,34566,ABC,...
3,10.22.33.456,sxcd,34566,DEFG,...
50,10.2.33.4,sxcd,12345,HI,...
50,10.2.33.4,sxcd,12344,HI,...
500,5.02.3.42,sxcd,12346,HI,...
500,4.22.30.425,sxcd,12344,HI,...
500,4.22.30.425,sxcd,12343,HI,...
/*
//SORTOUT DD DSN=&&O1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//SYSIN DD *
INREC PARSE=(%=(ENDBEFR=C','),
%01=(ENDBEFR=C'.',FIXLEN=2),
%02=(ENDBEFR=C'.',FIXLEN=2),
%03=(ENDBEFR=C'.',FIXLEN=2),
%04=(ENDBEFR=C',',FIXLEN=3),
%=(ENDBEFR=C','),
%05=(FIXLEN=5)),
OVERLAY=(81:%01,83:%02,85:%03,87:%04,90:%05)
SORT FIELDS=(81,2,UFF,A,83,2,UFF,A,85,2,UFF,A,
87,3,UFF,A,90,5,ZD,A)
OUTREC BUILD=(1,80)
/*
Code: Select all
500,4.22.30.425,sxcd,12343,HI,...
500,4.22.30.425,sxcd,12344,HI,...
500,5.02.3.42,sxcd,12346,HI,...
3,10.1.2.45,sxcd,34566,ABC,...
50,10.2.33.4,sxcd,12344,HI,...
50,10.2.33.4,sxcd,12345,HI,...
3,10.22.33.456,sxcd,34566,DEFG,...
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
Hi Frank,
Thanks a lot for your reply and the detailed example !
I tried the solution in my application Mainframe machine.It looks like the function PARSE is not supported in my Mainframe machine.But this example gave me idea about using the DFSORT.Once again thanks a lot !
Is there anyother way driven by the number of occurance of commas in the record.Like to sort 12th field, by checking the occurance of comma for 11 times.
Thanks,
Perumal.N.K.
Thanks a lot for your reply and the detailed example !
I tried the solution in my application Mainframe machine.It looks like the function PARSE is not supported in my Mainframe machine.But this example gave me idea about using the DFSORT.Once again thanks a lot !
Is there anyother way driven by the number of occurance of commas in the record.Like to sort 12th field, by checking the occurance of comma for 11 times.
Thanks,
Perumal.N.K.
- Frank Yaeger
- Moderator
- Posts: 812
- Joined: Sat Feb 18, 2006 5:45 am
- Location: San Jose, CA
- Contact:
DFSORT's PARSE function has been available since April, 2006. Ask your System Programmer to install z/OS DFSORT V1R5 PTF UK90007 or DFSORT R14 PTF UK90006 (it's free).It looks like the function PARSE is not supported in my Mainframe machine
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page