|
View previous topic :: View next topic
|
| Author |
Message |
ovreddy
Active User
.jpg)
Joined: 06 Dec 2004 Posts: 211 Location: Keane Inc., Minneapolis USA.
|
|
|
|
Hi All,
I need a help in formatting a CSV file by adding first record (Header) after each control break.
For example my input is as follows
custno,item,cost
1001,234,23.00
1001,437,87.00
1001,787,89.00
1002,777,20.00
1002,343,23.30
1003,778,09.00
1003,989,99.00
1003,999,99.00
Then output file should be BREAK on cust number (repeat headers for each customer change) output should be as follows
custno,item,cost
1001,234,23.00
1001,437,87.00
1001,787,89.00
custno,item,cost
1002,777,20.00
1002,343,23.30
custno,item,cost
1003,778,09.00
1003,989,99.00
1003,999,99.00
Please help this is urgent.
Thanks,
OVReddy.[/list] |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
| Quote: |
| Please help this is urgent. |
Your problem... not our
claiming urgency will just annoy people,
lowering Your chances of getting help.
did You search the forum? there are quite a few examples of the same requirement |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| You need to look at SECTIONS and HEADER3 on OUTFIL. |
|
| Back to top |
|
 |
rakesha.hg
Active User

Joined: 21 Mar 2008 Posts: 161 Location: bangalore
|
|
|
|
hi,
Try something like this
| Code: |
//STEP01 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTIN DD *
CUSTNO,ITEM,COST
1001,234,23.00
1001,437,87.00
1001,787,89.00
1002,777,20.00
1002,343,23.30
1003,778,09.00
1003,989,99.00
1003,999,99.00
//SYSIN DD *
OMIT COND=(1,16,CH,EQ,C'CUSTNO,ITEM,COST')
SORT FIELDS=(1,4,CH,A)
OUTFIL FNAMES=SORTOUT,
SECTIONS=(1,4,HEADER3=(1:'CUSTNO,',8:'ITEM,',13:'COST'))
/* |
Output -
| Code: |
CUSTNO,ITEM,COST
1001,234,23.00
1001,437,87.00
1001,787,89.00
CUSTNO,ITEM,COST
1002,777,20.00
1002,343,23.30
CUSTNO,ITEM,COST
1003,778,09.00
1003,989,99.00
1003,999,99.00 |
Further 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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Code: |
//STEP01 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYMNAMES DD *
CUSTNO-ITEM-COST,C'CUSTNO,ITEM,COST'
//SYMNOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTIN DD *
CUSTNO,ITEM,COST
1001,234,23.00
1001,437,87.00
1001,787,89.00
1002,777,20.00
1002,343,23.30
1003,778,09.00
1003,989,99.00
1003,999,99.00
//SYSIN DD *
OPTION COPY
OMIT COND=(1,16,CH,EQ,CUSTNO-ITEM-COST)
OUTFIL SECTIONS=(1,4,HEADER3=(1:CUSTNO-ITEM-COST))
/* |
A symbol/SYMNAME can avoid the possibility of a typo, using the same constant for the OMIT and the HEADER3.
The SORT is not needed, unless sorting the file is part of the requirement. |
|
| Back to top |
|
 |
rakesha.hg
Active User

Joined: 21 Mar 2008 Posts: 161 Location: bangalore
|
|
|
|
Thanks Bill for the recommendation, will keep in mind for future  |
|
| Back to top |
|
 |
ovreddy
Active User
.jpg)
Joined: 06 Dec 2004 Posts: 211 Location: Keane Inc., Minneapolis USA.
|
|
|
|
| Thanks for the reply. I got it in a different way but this looks optimized. One more question can we do this for a comma separated file with variable length fields. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes. You can PARSE for the key field, add it to the record, temporarily, use the temporary field with whatever method you have chosen, and drop the temporary field before output.
If that doesn't get you there, post the details in a new topic, please. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|