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

Parse a file to remove " and replace , with ~


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

New User


Joined: 06 Nov 2009
Posts: 14
Location: Singapore

PostPosted: Mon Jul 23, 2012 5:28 pm
Reply with quote

Hi All,

I have a file as mentioned in below sample. I need to parse this file and remove all the quotes " and have to replace all the commas , with ~ sign.

Input: The lenght of all the records are not same.

2004-10-12,"DOUGL",1724,1,"832702","M",4960,"O","20376361",1
2004-10-12,"DOU",1723,1,"161318","M",5119,"OW","20377946",1
2004-10-12,"DOUGLPA",1724,1,"832702","M",4960,"O","20376361",1

Output: The output should be as below

2004-10-12~DOUGL~1724~1~832702~M~4960~O~20376361~1
2004-10-12~DOU~1723~1~161318~M~5119~OW~20377946~1
2004-10-12~DOUGLPA~1724~1~832702~M~4960~O~20376361~1

Regards,
Vineet
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: Mon Jul 23, 2012 5:49 pm
Reply with quote

Please use the Code tags for your data.

Look at FINDREP in the manual. If I have understood correctly, it can do what you want.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon Jul 23, 2012 5:56 pm
Reply with quote

Hello,
This may work,
Code:

  OPTION COPY                                                       
  INREC FINDREP=(INOUT=(C'","',C'~',C',"',C'~',C'",',C'~',C',',C'~'))


Smart DFSORT tricks PDF has many useful and handy tricks with DFSORT. Give it a read, totally worth it.
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: Mon Jul 23, 2012 6:06 pm
Reply with quote

Basically there, but will be simpler if all the quotes are removed first, then all the commas can be changed to tildes. C'' (a character string of no length) indicates the removal of the position occupied by that value. By default the record will be "shuffled" to the left.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon Jul 23, 2012 6:11 pm
Reply with quote

Hello Bill,
You are right, I missed to notice that all fields are separated by , and " were expendable.
Code:
  INREC FINDREP=(INOUT=(C'"',C'',C',',C'~'))

Thanks for correction,
Back to top
View user's profile Send private message
vineetjoshi01

New User


Joined: 06 Nov 2009
Posts: 14
Location: Singapore

PostPosted: Tue Jul 24, 2012 12:39 pm
Reply with quote

Hi Vasanth / Bill,

Thanks for your help!!! It worked fine!!!

Regards,
Vineet
Back to top
View user's profile Send private message
vineetjoshi01

New User


Joined: 06 Nov 2009
Posts: 14
Location: Singapore

PostPosted: Thu Aug 02, 2012 2:59 pm
Reply with quote

Hi Vasanth / Bill,

Could you please help further in this case. Actually I have got comma , as data in some of the record fields. For example "DOUGL,HARON" in below record. I do not want that , to be replaced with ~. So the input will be as follows:

2004-10-12,"DOUGL,HARON",1724,1,"832702","M",4960,"O","20376361",1
2004-10-12,"DOU",1723,1,"161318","M",5119,"OW","20377946",1
2004-10-12,"DOUGLPA",1724,1,"832702","M",4960,"O","20376361",1

Output should be as follows: The , is retained which is part of data but rest of the commas are replaced with ~ sign.

2004-10-12~DOUGL,HARON~1724~1~832702~M~4960~O~20376361~1
2004-10-12~DOU~1723~1~161318~M~5119~OW~20377946~1
2004-10-12~DOUGLPA~1724~1~832702~M~4960~O~20376361~1

Thanks and regards,
Vineet
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 02, 2012 3:09 pm
Reply with quote

looks like you will have to go to parse using the PAIR option
and then BUILD, inserting the tilde between fields.
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: Thu Aug 02, 2012 4:34 pm
Reply with quote

That'll do it. You PARSE the fields using the comma as a delimiter. Those bounded by quotes, use PAIR to preserve any commas inside. Then BUILD your output, with the tilde between each field. Your quote-protected commas will be preserved that way.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Thu Aug 02, 2012 10:18 pm
Reply with quote

vineetjoshi01,

Use the following DFSORT JCL which will give you the desired results. The trick here is to use FINDREP to replace the comma to a space and then use SQZ with PAIR=QUOTE to replace the space with ~. Once that is done we use another SQZ to replace the space within the name to comma. Finally we use another FINDREP to replace the double quotes.

Code:

//STEP0100 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD *                                                     
2004-10-12,"DOUGL,HARON",1724,1,"832702","M",4960,"O","20376361",1 
2004-10-12,"DOU",1723,1,"161318","M",5119,"OW","20377946",1         
2004-10-12,"DOUGLPA",1724,1,"832702","M",4960,"O","20376361",1     
//SORTOUT  DD SYSOUT=*                                 
//SYSIN    DD *                                       
  SORT FIELDS=COPY                                     
  INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C',',C' '))),
  IFTHEN=(WHEN=INIT,                                   
  BUILD=(1,80,SQZ=(SHIFT=LEFT,PAIR=QUOTE,MID=C'~'))), 
  IFTHEN=(WHEN=INIT,                                   
  BUILD=(1,80,SQZ=(SHIFT=LEFT,MID=C','))),             
  IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'"',C'')))       
//*
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 FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
Search our Forums:

Back to Top