Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DISTINCT -SQL Function in Logical File !!!

Posted on 2006-06-16
8
Medium Priority
?
1,114 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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