Solved

DISTINCT -SQL Function in Logical File !!!

Posted on 2006-06-16
8
1,085 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
  • 4
  • 4
8 Comments
 

Author Comment

by:midwestexp
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 14

Expert Comment

by:daveslater
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:midwestexp
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Well opnqryf  Works , As usual, like Dave Comment "I love this System"

Thanks Dave
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now