Page 1 of 1

Converting CSV file to Fixed Length file

PostPosted: Fri Aug 31, 2012 4:28 pm
by seiko
Hello there!

I have a CSV file, how can I convert it to a fixed textfile?
Every field is also varying in length.
There are also spaces (e.g ',,').
Record lenght is varying to 250.
I am confused, what could its easiest method in cobol?

Thanks

Re: Converting CSV file to Fixed Length file

PostPosted: Fri Aug 31, 2012 4:46 pm
by enrico-sorichetti
if that is the only process to be carried on a <sort> solution might be quicker to develop, faster in execution, more effective overall.
search the forums

fixed language glitches

Re: Converting CSV file to Fixed Length file

PostPosted: Fri Aug 31, 2012 4:48 pm
by Robert Sample
UNSTRING would be the easiest way, but that requires you have no data fields with delimiters in them.

Another option, and the only real solution if you have data fields with delimiters in them, is to use reference modification to look at each byte and split the CSV file into separate fields based on the contents of each byte.

Re: Converting CSV file to Fixed Length file

PostPosted: Fri Aug 31, 2012 5:05 pm
by BillyBoyo
Not the only way...

However, I'm with enrico. As long as you do not have more than 100 fields, your sort product can cope with it, using PARSE, including fields with "embedded delimiters".

Re: Converting CSV file to Fixed Length file

PostPosted: Fri Aug 31, 2012 5:23 pm
by seiko
BillyBoyo wrote:Not the only way...

However, I'm with enrico. As long as you do not have more than 100 fields, your sort product can cope with it, using PARSE, including fields with "embedded delimiters".



What kind of sort? can i have a little sample?

Re: Converting CSV file to Fixed Length file

PostPosted: Fri Aug 31, 2012 5:48 pm
by enrico-sorichetti

Re: Converting CSV file to Fixed Length file

PostPosted: Fri Aug 31, 2012 7:58 pm
by dick scherrer
Hello,

If the ONLY process that needs to be done is to reformat the file (with 100 or less fields), yup - sort would be a good choice.

If the process needs to do other processing (i.e. read a database or vsam file), then a program would be a good choice.

Unfortunately, i have seen processes implemented using multiple passes of the data (makes a difference for a few hundred million records) so that some particular knowledge (sort, fileaid, Easytrieve, etdc) could be exploited without determining if the whole process might be better served in one bit of "code". . .

Re: Converting CSV file to Fixed Length file

PostPosted: Sat Sep 01, 2012 2:45 am
by NicC
There is definitely a solution onthe ibmmainframes forum because I put it there. My first attempt was with Rexx which took about 10 minutes to code up -ok I was slow that day but TPTB did not want a rexx solution because they are iggerant! Note that a Rexx solution is fine for small files but may be a bit slow for huge files.

Re: Converting CSV file to Fixed Length file

PostPosted: Sat Sep 01, 2012 9:02 am
by dick scherrer
Hi Nec,

a Rexx solution is fine for small files but may be a bit slow for huge files.
Ah, the gift of understatement 8-)

d

Re: Converting CSV file to Fixed Length file

PostPosted: Sat Sep 01, 2012 4:33 pm
by NicC
Of course one has to define 'huge'! My Rexx program to convert aseries of COBOL DISPLAYs into a CSV file took less than 1 minute to run and it include 2 sorts - to INCLUDE and OMIT records- and an NDM run with a maximum of 19,000 lines going into the initial sort.