Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need help in Creating a comma-delimited file using sort

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
Roshnii

New User


Joined: 30 Sep 2008
Posts: 45
Location: bangalore

PostPosted: Wed Oct 01, 2008 5:25 pm    Post subject: Need help in Creating a comma-delimited file using sort
Reply with quote

I need to create a comma-delimited file using sort.
My input file looks like this

Code:

sandrew bangalore  testing   
akash              development
lisa    pune       testing   
john               testing   

Code:


And my output looks like this

Code:

"sandrew","bangalore","testing",
"akash",,,"development",         
"lisa","pune","testing",         
"john",,"testing",               

Code:




Any suggestion will be helpful.
Back to top
View user's profile Send private message

Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Oct 01, 2008 5:35 pm    Post subject:
Reply with quote

Code:

OPTION COPY
INREC FIELDS=(1:C'"',1,10,12:C'","',11,10,C'","',21,10,C'",')
OUTREC FIELDS=(1,39,SQZ=(SHIFT=LEFT))

Back to top
View user's profile Send private message
Roshnii

New User


Joined: 30 Sep 2008
Posts: 45
Location: bangalore

PostPosted: Wed Oct 01, 2008 5:57 pm    Post subject:
Reply with quote

Thanks for the input.

My requirement is if there is no value in any of the field, then the field should have only a , and not ".
Say there are three fields and the value for one field of one record does not have a value, then the output file should have only a comma.
Whereas if the field has value, it should be enclosed within " and should have a comma after it.

I am giving the input again,

Code:

sandrew bangalore  testing   
akash              development
lisa    pune       testing   
john               testing   

Code:


Since the place field for secong record does not have any value, it should have only a , and not enclosed within "".
So my output should look like this

Code:

"sandrew","bangalore","testing",
"akash",,,"development",         
"lisa","pune","testing",         
"john",,"testing",               

Code:


So in the second record after akash it is three ,,,.

Can this be done by sort?

I hope my query is clear.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Wed Oct 01, 2008 11:03 pm    Post subject:
Reply with quote

Quote:
So in the second record after akash it is three ,,,.


No, it would be two commas:

"akash",,"development",

just like its two commas for the last record:

"john",,"testing",

Here's a DFSORT job that will do what you asked for. Since you didn't say, I assumed field1 is in positions 1-9, field2 is in positions 9-18 and field3 is in positons 20-30. I added more variations in the input records for a better test:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
sandrew bangalore  testing
akash              development
lisa    pune       testing
john               testing
        joan       harry
                   harry
bill

        frank      george
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(41:1,30)),
    IFTHEN=(WHEN=(41,7,CH,NE,C' '),
     OVERLAY=(1:C'"',41,7,C'",'),HIT=NEXT),
    IFTHEN=(WHEN=(41,7,CH,EQ,C' '),
     OVERLAY=(1:C',',9X),HIT=NEXT),
    IFTHEN=(WHEN=(49,10,CH,NE,C' '),
     OVERLAY=(11:C'"',49,10,C'",'),HIT=NEXT),
    IFTHEN=(WHEN=(49,10,CH,EQ,C' '),
     OVERLAY=(11:C',',12X),HIT=NEXT),
    IFTHEN=(WHEN=(60,11,CH,NE,C' '),
     OVERLAY=(24:C'"',60,11,C'",'),HIT=NEXT),
    IFTHEN=(WHEN=(60,11,CH,EQ,C' '),
     OVERLAY=(24:C',',13X))
  OUTREC BUILD=(1,37,SQZ=(SHIFT=LEFT))
/*


SORTOUT will have:

Code:

"sandrew","bangalore","testing",   
"akash",,"development",             
"lisa","pune","testing",           
"john",,"testing",                 
,"joan","harry",                   
,,"harry",                         
"bill",,,                           
,,,                                 
,"frank","george",                 
Back to top
View user's profile Send private message
Roshnii

New User


Joined: 30 Sep 2008
Posts: 45
Location: bangalore

PostPosted: Fri Oct 03, 2008 11:58 am    Post subject:
Reply with quote

Awesome !!!!!!!!!!! icon_biggrin.gif It worked just the way I wanted.

Thank you so much for the solution. icon_smile.gif

I had a problem while squeezing. It was ignoring the spaces that is between the characters of a field. For Example, If there is a blank between the first name and the last name, I would not want this space to be vanished.
So I added this option while squeezing
OUTREC BUILD=(1,658,SQZ=(SHIFT=LEFT,PAIR=QUOTE))

and its working fine.

Thanks again icon_smile.gif
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


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

PostPosted: Fri Oct 03, 2008 10:15 pm    Post subject:
Reply with quote

Quote:
I had a problem while squeezing. It was ignoring the spaces that is between the characters of a field. For Example, If there is a blank between the first name and the last name, I would not want this space to be vanished.
So I added this option while squeezing

OUTREC BUILD=(1,658,SQZ=(SHIFT=LEFT,PAIR=QUOTE))


You didn't show that variation in your example, so I didn't code for it. But good for you for figuring out the solution for that variation yourself (that doesn't seem to happen very often here).
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 5 Tue Jan 17, 2017 4:26 pm
No new posts Copy RECFM =VB TO FB file with RECL =... sahil41352 DFSORT/ICETOOL 3 Wed Dec 28, 2016 11:29 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us