RPGLE How to use SETLL and READE to find duplicate records for a keyed field

5.2k Views Asked by At

Can someone give me an example of using SETLL and READE to find a duplicate record for a keyed field.

Currently the file I am working with has 3 keyed fields. The field I am looking for duplicates in is the second key in sequence. I am not sure how to code this in free format, where I use READE and SETLL to find duplicate records.

/free
read filename;              

dow not %eof(filename);     


SETLL (XXPART)OUTPUTWORKFILE; 
IF NOT %EQUAL(OUTPUTWORKFILE);
write OUTPUTWORKFILE;  
enddo;      

I know that I can't just jump to the second keyed field(XXPART), so I have to include the first keyed field (XXPLNT). Just not sure how to do that in free form. Also uncertain where I should put the reade.

Thanks in advance.

2

There are 2 best solutions below

0
On BEST ANSWER

I don't think you need a reade to do what you want. setll should be sufficient as long as you don't need anything from outfile. Notice that you can use a compound key with setll.

read filename;              
dow not %eof(filename);     
  setll (xxplnt: xxpart) outputworkfile;
  if not %equal(outputworkfile);
    write outputworkfile;
  endif;
  read filename;
enddo;
2
On

@jmarkmurphy has a reasonable answer but I also think this is even easier using SQL if can.

select xxplnt, xxpart from filename
group by xxplnt, xxpart
having count(*) > 1