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

How to remove spaces in between.


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gpnavinkumar

New User


Joined: 03 Jul 2015
Posts: 4
Location: United States

PostPosted: Mon Jun 20, 2022 10:03 pm
Reply with quote

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

Senior Member


Joined: 15 Aug 2015
Posts: 1255
Location: Bamberg, Germany

PostPosted: Mon Jun 20, 2022 10:55 pm
Reply with quote

Use PARSE and SQZ where needed.

Remember to use the Code tags button, btw.
Back to top
View user's profile Send private message
gpnavinkumar

New User


Joined: 03 Jul 2015
Posts: 4
Location: United States

PostPosted: Tue Jun 21, 2022 7:22 am
Reply with quote

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

Senior Member


Joined: 15 Aug 2015
Posts: 1255
Location: Bamberg, Germany

PostPosted: Tue Jun 21, 2022 10:04 am
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Jun 22, 2022 8:16 am
Reply with quote

ibmmainframes.com/about47014.html
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Jun 22, 2022 8:47 am
Reply with quote

In many practical cases the simple approach is more than enough
Code:
 INREC FINDREP=(IN=(C' |',C'| '),OUT=C'|',
                DO=10)
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1255
Location: Bamberg, Germany

PostPosted: Wed Jun 22, 2022 5:45 pm
Reply with quote

Thanks for your updates. I appreciate your hints and recommendations.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Jun 22, 2022 5:54 pm
Reply with quote

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. 358.gif
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Jun 24, 2022 8:54 am
Reply with quote

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

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Fri Jun 24, 2022 4:42 pm
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Jun 29, 2022 11:18 pm
Reply with quote

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

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Jun 30, 2022 6:37 am
Reply with quote

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

Senior Member


Joined: 15 Aug 2015
Posts: 1255
Location: Bamberg, Germany

PostPosted: Fri Jul 01, 2022 11:37 am
Reply with quote

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
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 -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
No new posts How to remove block of duplicates DFSORT/ICETOOL 8
Search our Forums:

Back to Top