Page 1 of 1

Sorting CSV files in cobol

PostPosted: Fri Feb 26, 2010 10:52 pm
by krishmain
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

Re: Sorting CSV files in cobol

PostPosted: Fri Feb 26, 2010 11:32 pm
by Robert Sample
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).

Re: Sorting CSV files in cobol

PostPosted: Sat Feb 27, 2010 12:38 am
by dick scherrer
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.

Re: Sorting CSV files in cobol

PostPosted: Sun Feb 28, 2010 7:23 am
by krishmain
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

Re: Sorting CSV files in cobol

PostPosted: Sun Feb 28, 2010 7:58 am
by dick scherrer
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.

Re: Sorting CSV files in cobol

PostPosted: Mon Mar 01, 2010 11:29 pm
by krishmain
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

Re: Sorting CSV files in cobol

PostPosted: Mon Mar 01, 2010 11:47 pm
by ctrevino
Syncsort now has a PARSE function. I saw some posts around using that to sort comma delimited files and convert them to flat files.

Re: Sorting CSV files in cobol

PostPosted: Wed Aug 31, 2016 4:51 pm
by boazh850
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?)