View previous topic :: View next topic
|
Author |
Message |
adrianlmk
New User
Joined: 02 Jan 2008 Posts: 11 Location: Malaysia
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
Back to top |
|
|
adrianlmk
New User
Joined: 02 Jan 2008 Posts: 11 Location: Malaysia
|
|
|
|
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 |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
@ 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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
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
if You can read REXX I might have some prototypes around to show |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
adrianlmk
New User
Joined: 02 Jan 2008 Posts: 11 Location: Malaysia
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
adrianlmk
New User
Joined: 02 Jan 2008 Posts: 11 Location: Malaysia
|
|
|
|
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 |
|
|
|