IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to read fields with comma in Comma delimitted file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kaushik8205

New User


Joined: 10 Nov 2006
Posts: 49
Location: Canada

PostPosted: Mon Mar 14, 2011 9:36 pm
Reply with quote

Hi,

I have an input file which is comma delimited.
This file has some fields which contain commas.

e.g. address fields:
"163, Avenue West"

In output file:
Address should come as 163, Avenue West

All fields in input file having commas as part of the field value will be enclosed in double quotes.

I am using Unstring delimitting by comma but that does not help for such fields.

Please advise as to how to achieve the desired result.

Thanks,
Kaushik
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Mon Mar 14, 2011 10:39 pm
Reply with quote

There are many ways to handle this problem, but they all require a lot of coding. In my opinion, it is easier to use DFSORT to convert the file to a fixed format and then let your Cobol program handle the converted file, the way nature intended.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Mon Mar 14, 2011 10:41 pm
Reply with quote

At first stage, you have to replace all commas between quotes with some other unique character - like asterisk or tilde. Then run your usual unstring, and then replace back to comma.

O.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Mar 14, 2011 10:42 pm
Reply with quote

Hello,

This is one reason that many places no longer use the comma for a delimiter. . .

Suggest you consider changing the delimiter when the file is created to something that cannot occur in the data. If the data is text data, the tab character (x'05') works well and is portable across systems.
Back to top
View user's profile Send private message
kaushik8205

New User


Joined: 10 Nov 2006
Posts: 49
Location: Canada

PostPosted: Mon Mar 14, 2011 10:49 pm
Reply with quote

Thanks All!

I think Ofer's suggestion is best suited for my csae as we cannot change the source file and have limitation of using COBOL only.

Thanks,
Kaushik
Back to top
View user's profile Send private message
kaushik8205

New User


Joined: 10 Nov 2006
Posts: 49
Location: Canada

PostPosted: Mon Mar 14, 2011 11:50 pm
Reply with quote

Hi O,

Can you suggest me the simplest way to replace comma between quotes.

I do not think that it is possible by Inspect. Is there any format of inspect which can replace values between identifiers?

Thanks,
Kaushik
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 15, 2011 12:03 am
Reply with quote

INSPECT CONVERTING will do the trick. The quotes will be ignored, unless they're specified in the INSPECT.

You INSPECT the GIANT-FIELD, which contains the entire CSV file-string, converting comma to "Whatever obscure byte-value of your choosing".

The obscure byte-value could be (for example) X'80'.

Bill
Back to top
View user's profile Send private message
kaushik8205

New User


Joined: 10 Nov 2006
Posts: 49
Location: Canada

PostPosted: Tue Mar 15, 2011 12:18 am
Reply with quote

Bill,

That would convert all the commas to obscure byte-value.

I want to convert only the commas within the quotes to obscure byte-value.
Back to top
View user's profile Send private message
kratos86

Active User


Joined: 17 Mar 2008
Posts: 148
Location: Anna NGR

PostPosted: Tue Mar 15, 2011 7:33 pm
Reply with quote

If you are sure about the starting and end position of the quotes, it will be easy to handle in cobol. Otherwise it requires a lot of coding.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Tue Mar 15, 2011 7:49 pm
Reply with quote

I know I'm not a COBOL guy, but wouldn't it make sense to just "normalize" the data outside of the program first to make handling it a whole lot easier and maintaining it even more so?
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Tue Mar 15, 2011 7:56 pm
Reply with quote

superk wrote:
I know I'm not a COBOL guy, but wouldn't it make sense to just "normalize" the data outside of the program first to make handling it a whole lot easier and maintaining it even more so?
I am a Cobol guy and I totally agree with you. DFSORT does a nice job of converting CSV files to fixed format.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Mar 15, 2011 7:56 pm
Reply with quote

Hello,

If every field has quotes arount it, it will be rather straingtforward regardless of if the quotes are in fixed positions. If not every field has quotes, it will be more difficult.

Quote:
we cannot change the source file
You may not have permission to change this, but someone does or can direct it. Suggest your organization consider a better approach because the need to pass delimited data is on the increase most places i've been.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Wed Mar 16, 2011 12:54 am
Reply with quote

I agree with Don. DFSORT can do the trick, even replacing the commas between quotes. Just post an input example in the DFSORT forum and you'll get an answer.

O.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top