Converting CSV file to Fixed Length file



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

Converting CSV file to Fixed Length file

Postby seiko » Fri Aug 31, 2012 4:28 pm

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
seiko
 
Posts: 8
Joined: Fri Aug 31, 2012 8:04 am
Has thanked: 0 time
Been thanked: 0 time

Re: Converting CSV file to Fixed Length file

Postby enrico-sorichetti » Fri Aug 31, 2012 4:46 pm

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
Last edited by enrico-sorichetti on Fri Aug 31, 2012 4:49 pm, edited 2 times in total.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Converting CSV file to Fixed Length file

Postby Robert Sample » Fri Aug 31, 2012 4:48 pm

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.
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: Converting CSV file to Fixed Length file

Postby BillyBoyo » Fri Aug 31, 2012 5:05 pm

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".
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Converting CSV file to Fixed Length file

Postby seiko » Fri Aug 31, 2012 5:23 pm

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?
seiko
 
Posts: 8
Joined: Fri Aug 31, 2012 8:04 am
Has thanked: 0 time
Been thanked: 0 time

Re: Converting CSV file to Fixed Length file

Postby enrico-sorichetti » Fri Aug 31, 2012 5:48 pm

cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Converting CSV file to Fixed Length file

Postby dick scherrer » Fri Aug 31, 2012 7:58 pm

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". . .
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: Converting CSV file to Fixed Length file

Postby NicC » Sat Sep 01, 2012 2:45 am

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Converting CSV file to Fixed Length file

Postby dick scherrer » Sat Sep 01, 2012 9:02 am

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
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: Converting CSV file to Fixed Length file

Postby NicC » Sat Sep 01, 2012 4:33 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post