View previous topic :: View next topic
|
Author |
Message |
gpnavinkumar
New User
Joined: 03 Jul 2015 Posts: 4 Location: United States
|
|
|
|
Hi,
I have a file which contains spaces in most of the fields but the spaces in the name field should not be removed.
File:
963 | 16 5|your name| B8675 |
24 | 95 4|your name| C 4 |
Output should look like:
963|165|your name|B8675|
24|954|your name|C4|
If I use SQZ all the spaces are gone including the name field.
Could someone please help,
Thanks in advance. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1305 Location: Bamberg, Germany
|
|
|
|
Use PARSE and SQZ where needed.
Remember to use the Code tags button, btw. |
|
Back to top |
|
|
gpnavinkumar
New User
Joined: 03 Jul 2015 Posts: 4 Location: United States
|
|
|
|
Thanks a lot Joerg
But my input file is in fixed format as given below. As suggested I have added code tags.
Input:
Code: |
963 | 16 5|your name| B8675 |
2 4 | 95 4|your name| C 4 |
|
Desired Output:
Code: |
963|165|your name|B8675|
24|954|your name|C4|
|
|
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1305 Location: Bamberg, Germany
|
|
|
|
Something that comes to my mind is:
Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(FIXLEN=20,STARTAT=NUM,ENDBEFR=C'|',REPEAT=2),
%03=(FIXLEN=20,STARTAT=MC,ENDBEFR=C'|',REPEAT=2)),
BUILD=(%01,C'|',%02,C'|',
%03,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'"'),C'|',%04,C'|')),
IFTHEN=(WHEN=INIT,BUILD=(1,86,SQZ=(SHIFT=LEFT,PAIR=QUOTE))),
IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'"',C'')))
END |
For Input
Code: |
963 | 16 5|your name| B8675 |
2 4 | 95 4|John O'Connor| C 4 | |
it will give:
Code: |
963|165|your name|B8675|
24|954|John O'Connor|C4| |
|
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3075 Location: NYC,USA
|
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2115 Location: USA
|
|
|
|
In many practical cases the simple approach is more than enough
Code: |
INREC FINDREP=(IN=(C' |',C'| '),OUT=C'|',
DO=10) |
|
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1305 Location: Bamberg, Germany
|
|
|
|
Thanks for your updates. I appreciate your hints and recommendations. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2115 Location: USA
|
|
|
|
Joerg.Findeisen wrote: |
Thanks for your updates. I appreciate your hints and recommendations. |
My habit is, not to do the things more complex than they really are. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3075 Location: NYC,USA
|
|
|
|
sergeyken wrote: |
In many practical cases the simple approach is more than enough
Code: |
INREC FINDREP=(IN=(C' |',C'| '),OUT=C'|',
DO=10) |
|
I posted same solution but deleted my post as this doesn’t fit the need fully as TS needs to remove spaces between the words except for name.
Something of this sort
ibmmainframes.com/about50765.html |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2115 Location: USA
|
|
|
|
Rohit Umarjikar wrote: |
sergeyken wrote: |
In many practical cases the simple approach is more than enough
Code: |
INREC FINDREP=(IN=(C' |',C'| '),OUT=C'|',
DO=10) |
|
I posted same solution but deleted my post as this doesn’t fit the need fully as TS needs to remove spaces between the words except for name.
Something of this sort
ibmmainframes.com/about50765.html |
Code: |
INREC FINDREP=(IN=(C' |',C'| '),OUT=C'|',
DO=10)
OUTREC FINDREP=(INOUT=(C' ',C' '),
DO=10) |
|
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3075 Location: NYC,USA
|
|
|
|
sergeyken wrote: |
Rohit Umarjikar wrote: |
sergeyken wrote: |
In many practical cases the simple approach is more than enough
Code: |
INREC FINDREP=(IN=(C' |',C'| '),OUT=C'|',
DO=10) |
|
I posted same solution but deleted my post as this doesn’t fit the need fully as TS needs to remove spaces between the words except for name.
Something of this sort
ibmmainframes.com/about50765.html |
Code: |
INREC FINDREP=(IN=(C' |',C'| '),OUT=C'|',
DO=10)
OUTREC FINDREP=(INOUT=(C' ',C' '),
DO=10) |
|
I kindly suggest you to test this code against the original ask or Joerg's working code. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2115 Location: USA
|
|
|
|
Rohit Umarjikar wrote: |
I kindly suggest you to test this code against the original ask or Joerg's working code. |
Several notes.
1. This post has just confirmed that nobody of TS visitors is interested in learning, or just trying to analyze something, except of getting a ready-to-copy-and-paste solution. Rare exceptions are: some moderators, and retired experts.
2. I really did not test specifically the last code because I reproduced this idea from my own 3-4 years old real production code, which was working perfectly that time, and successfully handled multi-GB unloaded databases before their transfer to another environment. I've already left that project, and I guess all needed data have been converted and transmitted since that time.
3. It is also a surprise for myself, that almost the same code is not working in full now. I can suspect any reason, even malfunctioning enhancement of SORT; no idea so far.
4. Anyone interested in learning multiple approaches to the same task might run a few tests by himself, to find out the updates needed for the working solution:
Code: |
INREC BUILD=(1,80,SQZ=(SHIFT=LEFT,MID=C' '))
SORT FIELDS=COPY
OUTREC FINDREP=(INOUT=(C' |',C'|'))
OUTFIL FINDREP=(INOUT=(C'| ',C'|'))
END |
The changes are required for this workaround of not properly working multi-replacements performed by FINDREP. When separated, they start working again... |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1305 Location: Bamberg, Germany
|
|
|
|
We know that this forum lacks a Feedback Button. Some people think that this is "Put some request in - get a ready-to-copy solution out" only. I am not yet retired, get a lot of practice while reading and trying out here. Of course most provided samples can be enhanced in a certain way, but still this is a Help-Forum. |
|
Back to top |
|
|
|