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

Need logic to remove duplicates from same file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
renjithravi1
Warnings : 2

New User


Joined: 31 May 2005
Posts: 16

PostPosted: Fri Aug 21, 2009 9:43 am
Reply with quote

Hi All,

I have a requirement to remove the duplicates from a single input file.
The keys of the file are known and the file is already sorted based on the key. It is sure that there can be maximum of only 2 duplicates will be occuring in the file. I need to remove both the duplicates from the input file and create an output file. I should do this using a cobol program not by using sort. Kindly help me in this regard

Thanks and regards
Renjith
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Fri Aug 21, 2009 11:28 am
Reply with quote

Hang on, if the file is already sorted previously, why not just adapt the sort step to remove the duplicates. Save time, save effort, or is this another of them stupid requirements from somebody who knows naff all about the IT world.
Back to top
View user's profile Send private message
renjithravi1
Warnings : 2

New User


Joined: 31 May 2005
Posts: 16

PostPosted: Fri Aug 21, 2009 11:59 am
Reply with quote

Hi

Ok. Agreed. You know enough about IT world.
But think about the requirement which u r calling stupid, if sort utility was not there how you will do this?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Fri Aug 21, 2009 12:03 pm
Reply with quote

Are you seriously telling me that your site does not have a sort product.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Aug 21, 2009 12:31 pm
Reply with quote

Hi Renjith,

renjithravi1 wrote:
Ok. Agreed. You know enough about IT world.

icon_rolleyes.gif
Expat, as we call him, is one of the most respected persons in the forum. After all, he has only given you a suggestion.

If I understood your requirement correctly, guess you would be able to do it, if you store the key in a temporary field. Each time u read the record, compare with this temporary key as process it.

Code:

If KEY = TEMP-KEY
    Discard the Record
Else
    Write the record to the file
    MOVE TEMP-KEY to KEY
End-if

Fairly simple i should say... icon_wink.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Fri Aug 21, 2009 12:51 pm
Reply with quote

Let me try to understand:
renjithravi1 wrote:
I need to remove both the duplicates from the input file and create an output file.
As you said, if there are duplcates, at the most, there can be two. If so, you want to remove both of them?
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Aug 21, 2009 1:11 pm
Reply with quote

Binop B wrote:
Fairly simple i should say... icon_wink.gif
Yes it is, But the question here is since the OP said "the file is already sorted based on the key", the common assumption is that, it was done using his sort product(unless his shop is still living with an internal COBOL SORT icon_mad.gif ). So why would we need to have another pass of data.
Quote:
If so, you want to remove both of them?
A few sample records might clarify what exactly the OP wants here.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Aug 21, 2009 1:14 pm
Reply with quote

I guess the answer is already given by expat... icon_lol.gif

Quote:
is this another of them stupid requirements from somebody who knows naff all about the IT world
Back to top
View user's profile Send private message
renjithravi1
Warnings : 2

New User


Joined: 31 May 2005
Posts: 16

PostPosted: Fri Aug 21, 2009 1:31 pm
Reply with quote

Hi All,

Thanks a lot for your expert opinions. I will find a way to do this.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Aug 21, 2009 1:57 pm
Reply with quote

Hi Renjith,

I thought i have already provided a solution... icon_rolleyes.gif

Is not my solution acceptable.. icon_sad.gif
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Fri Aug 21, 2009 2:31 pm
Reply with quote

Binop ,
Quote:
Fairly simple i should say...
do you think you code would be able to remove BOTH the records that are duplicate.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Fri Aug 21, 2009 2:52 pm
Reply with quote

Hi Arun,
arcvns wrote:
(unless his shop is still living with an internal COBOL SORT icon_mad.gif ).
I'm not sure if you meant that "internal sort" in Cobol is somewhat different -- The internal sort and the external sort execute the same sort product, whichever is used on your system...
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Aug 21, 2009 3:09 pm
Reply with quote

Quote:
The internal sort and the external sort execute the same sort product, whichever is used on your system
Hi Anuj,

Yes True, but AFAIK the latter is a little bit efficient. I was thinking if he is looking for an INTERNAL sort followed by some coding logic to remove the duplicates. Anyways the OP does n't seem to be interested to help us with some more info here. icon_lol.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Fri Aug 21, 2009 3:30 pm
Reply with quote

arcvns wrote:
Anyways the OP does n't seem to be interested to help us with some more info here. icon_lol.gif
Usual story on these Forums these days, as Kevin (superk) once said, "ow. my head hurts..." icon_smile.gif.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6248
Location: Mumbai, India

PostPosted: Fri Aug 21, 2009 3:39 pm
Reply with quote

And which one is efficient is altogther a different story, we may start a different thread if you want... icon_biggrin.gif
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Aug 21, 2009 4:44 pm
Reply with quote

Succor wrote:
Binop ,
Quote:
Fairly simple i should say...
do you think you code would be able to remove BOTH the records that are duplicate.


As per my understanding of the requirement... i guess it should work... icon_razz.gif

I am guessing that what Renjith meant is,
Say if there is a field with key as AAAA, and there are chances that there could be two or less AAAA records immediately (duplicates) following the first AAAA record. and Renjith wanted to remove both the duplicates. I am guessing he wants to remove the other records keeping the first record.

Hope i have explained properly my understanding of the requirement... icon_smile.gif
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Fri Aug 21, 2009 6:16 pm
Reply with quote

Binop, Yes you have explained well .
My thought was that the OP would like to remove the whole set of records for which there are duplicates (which is again an assumption).
I reckon we should have gone by what Arun had asked for
Quote:
A few sample records might clarify what exactly the OP wants here.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Aug 21, 2009 8:17 pm
Reply with quote

Succor wrote wrote:
My thought was that the OP would like to remove the whole set of records for which there are duplicates (which is again an assumption).


I too on my first read thought that was what Renjith wanted. But then, functionally, I thought such a requirement didnt make much sense... icon_razz.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10888
Location: italy

PostPosted: Fri Aug 21, 2009 8:37 pm
Reply with quote

Quote:
... I should do this using a cobol program not by using sort ...


Quote:
Are you seriously telling me that your site does not have a sort product.


just good old plain homework
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Aug 21, 2009 8:50 pm
Reply with quote

enrico-sorichetti wrote:
just good old plain homework

I had thought about that... but then the guy, Renjith, has been active since almost a year. Looks odd for a guy to be doing Homework for almost a year... icon_razz.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10888
Location: italy

PostPosted: Fri Aug 21, 2009 9:34 pm
Reply with quote

Quote:
has been active since almost a year


I would rather say ...
has been inactive since almost a year, only 10 posts after all

and he should have known that if he wanted better replies he should have posted in a better way ...

these threads usually lower the benevolence factor of the TS/OP
Back to top
View user's profile Send private message
renjithravi1
Warnings : 2

New User


Joined: 31 May 2005
Posts: 16

PostPosted: Fri Aug 21, 2009 10:44 pm
Reply with quote

Hi All,

Thanks for your expertise and suggestions so far. Let me explain you the requirement before i leave.

I have a file coming from some system, not from mainframe, dont know or dont care how it is coming sorted and specifications says it will be sorted.

So the file is sorted on the key and the file content example is below,

AA12345ZINSSXY
AA12345ZINSSXY
AA12345ZINSZXY
BB34444STUPSPP

My key is position 1 to 2 and 13 to 14

if two records have the same key and the value of the first record in position 8 to 12 is 'ZINSSS' and second record the same position has record 'ZINSSZ' then both the records have to be omitted from writing to output file, rest all records should be written to output file.

Of course my system has SORT and related tools, but for the records omitted a report should be printed and should be sent to business in specific format, for this the client feels using a cobol program is better.
So i have to do using program and i got the logic and did the program and first report has been successfully delivered.

To the point that i did only 10 posts during the last one year, i have explanation for that, it is not necessary for me to look at this everytime i am stuck, i know enough and i do my 'HOMEWORK' well and i have enough knowledge in IT. But sometimes too many things are need to be done from your side and you have a lots of work to do, all have to be done in one day, you think the best possibilities to reduce your time...that is the mistake i did and posted in this site..sorry for that...

Now you have the requirement clear...if you think about the logic or dont think i dont care!

Thanks a lot for all your help so far!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Sat Aug 22, 2009 12:43 am
Reply with quote

Hello,

Quote:
that is the mistake i did and posted in this site
Posting was not a mistake. Taking personal affront to replies might be. . . Keep in mind that replies are not directed at the poster nearly as often as they are directed at the idea icon_neutral.gif

Unfortunately, your initial post was misunderstood by many and so most replies centered on a sort/utility solution. Had your most recent post been part of the topic start, this topic might have developed completely differently.

And yes, i agree with your client - i believe this is best served by code.

Quote:
if you think about the logic or dont think i dont care
Probably not the best way to proceed. . . Attitude is everything.
Quote:
Thanks a lot for all your help so far!
You're welcome - is this work complete now?
Back to top
View user's profile Send private message
renjithravi1
Warnings : 2

New User


Joined: 31 May 2005
Posts: 16

PostPosted: Sat Aug 22, 2009 4:27 pm
Reply with quote

HI

Yes this work is complete now!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Sat Aug 22, 2009 10:52 pm
Reply with quote

Good to hear it is working - thanks for letting us know icon_smile.gif

d
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 -> COBOL Programming Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts Unable to interpret a hex value to De... COBOL Programming 7
No new posts how to eliminate null indicator value... DB2 7
No new posts Format Binary file to EBCDIC JCL & VSAM 4
No new posts Binary File format getting change whi... All Other Mainframe Topics 7
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
Search our Forums:

Back to Top