260 pts.
0
Q:
AS/400: Unique records in file
hi all,

i have a problem , suppose i have a physical file which has multiple occurrences of fld1 ,
now i need to access that in distinct (one data single time) order. so i created a logical file with UNIQUE keyword . but when i make query on this LF then msg comes that no member found.
and a dump also occurs that duplicate key not allowed.is thai method is correct to find unique data.
ASKED: Dec 2 2008  8:39 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
23625 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
Hi,

You can't create an LF with unique when the data isn't unique. What are you using to access the data? RPG, SQL?

One option is to create a new physical with unique and use CPYF with ERRLVL(*NOMAX)

Regards,

Martin Gilbert.
Last Answered: Dec 2 2008  9:42 AM GMT by Gilly400   23625 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Philpl1jb   24105 pts.  |   Dec 2 2008  2:13PM GMT

A logical with UNIQUE keyword will prevent adding records that violate the rule. It will error when compiled if the file contains duplicte key values.

The method to see one occurance of each varies with the access method.
In QUERY/400 you could use report summary functions on fld1 and other fields that you want to report.

In RPG you could use the Key - something like this

*loval SETTLL myfile
Read myfile
dow not %eof(myfile)
process your record
FLd1 SETGT myfile
Read myfile
enddo

The SETGT will position you at the first record past the key value.

Phil

 

Gilly400   23625 pts.  |   Dec 2 2008  3:01PM GMT

Hi,

Or if you’re using SQL you could use a SELECT DISTINCT.

Regards,

Martin Gilbert.

 

Philpl1jb   24105 pts.  |   Dec 2 2008  4:45PM GMT

Select distinct works great provide that all the fields retrivied are the same for a specific value of FLD1. It retrieves distinctly different rows.

 

Ambrish 82   260 pts.  |   Dec 3 2008  4:16AM GMT

thanks , it’s really useful.

 
0