How to get the duplicate records using RPG/400

140 pts.
Tags:
Duplicate records
RPG
RPG/400
Please advice how to get the duplicate records using rpg/400.
ASKED: January 16, 2009  7:33 AM
UPDATED: January 16, 2009  8:57 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Easiest way is in SQL

Select count(*), field1, field2, field3 from myfile
group by field1, field2, field3
having count(*) > 1

This would find matches on these three fields.

Programmatically you would open a cursor and fetch the results into a datastructure of
count(*), field1, field2, field3

But if you must do it in RPG – this will do it — kind of — it will find records that are identical and have the same key unless there are other records that have the same key and are not identical.

create two datastructures based on the file structure.
one of them should have a prefix such as h_
open the file as keyed

1. Read each record of the file
2. dow not eof
3. if the two datastructure’s are equal
— do whatever you want with the duplicated record
4. else
datastructure_h = datastructure
5 read next record
6 enddo

Phil

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • LBurkett99
    Use the reade opcode. chain keyid recordname; if %found; reade keyid recordname; if not %eof; (we have a duplicate) endif; endif;
    830 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following