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

Removing Spaces and Inserting delimiter


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Wed Aug 31, 2011 3:06 am
Reply with quote

Hi,

I have to remove trailing spaces for a particular field and but the issue is this field can have spaces in between. I am using

Code:

1,44,SQZ=(SHIFT=LEFT),C',',45,8,SQZ=(SHIFT=LEFT)


But the above one is removing spaces which are in between the value.

My Input looks like (record length=80,Record Format=FB)

Code:

Field1                                        Field2 
(1-44)                                        (45-52)
ABC DEF GHI & JKML                          135 2432


Expected Output

Code:

ABC DEF GHI & JKML,135 2432


But I am getting as below.
Code:

ABCDEFGHI&JKML,1352432


How can we handle spaces which are in between of the field? Appreciate your help.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Aug 31, 2011 3:14 am
Reply with quote

ksk,

Assuming there is a single space between words you can use the following DFSORT JCL which will give you the desired results

Code:

//STEP0100 EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                     
//SORTIN   DD *                                             
ABC DEF GHI & JKML                          135 2432       
//SORTOUT  DD SYSOUT=*                                     
//SYSIN    DD *                                             
  SORT FIELDS=COPY                                         
  INREC BUILD=(1,44,C',',45,8,53,27)                       
  OUTREC FINDREP=(INOUT=(C'  ',C'',C' ,',C',',C', ',C',')) 
//*
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Wed Aug 31, 2011 3:33 am
Reply with quote

Thanks for the immediate reply.

Can you please explain what the below code does?

Code:

INOUT=(C'  ',C'',C' ,',C',',C', ',C',')


Please note that one field can have any number of single spaces in between or cannot have even a single space in between.
For ex,

Code:

A B CDE FGHI KDJFJ D S
ABCDEFGRHYSJFDJFKJFK
SFDHDSFSD ASDSD GFG


In the above I/P, respective field of the first record has 6 single spaces in between and 2nd record does not have any spaces and the third has 2 spaces so on...
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Aug 31, 2011 4:35 am
Reply with quote

ksk wrote:
Can you please explain what the below code does?


The First C'bb' is looking for 2 adjacent spaces(b= blank) and eliminating them. so if there are even number of space at the end they would get all eliminated and the other conditions are checking for odd number of spaces and starting spaces for field 2.

You are fine as long as your field 1 has single spaced words. It doesn't matter how many words you have.

however if your data has
Code:

ABC  FH  <== 2 adjacent spaces between ABC and FH


Your output would be

Code:

ABCFH


So as long as you maintain single spacing between words you are fine.

If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

www.ibm.com/support/docview.wss?rs=114&uid=isg3T7000080
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Aug 31, 2011 5:25 am
Reply with quote

ksk,

Here's another way to do it with DFSORT which will preserve any number of spaces between the words.

Code:

  OPTION COPY                                                       
  INREC IFTHEN=(WHEN=INIT,                                           
   BUILD=(1,44,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'",',LENGTH=47),     
     45,8,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'"',LENGTH=10))),         
   IFTHEN=(WHEN=INIT,BUILD=(1,57,SQZ=(SHIFT=LEFT,PAIR=QUOTE))),     
   IFTHEN=(WHEN=INIT,FINDREP=(IN=C'"',OUT=C''))                     


For example, if the input is:

Code:

ABC DEF GHI & JKML                          135 2432 
ABC DEF GHI & JKML    QR                    135 2432 
ABC DEF GHI & JKML           XYZ      AB    135  432 


The output will be:

Code:

ABC DEF GHI & JKML,135 2432                           
ABC DEF GHI & JKML    QR,135 2432                     
ABC DEF GHI & JKML           XYZ      AB,135  432     
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Thu Sep 01, 2011 2:18 am
Reply with quote

Thanks Kolusu and Frank. Worked perfectly for my requirement.
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
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 Inserting variable length into output... JCL & VSAM 2
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
No new posts How to remove spaces in between. SYNCSORT 12
Search our Forums:

Back to Top