Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to read fields with comma in Comma delimitted file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to read fields with comma in Comma delimitted file
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: 642
Location: Whitby, ON, Canada

PostPosted: Mon Mar 14, 2011 10:39 pm    Post subject:
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: 2360
Location: Israel

PostPosted: Mon Mar 14, 2011 10:41 pm    Post subject:
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

Site Director


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

PostPosted: Mon Mar 14, 2011 10:42 pm    Post subject:
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    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 15, 2011 12:03 am    Post subject: Reply to: How to read fields with comma in Comma delimitted
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    Post subject:
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    Post subject:
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

Moderator Team Head


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

PostPosted: Tue Mar 15, 2011 7:49 pm    Post subject: Reply to: How to read fields with comma in Comma delimitted
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: 642
Location: Whitby, ON, Canada

PostPosted: Tue Mar 15, 2011 7:56 pm    Post subject: Re: Reply to: How to read fields with comma in Comma delimit
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

Site Director


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

PostPosted: Tue Mar 15, 2011 7:56 pm    Post subject:
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: 2360
Location: Israel

PostPosted: Wed Mar 16, 2011 12:54 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us