Ovrdbf 1. What Exactly The OVRDBF Does?: 'HSTATUS "C" & HCUST 08177' 'HCUST 08177'
Ovrdbf 1. What Exactly The OVRDBF Does?: 'HSTATUS "C" & HCUST 08177' 'HCUST 08177'
OVRDBF
2) Say you want to use a different file (with the same record level) in a program.
To be theoretical,
The OVRDBF is used to
1) To temporarily change the attributes of a file like member, position of rrn ,sharing the Open
Data Path etc....
2) To Redirect the references made for one file to other file.
Page 84 of 228
Actually OVRDBF is used for multimember concept. A pf having multiple member and u need
to access one of the members from that, OVRDBF is used. Also, in CL u can access only 1 file at
a time. For more than 1 file also OVRDBF is used
OPNQRYF
It is a dynamic record selection. The OPNQRYF command acts as a filter between the
processing program and the database records. The database file can be a PF or LF. It will create
open data pathway to access (retrieve) data file.
If you want to specify any SQL operation within a CL we have to use OPNQRYF
Functions supplied by OPNQRYF are:
Dynamic record selection.
Dynamic keyed sequence access path
Dynamic keyed sequence access path over a join
Dynamic join
Handling missing records in secondary join files
Unique-key processing
Mapped field definitions
Group processing
Final total-only processing
Improving performance
Open query identifier (ID)
OPNQRYF SQLRPG
OPNQRYF will come along with OS/400 We need to have SQLRPG installed in
system and no need to have any as/400 system which involves additional
additional package needed to execute it cost to the programmers
OPNQRYF is faster as compared to It is slower
SQLRPG
OPNQRYF is nothing but a dynamic SQLRPG is imbedding SQL statements
logical files will be created and the directly within SQL statement
records
Page 85 of 228
If a PF is having 100 records and if we want to override the PF so that
it continues only the specific number of records we are using
OVRDBF
OPNQRYF
FILE (LIB / PF) QRYSLT (‘EMPNO *EQ ‘ *BCAT &A)
If you want to perform any SQL operation we have to declare in
OPNQRYF command only.
In case of OPNQRYF we can perform expression only based on
characters but not on numeric.
*BCAT
If you want to perform any charter expression are using *BCAT
expression which will provide a blanks in between the 2 variables.
%WLDCRD
It is similar to %LIKE in SQL
QRYSLT (‘EMPNAME *EQ %WLDCRD (“S* “)’)
It will fetch all the records whose empname starts from S.
*CT
It will fetch all the records, which conditions the particular
charter.
QRYSLT (‘EMPNAME *CT “S” ‘)
%RANGE
It will fetch the records within the specific range
QRYSLT (‘EMPNO *Eq %RANGE (100 110)’)
CALL PGM (LIB/NAME) PARM ()
DLTOVR
As we see early the main file logically overridden and after performing
the necessary operation, we have to delete the logical file so that the main
file contains the actual records for this DLTOVR will be used.
DLTOVR FILE (OPNPF)
CLOF
We have to close the file, which has been opened
CLOF OPNID (OPNPF)
You will copy overridden file records using CPYFRMQRYF
CPYFRMQRYF
Since OVRDBF is logical we cannot able to list the variables, which satisfy
the query condition. To see the records being selected we have to copy
from the source file to a temporary file for this CPYFRMQRYF will be
used
CPYFRMQRYF FROMOPNID (OPNPF) TOFILE (LIB/NAME)
MBR (*REPLACE) CRTFILE (*YES) FMTOPT (*NOCHK)
RUNQRY
We have copied the contents satisfy the query into a temporary file using
CPYFRMQRYF. If we run the destination file we got the actual records,
which satisfy the query.
RUNQRY QRYFILE (LIN/NAME)
Page 86 of 228
Example:
Database PF
SKANDASAMO/CLP
OPENF
0000.01 C UNIQUE
0001.00 C R OPNQFILE
0002.00 C OEMPNO 5S 0
0005.00 C ODOB 8S 0
0006.00 C K OEMPNO
Data file
Display Report
CL program
SKANDASAMO/CLP
OPNQFILE5
Page 87 of 228
0001.00 PGM
0011.00 ENDPGM
OUTPUT
FMTDTA OPNQRY
It will sort the records sequentially based It will sort the records based on the field
on the position of the record values.
Page 88 of 228
If any change in the attribute size of a PF If there is any change in the attribute size it
then we have to change the program will not affect the program specification
specification also. also.
LF creates a new object in the system while that is not the case for OPNQRYF.LF creates a
permanent data access path to the physical file that will be updated as and when and add,
update and delete operation is performed on file Whereas OPNQRYF creates a temporary
access data path that is shared by high level pgm for further processing of recs in file.
I agree with Vaiv20. Just want to add that OPNQRYF is used with keyword Share (*Yes) and
that's what makes the ODP available to high level pgms.
Also the usage of OPNQRYF is for adhoc jobs that are executed once in a while whereas LF is
used in case where the ODP is going to be used pretty regularly. So LF object would be
preferred when the usage is going to be regular.
OPNQRYF would be good where the job is going to be once in a while.
LF would make the job faster compared to OPNQRYF though it depends on what kind of
maintenance option you use for LF.
The main difference is: Logical file creates permanent object on the system. OPNQRYF creates
temporary access path.
CL-PROGRAM
ILLUSTRATED IN SAMPLES 1 - 3.
Page 89 of 228
INPUT........: DB-FILE: QRYSLTPF
FIELDS: UPUPRF 10 A
UPUID 10 P0
FIELDS: UPUPRF 10 A
UPUID 10 P0
PGM
Page 90 of 228
DCL VAR(&X) TYPE(*CHAR) LEN(1) + VALUE(' ')
ADDLIBLE LIB(JPHLIB)
/* USED IN SAMPLE 3. */
/*****************************************************************/
/*****************************************************************/
ONE:
OPNQRYF FILE((JPHLIB/QRYSLTPF)) +
QRYSLT(' +
*AND +
') +
Page 91 of 228
OPNID(BRUG)
GOTO CMDLBL(OUT)
/*****************************************************************/
/*****************************************************************/
TWO:
OPNQRYF FILE((JPHLIB/QRYSLTPF)) +
QRYSLT(' +
*AND +
') +
OPNID(BRUG)
GOTO CMDLBL(OUT)
/*****************************************************************/
/*****************************************************************/
THREE:
OPNQRYF FILE((JPHLIB/QRYSLTPF)) +
QRYSLT(' +
*AND +
') +
OPNID(BRUG)
Page 92 of 228
GOTO CMDLBL(OUT)
/*****************************************************************/
/*****************************************************************/
MBROPT(*ADD)
CLOF OPNID(BRUG)
DLTOVR FILE(*ALL)
GOTO CMDLBL(CHOISE)
/* LIBRARY-LIST IS RESTORED */
RCLRSC
RETURN
ENDPGM
DISPLAY-FILE:
A DSPSIZ(24 80 *DS3)
A R F0
A CF03(03 'Afslut')
A 1 69TIME
A 1 63'Time:'
A DSPATR(HI)
A 2 69DATE
A EDTCDE(Y)
A 2 63'Date:'
A DSPATR(HI)
Page 93 of 228
A PROMPT 1A I 24 4DSPATR(ND)
A 24 6'Enter=Run F3=Exit'
A COLOR(BLU)
A USER 10A I 4 35
A 6 12'User id . . . . . . :'
A DSPATR(HI)
A NR 10S 0I 6 35CHECK(FE)
A CHECK(RZ)
A 8 12'Sample . . . . . . :'
A DSPATR(HI)
A EX 1S 0I 8 35RANGE(1 3)
**********************************************************************
**********************************************************************
*_____________________________________________________________________
A R SELECT
*_____________________________________________________________________
A UPUPRF 10 TEXT('USER')
A COLHDG('USER')
A COLHDG('ID')
*_____________________________________________________________________
I hope this will help you understanding some of the basics in OPNQRYF.
Page 94 of 228
However there is a small thing usually wrapped in plastic or hidden on a CD called a manual.
This could be a great help but sometimes very hard to understand and with some stupid
examples that don't work. My samples can be typed in on your AS/400 and it works.
Don't hesitate to send a mail if you want more help or want to discuss some of the above
mentioned topics.
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/dbp/rbafomst02.htm
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/dbp/rbafomst199.htm#HDROPNQ
F
http://www.geocities.com/SiliconValley/Hills/6632/opnqryf.html
http://publib.boulder.ibm.com/html/as400/v4r5/ic2979/info/db2/rbafomst140.htm#Header_19
9
TESTPF data:
1 Agnie 1,234,567
2 Amudha 3,456,789
TESTPF1 data:
1 Agnie Coimbatore
3 Varun Bangalore
Format of OPNQRYRES – Note that it contains the fields of TESTPF as well as TESTPF1
PGM
Page 95 of 228
/* To select the records present in TESTPF & TESTPF1 and copy that to a new file (which
contains all the fields of TESTPF and TESTPF1 */
FORMAT(SHAILESH/OPNQRYRES) +
JDFTVAL(*NO)
CLOF OPNID(TESTPF)
FORMAT(SHAILESH/TESTPF) +
JFLD((TESTPF/EMPNO TESTPF1/EMPNUM)) +
JDFTVAL(*ONLYDFT)
CLOF OPNID(TESTPF)
FORMAT(SHAILESH/TESTPF1) +
JFLD((TESTPF1/EMPNUM TESTPF/EMPNO)) +
JDFTVAL(*ONLYDFT)
CLOF OPNID(TESTPF1)
ENDPGM
SQLRPGLE
Page 96 of 228