140 pts.
 How to get the duplicate records using RPG/400
Please advice how to get the duplicate records using rpg/400.

Software/Hardware used:
ASKED: January 16, 2009  7:33 AM
UPDATED: January 16, 2009  8:57 PM

Answer Wiki:
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
Last Wiki Answer Submitted:  January 16, 2009  3:13 pm  by  philpl1jb   44,630 pts.
All Answer Wiki Contributors:  philpl1jb   44,630 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Use the reade opcode.

chain keyid recordname;

if %found;
reade keyid recordname;
if not %eof;
(we have a duplicate)
endif;
endif;

 830 pts.