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

How to use unstring in this scenerio


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Feb 28, 2012 8:50 pm
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
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
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: 771
Location: Germany

PostPosted: Tue Feb 28, 2012 8:59 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Feb 28, 2012 9:12 pm
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
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

Moderator Emeritus


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

PostPosted: Tue Feb 28, 2012 9:17 pm
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
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
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
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

Moderator Emeritus


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

PostPosted: Tue Feb 28, 2012 9:57 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Handling the numeric data in unstring... COBOL Programming 18
No new posts Unstring COBOL Programming 4
No new posts UNSTRING problem COBOL Programming 3
No new posts UNSTRING a big string COBOL Programming 16
No new posts Unstring list of values into an array. COBOL Programming 8
Search our Forums:

Back to Top