View previous topic :: View next topic
|
Author |
Message |
kaushik8205
New User
Joined: 10 Nov 2006 Posts: 49 Location: Canada
|
|
|
|
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 |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
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 |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
kaushik8205
New User
Joined: 10 Nov 2006 Posts: 49 Location: Canada
|
|
|
|
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 |
|
|
kaushik8205
New User
Joined: 10 Nov 2006 Posts: 49 Location: Canada
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
kaushik8205
New User
Joined: 10 Nov 2006 Posts: 49 Location: Canada
|
|
|
|
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 |
|
|
kratos86
Active User
Joined: 17 Mar 2008 Posts: 148 Location: Anna NGR
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
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 |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
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 |
|
|
|