Sorting CSV files in cobol



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Sorting CSV files in cobol

Postby krishmain » Fri Feb 26, 2010 10:52 pm

Hi ,

I wanted to know what are the sort parameters used for sorting a comma separated file. The comma can occur anywhere in the records.

Thanks,
kris
krishmain
 
Posts: 5
Joined: Fri Feb 26, 2010 2:53 am
Has thanked: 0 time
Been thanked: 0 time

Re: Sorting CSV files in cobol

Postby Robert Sample » Fri Feb 26, 2010 11:32 pm

Normally, COBOL commands are used to convert the file into fixed length variables and then sorted on those fixed length variables. I'm not sure it is possible on the mainframe to directly sort a comma delimited file (but I'm not up to date on the latest SORT innovations, either).
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Sorting CSV files in cobol

Postby dick scherrer » Sat Feb 27, 2010 12:38 am

Hello and welcome to the forum,

Firstly - is this a cobol question or a sort question?

If there is a delimited file i need to sort in a cobol program, i first unstring the data so that i can easily identify the sort keys. Then in an SD i define the sort keys followed by the entire set of delimited data.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Sorting CSV files in cobol

Postby krishmain » Sun Feb 28, 2010 7:23 am

I appreciate your answer for the cobol case but if the requirement is to sort using sort utilities, how would you advise to go about it.

Thanks for your help,
kris
krishmain
 
Posts: 5
Joined: Fri Feb 26, 2010 2:53 am
Has thanked: 0 time
Been thanked: 0 time

Re: Sorting CSV files in cobol

Postby dick scherrer » Sun Feb 28, 2010 7:58 am

Hello,

Well, i posted a cobol reply as the topic mentons cobol and is posted in the cobol part of the forum :)

If you'd like to look for a sort product solution, post which sort product is used on your system. If you are not sure which is used, run any sort and the informational messages will identify which product is used.

Post the information produced by the sort so we will see what is needed to proceed.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Sorting CSV files in cobol

Postby krishmain » Mon Mar 01, 2010 11:29 pm

Hi Scherrer,

The sort utility used here is Syncsort. The requirement is to sort a csv file. I need to know as to what the sort parameters would be. The position of the comma can be arbitrarily at any place in the records and the records are a combination of alphanumeric characters.

Thanks,
kris
krishmain
 
Posts: 5
Joined: Fri Feb 26, 2010 2:53 am
Has thanked: 0 time
Been thanked: 0 time

Re: Sorting CSV files in cobol

Postby ctrevino » Mon Mar 01, 2010 11:47 pm

Syncsort now has a PARSE function. I saw some posts around using that to sort comma delimited files and convert them to flat files.
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Sorting CSV files in cobol

Postby boazh850 » Wed Aug 31, 2016 4:51 pm

u can use this example by syncsort
//*-----------------------------------------------------------------
//* SORT CSV EXAMPLE
//*-----------------------------------------------------------------
//STEP040 EXEC PGM=SORT
//*-----------------------------------------------------------------
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,
// DSN=&SORTIN
//SORTOUT DD DSN=&SORTOUT,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(CYL,(10,10),RLSE)
//SYSIN DD *
INREC PARSE=(%00=(ENDBEFR=C',',FIXLEN=006),
%01=(ENDBEFR=C',',FIXLEN=001),
%02=(ENDBEFR=C',',FIXLEN=001),
%03=(ENDBEFR=C',',FIXLEN=009),
%04=(ENDBEFR=C',',FIXLEN=004),
%05=(FIXLEN=002)),
OVERLAY(30:%00, OLD-REC
37:%01, STAM
39:%02, STAM
41:%03,JFY=(SHIFT=RIGHT,LEAD=C'00'), TZ
51:%04,JFY=(SHIFT=RIGHT,LEAD=C'000'), SIDURI
56:%05)
SORT FIELDS=COPY
OUTREC FIELDS=(001,029,
041,009,
051,004,CHANGE=(004,C'NULL',C'0000'),
NOMATCH=(051,004))

/*

(Do you really think that anyone cares after six and a half years?)
boazh850
 
Posts: 1
Joined: Wed Aug 31, 2016 4:46 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post