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 use unstring in this scenerio

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
adrianlmk

New User


Joined: 02 Jan 2008
Posts: 11
Location: Malaysia

PostPosted: Tue Feb 28, 2012 8:41 pm    Post subject: How to use unstring in this scenerio
Reply with quote

Hi All,

I'm having a issue with my recent code to split my record into respective copybook field.

Here is my sample input

Code:
abcd,,cdef,"New York, US","New business",Jason


Expected output is
Code:
field 1 = abcd
field 2 = spaces
field 3 = cdef
field 4 = New York, US
field 5 = New business
field 6 = Jason

My concern will be more on field 4 because if i using unstring, it will split the field New York, US into 2 different field.
At the same time I want to remove the " from the field4 and field5.

Is it possible to use unstring to get the output as shown above?

Appreciate for the input from you.

Thanks in advance
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Tue Feb 28, 2012 8:50 pm    Post subject: Reply to: How to use unstring in this scenerio
Reply with quote

the best input is the one You might get by reading the manual ( link at top of the page )
or starting from
http://www-03.ibm.com/systems/z/os/zos/bkserv/index.html
hint...
meditate on construct UNSTRING ... DELIMITED BY
Back to top
View user's profile Send private message
adrianlmk

New User


Joined: 02 Jan 2008
Posts: 11
Location: Malaysia

PostPosted: Tue Feb 28, 2012 8:58 pm    Post subject:
Reply with quote

Hi Enrico,

Thanks for your sharing.
I have gone through the manual and I know that I can
use unstring .. delimited by, the only problem is I'm looking for direct way
to split the field correctly without splitting New York, US.

Hope you can enlighten me.
Thanks
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 743
Location: Germany

PostPosted: Tue Feb 28, 2012 8:59 pm    Post subject:
Reply with quote

@ adrianlmk !

At the first moment i'm thinking about prepairing the Field and then do some unstrings, string operations. Perhaps deleting all " first in the input-string. Then changing ",," to ", ,". Then unstring into diverse fileds. Then string field-4 and -5 together in another field. -> new york & us = new york, us.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Tue Feb 28, 2012 9:12 pm    Post subject: Reply to: How to use unstring in this scenerio
Reply with quote

oops, I had not notice the <comma> in the New York token...

I guess You will have to hand parse the string Yourself using the MODIFICATION REFERENCE stuff

not really complicated once You have learned how to do it ...

parsing is not really language dependent, is just a logic issue
once You have mastered it the language is just a lowly technicality
icon_wink.gif

if You can read REXX I might have some prototypes around to show
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Feb 28, 2012 9:13 pm    Post subject:
Reply with quote

problem is that you have double quotes that are used as escape characters,
that allow A field to contain the comma.

not knowing how many 'imbedded' commas would require you to loop until tally is zero:

INSPECT REPLACING FIRST COMMA BY X"FF" AFTER INITIAL DOUBLEQUOTE.

Then twice INSPECT REPLACING FIRST DOUBLEQUOTE BY SPACE

goto loop start.

then you could simply UNSTRING text DELIMITED BY COMMA INTO .....

then INSPECT unstrung-group REPLACING X"FF" BY COMMA.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Tue Feb 28, 2012 9:17 pm    Post subject: Reply to: How to use unstring in this scenerio
Reply with quote

If your file is being sorted at some point prior to needing those fields, you could consider the PARSE in your sort product. I know DFSORT can deal with your issue, creating fixed-length output fields ready for the next step, and it knows not to treat seperators wthin specified delimeters. Not so sure about Syncsort, as I don't have acccess to the documentation.

EDIT: Problem with your field is "user input". You may have more than one comma in a field, unless that is prevented at data-entry. If you have more than one, your unstring can easily pickle things. In the Cobol, I'd go for ODO not reference-modification, for ease of understanding. Don't know if I have one hanging around... if you search this forum for City, State, Zip, you'll find some processing that you may be able to apply.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Feb 28, 2012 9:29 pm    Post subject:
Reply with quote

and if the first char of a field is space, use a move instruction to move the data to the left
(since ibm cobol move is left to right)
either by subdefining the fields or use reference modification.
with reference modification you would need a second move of space to last char.

move field-a(2:length of field - 1) to field-a(1:length of field - 1)
move space to field-a(length of field - 1:1)

now if this was my task, i would do as bill suggested and use the sort product to 'prep' the data.
Back to top
View user's profile Send private message
adrianlmk

New User


Joined: 02 Jan 2008
Posts: 11
Location: Malaysia

PostPosted: Tue Feb 28, 2012 9:45 pm    Post subject:
Reply with quote

Hi Bill & dbz,

Really appreciate for your help. parse in sort was the first trial when I trying deal with the input. But I was facing the issue where the parse used stop before and comma. It will still split my New York, US into 2 different field.

"New York, US" is user entry which can have multiple comma or not even a comma in between. That's the reason I'm finding tough to deal with this input.

In addition, it is possible the input without the New York, US which can be something like this


Code:
abcd,,cdef,"New York, US","New business",Jason
abcd,,cdef,"New York, New Jersey,US",,Jason
abcd,,cded,,"New Business",Jason
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Feb 28, 2012 9:52 pm    Post subject:
Reply with quote

Quote:
Really appreciate for your help. parse in sort was the first trial when I trying deal with the input. But I was facing the issue where the parse used stop before and comma. It will still split my New York, US into 2 different field.


if your sort product is DFSORT,
you erred by not asking Frank or Kolusu for help.
i imagine Alissa would also provide a solution for SYNCSORT.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Tue Feb 28, 2012 9:57 pm    Post subject: Reply to: How to use unstring in this scenerio
Reply with quote

If you resurrect your SORT cards, and check in the manual for PAIR=QUOTE, you should be able to deal with those three cases, and others.
Back to top
View user's profile Send private message
adrianlmk

New User


Joined: 02 Jan 2008
Posts: 11
Location: Malaysia

PostPosted: Tue Feb 28, 2012 10:01 pm    Post subject: Re: Reply to: How to use unstring in this scenerio
Reply with quote

Bill Woodger wrote:
If you resurrect your SORT cards, and check in the manual for PAIR=QUOTE, you should be able to deal with those three cases, and others.


Thanks Bill. Will definitely revisit the manual for SORT manual on Pair=quote.
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 Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts Problem with UNSTRING of CSV data Bill Woodger COBOL Programming 14 Tue Dec 15, 2015 5:32 pm
No new posts Unstring in Cobol Govardhana krishna COBOL Programming 7 Thu Oct 17, 2013 8:52 pm
No new posts Unstring the message d katkuri COBOL Programming 13 Wed Aug 14, 2013 12:28 pm
No new posts UNSTRING of Variable length Data kedianirmal COBOL Programming 9 Thu Jul 18, 2013 3:25 pm


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