I want to sort a file on a key SORT FIELDS=(1,5,CH,A) . I want to sort, keep all the records, I just want to flag the duplicates. Say my input file is of length 5 . I want output file of length six and mark all the records those are duplicate with a flag Y.
Example
Just to understand it more, for the same condition, where I want all the i/p records in o/p file, with duplicates flagged, how I am going to code , if my input file length is 100, output is 101,sort fileds are 1,15 and flag should be at position 101.
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
I assumed that you only had the key in each record as shown in your original example, so you didn't care about the order of the records with the same key for output. If you have other fields in the record and do care about the order of the records with the same key for output, then we'd need to do it a different way.
Let's start over. Show me a better example of your input records and expected output records with the other fields in the record besides the key so I can see what you really want.
Let me restart it. I have one i/p file, LRECL=100. My sort key is 15 chars.
rest all won't matter to me. I have already sorted the file with the key. Now say, I have 100 records in my sorted i/p file, with 20 duplicates, means total 80 unique records and 20 with duplicates. I want the output file LRECL=100 with a flag in each duplicate record at position 101 so in my cobol program, I know that it's a duplicate and I can process it accordingly checking for the flag. So I will have 100 in my o/p file and have 20 with flags and 80 without any flags.
The '.............' in the example are fields with 9's , A's and X's I want those as it is and they have nothing to do with sort or duplicates.
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
Hello,
Sorry to "charge in", but i have to ask. . .
Is there some reason processing the data 3 times is better than adding the bit of code needed to handle duplicates in the COBOL program (which requires only 1 pass of the data)?
Hopefully, there is something i am misunderstanding. . .
If I have duplicates, those need to be reported and I need to add up the sum of amounts. I can not ignore, it is not to delete or omit duplicates, but to flag the duplicates and then use the file with the duplicates for calculating some amounts and also to put those in reporting.
There may be same key, but the other fields could be different. Means a same key, under different department, and getting some benefits. So need to know what all benefits key has received under the different department and to update the departments of duplicate keys in the cobol reports !
So I will have a good file ready with the duplicates flagged. I did write a program to do this, but what can be done in JCL for 100,000's of records will take time in Cobol.
I hope it explains !
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
Hello,
Well, you have learned something new. . .
For your requirement it is very likely not good and should surely not be used day to day.
Maybe someday you will also learn that it is nearly never a good decision to read all of the data, write all of the data, and read it all again when a single read would be sufficient.
I am not processing it so many times as you have understood.
Here a raw file is sorted and flagged for duplicates in JCL and later on used for processing in a Cobol.
What would be best way to do it in a single read ?
( When I do need an to process duplicates in reports and transaction files differently in cobol processing)
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
Hello,
Quote:
I am not processing it so many times as you have understood.
The data you posted as the "input" is already in sequence - which would lead to "extra" processing. If the "real" data will not be in sequence, sorting it will not be extra overhead - it would be needed
Quote:
(When I do need an to process duplicates in reports and transaction files differently in cobol processing)
Yes, that's what we were discussing. If I am using the above ICETOOL step I am not going to have a sort step above it. I will remove my sort and use this. So sort and flag addition in 1 step only. I already mentioned in my post in which I gave the data 'I have already sorted the file with the key'. ....
Hope now we are on same page ..