Solved

DISTINCT -SQL Function in Logical File !!!

Posted on 2006-06-16
8
1,099 Views
Last Modified: 2008-01-09
Is there any Way I can Eliminate the Duplicate Value being read by the PGM .
I have a Physical File with one field having the Duplicate Value . If Possible I want to create a logical file
Which will automatically eliminate the Duplicate Value ( Like DISTINCT -SQL Function) ?

TIA
MW
0
Comment
Question by:midwestexp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 

Author Comment

by:midwestexp
ID: 16919990
I have Created a SQL view to Accomplish this but the Only Problem is I am not able to CHAIN /SETLL  to that SQL View, How will I workaround this ? , is there any thing I have to Do in the F-Spec to use SQL view ?
TIA
0
 
LVL 14

Expert Comment

by:daveslater
ID: 16919991
Hi
There is any easy way using OPNQRYF if that is any good.

OPNQRYF FILE((MYFILE)) KEYFLD((KEY1) (KEY2) (KEY3)) UNIQUEKEY(*ALL)

or if you are using a logical with the correct keys

OPNQRYF FILE((MYFILE)) KEYFLD(*FILE) UNIQUEKEY(*ALL)  

Have fun

Dave
0
 

Author Comment

by:midwestexp
ID: 16920019
Dave it is good to see you after a long time (atleast in my question),

OPNQRYF FILE((MYFILE)) KEYFLD((KEY1) (KEY2) (KEY3)) UNIQUEKEY(*ALL)

Will this Work Even if i have Duplicate values in the Physical file ?

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:daveslater
ID: 16920040
if
you want to access it on a setll / read then do it via sql

 /exec sql
c+ decare mycursor for
c+ select * from myfile
c+ where field1 = :value1
c+   and field2 = :value2
c+ fetch first 1 rows only
 /end-exec

Dave
0
 

Author Comment

by:midwestexp
ID: 16920074
My Problem is for this particular PGM my Company is not alowing me to use SQL, Please Don't ask me Why ?!!!
i know i can do this RPG by haveing anothe Hold-KEY-Field SKip reading of the same Key . I would like to to is there any other Way like DDS, DDM thinkgs like that .

OPNQRYF FILE((MYFILE)) KEYFLD((KEY1) (KEY2) (KEY3)) UNIQUEKEY(*ALL)

Will this Work Even if i have Duplicate values in the Physical file ?
0
 
LVL 14

Expert Comment

by:daveslater
ID: 16920097
Hi
the opnqry will work even if there are duplicates in the physical

enter the opnqryf command on a command line then use the CPYFRMQRYF command to copy the result set to a a file in QTEMP - you can then see what would be brough into the program.

The advantage of this method is you can still access details in the whole record not just the distinct values like in SQL.

if it is just some spacific values you want then craete a logical with the fields in or use embened sql with a

select distinct.

Give a few more details of the program logic and we can reccoment the best way forward.

Dave
0
 
LVL 14

Accepted Solution

by:
daveslater earned 125 total points
ID: 16920152
Hi
opnqryf is the answer - that is what I love about this machine so much history that there are workrounds for anything.

For speed considerations you may need to built an access path over the distinct fields, once that is done the jobs a finished.

for completeness I will put in the required cl.
CL is required as the OPNQRYF command actually opens the file, if the file was not shared then the RPG program would open a new version of the file and all records would be processed not just the distinct values/


PGM

 ovrdbf myfile share(*yes)
opnqryf myfile .........


call pgm

close myfile
dltovr myfile

endpgm

Dave
0
 

Author Comment

by:midwestexp
ID: 16922232
Well opnqryf  Works , As usual, like Dave Comment "I love this System"

Thanks Dave
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
We asked our MSP customer base what their favorite tools were and how they help them serve clients. We focused our questions on favorite tools in the following categories: >PSA tools >RMM tools >Alert management tools >Communication tools and Mo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question