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

Need help in Creating a comma-delimited file using sort


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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
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
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 Developer


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

PostPosted: Wed Oct 01, 2008 11:03 pm
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
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 Developer


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

PostPosted: Fri Oct 03, 2008 10:15 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top