Sorting comma delimited file?

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
perumalnk
Member
Posts: 24
Joined: Thu Feb 28, 2008 3:30 am
Location: Denver,USA

Sorting comma delimited file?

Post by perumalnk » Tue Mar 11, 2008 3:12 am

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.

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Tue Mar 11, 2008 4:03 am

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.

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)
/*
SORTOUT would have the following (if you check it carefully, you'll see that it's sorted correctly):

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

perumalnk
Member
Posts: 24
Joined: Thu Feb 28, 2008 3:30 am
Location: Denver,USA

Post by perumalnk » Tue Mar 11, 2008 8:52 am

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.

User avatar
Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:

Post by Frank Yaeger » Tue Mar 11, 2008 8:04 pm

It looks like the function PARSE is not supported in my Mainframe machine
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).
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

perumalnk
Member
Posts: 24
Joined: Thu Feb 28, 2008 3:30 am
Location: Denver,USA

Post by perumalnk » Tue Mar 11, 2008 9:11 pm

Hi Frank,

Thanks a lot !
I will discuss about this with my Tech support team.

Thanks,
Perumal.N.K.

Post Reply

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



Other References
Mainframe Tools and others