View previous topic :: View next topic
|
Author |
Message |
Govardhana krishna
New User
Joined: 29 Apr 2008 Posts: 9 Location: INDIA
|
|
|
|
Hi,
The data in the sting is mixed with Alpha numeric & numeric and every field is separated by comma. (,). but all the alphanumeric fields has a additional quotes in it.
But i need to remove the additioanl quotes from Alphanumeric fields in order to perform unstring by comma to use the data.
Example 1:
'"600","CY",8,"3787660","000043877",14099.83,1166.96,"USD"'.
But I need the above record as shown below:
EXAMPLE2:
'600,CY,8,3787660,000043877,14099.83,1166.96,USD'.
So that i can unstring the data shown in exapmle 2 using just ','.
Note:
I managed to remove the quotes using ICETOOL Replace command but it takes 4 step procedure to remove . But is there any way using Inspect or any cobol command to remove the additional quotes in alphanumeric fields?
Thanks,
Govi. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, you don't need to remove the quotes to get the UNSTRING to work.
If the quotes are not "protecting" a potential embedded comma, then they are useless anyway, and you can request that the provider of the data drops them.
If they are potentially protecting a comma, then your UNSTRING is not going to be reliable anyway.
So which is it? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
INSPECT REPLACE, replaces, does not remove (simple look in the reference would have answered that.)
as Bill said, the easiest would be to have double quotes removed at file creation time,
but often this is not easy to organize,
especially in a big organization.
casual inspection of your data (what little you have provided)
shows that there are probably NO imbedded commas,
so blindly removing the double quotes is probably your solution.
the actual code that SORT would generate probably is the fastest,
(though why it requires 4 steps is beyond me, simple replace '"' with '')
though it involves invoking another program and
a father-son of the file (input and output)
so, fastest would probably be to
write a simple COBOL PERFORM
to run an index down the source string
moving only non-double quote characters to a destination string via a second index.
Small strings (less than 256) could be also addressed thru subscripts without a performance hit.
then UNSTRING from the new area populated by the above routine. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
I have never tried it, but would following not work?
Code: |
UNSTRING xx DELIMITED BY ALL ',' OR ALL '"'... |
or does that only work with ,,, and """ but not with a combination of " and , ?
or maybe try
Code: |
UNSTRING xx DELIMITED BY '","' OR '",' or ',"' or ',' or '"' ... |
not sure how this would respond.
(don't want to test this on my new clients mainframe) |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
With the first you'd get a pile of "empty" fields interspersed with data (and assuming the previous values had been cleared first). You'd not want the ALL either, as multiple commas would not be correctly processed.
The second is a good shot and would work, since you have taken care with the order of the delimiters.
Another possibility is
Code: |
group-item.
subordinate filler length one
subordinate data with final quote |
UNSTRING into fields like that, then deal with the trailing ".
TS has a SORT solution already. Choosing how to do it in COBOL also depends on how the data is to be processed afterwards. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You're standing there cutting mushrooms, when suddenly it comes to you.
It would need "WITH POINTER" to get over the fact that there may be a delimiter as the first character of the data areas. |
|
Back to top |
|
|
madprasy
New User
Joined: 08 Apr 2008 Posts: 34 Location: Chennai
|
|
|
|
Inspect will help if the record length and positiion of the fields are constant..
Else go for SORT, using <competitor link removed> |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
There is already a SORT solution for this requirement here. |
|
Back to top |
|
|
|