Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
Hi,
I have an Input File(RECFM=VB & LRECL=1004), in which first three fields are key. 4th field is Amount.
My output file should have no duplicates and final sum of the amount for same set of keys.
If sum of the amount is zero, then we don't need that record in output file.
Output file should also be the same,i.e. RECFM=VB and LRECL=1004.
Input File:
Code:
XX|11111|001A|16.93|JOHNNY B. GOODE||INVALL||||
XX|2222|001A|-17.12|JOHNY DEPP II||INVALL||||
XX|33333|001|10.45|JOHNNY R. CASH||INVALL||||
XX|4444444|0002|15.93|JOHNNY ENGLISH||INVALL||||
XX|2222|001A|15.12|JOHN DEPP II||INVALL||||
XX|33333|001|-9.45|JOHNNY R. CASH||INVALL||||
XX|11111|001A|-16.93|JOHNNY B. GOODE||INVALL||||
Output File:
Code:
XX|2222|001A|-2.12|JOHNY DEPP II||INVALL||||
XX|33333|001|1.00|JOHNNY R. CASH||INVALL||||
XX|4444444|0002|15.93|JOHNNY ENGLISH||INVALL||||
I searched the forum and found this post somewhat similar, in terms of Parsing.
My current approach is to change the Source Program for this Input file and make all the fields Fixed Length Format and then use SORT to get the final output.
But then I was just wondering how It can be done using just SORT, without changing the Source Program.
XX|11111|001A|16.93|JOHNNY B. GOODE||INVALL||||
XX|2222|001A|-17.12|JOHNY DEPP II||INVALL||||
XX|33333|001|10.45|JOHNNY R. CASH||INVALL||||
XX|4444444|0002|15.93|JOHNNY ENGLISH||INVALL||||
XX|2222|001A|15.12|JOHN DEPP II||INVALL||||
XX|33333|001|-9.45|JOHNNY R. CASH||INVALL||||
XX|11111|001A|-16.93|JOHNNY B. GOODE||INVALL||||
Output:
Code:
XX|2222|001A|-2.00|JOHNY DEPP II||INVALL||||
XX|33333|001|+1.00|JOHNNY R. CASH||INVALL||||
XX|4444444|0002|+15.93|JOHNNY ENGLISH||INVALL||||
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
You only need the first four fields to be fixed in length, the three you SORT on and the field you SUM. You could make the %05 just to have FIXLEN=themaximumlengthfordata.
If you look at ENDAT instead of ENDBEFR you should be able to preserve the "|" without having to reset it for the first three fields.
You don't need all the column-numbers on the BUILD, as all of those positions is where DFSORT is going to put the data anyway. Makes for maintenance problem when a field-length changes if you code the columns.
You can put the "pipe" for the amount back with the OVERLAY where you are editing.
Your PARSEd field %05 will be "too long", it will have a load of trailing blanks. Look at VLTRIM on OUTFIL to get rid of those. You've probably got some trailing blanks on your records already?
You'll no longer need the FINDREP to get rid of blanks between the pipes.
Bear in mind, if you have fields with more than one embedded blanks, you're going to change those to one. If you want to preserve those, you'll have to use PAIR= on the SQZ.
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
Thanks a lot Bill..Sorry for replying a little late..but I was busy..people at my site find this solution "something that can be used as a temporary fix" and suggested that I should write a Program in COBOL or PL/I to do it..and I'm working on that now..
Nevertheless..it was a good learning experience..thanks again :-)
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
No problem.
Funny. You have to SORT the file anyway. The processing can be done at the same time without another pass of the data. I guess there is a client "paying" for the extra load (and now extra development) :-)