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

Unstring in Cobol


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

New User


Joined: 29 Apr 2008
Posts: 9
Location: INDIA

PostPosted: Thu Oct 17, 2013 8:52 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Oct 17, 2013 9:19 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Oct 18, 2013 6:26 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Oct 18, 2013 7:24 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Oct 18, 2013 9:13 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Oct 19, 2013 1:41 am
Reply with quote

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
View user's profile Send private message
madprasy

New User


Joined: 08 Apr 2008
Posts: 34
Location: Chennai

PostPosted: Sat Oct 19, 2013 11:24 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Oct 19, 2013 2:14 pm
Reply with quote

There is already a SORT solution for this requirement here.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top