Command reference / db
OPNQRYF
Open Query File
Opens a file to a set of database records that satisfies a database query request. Once opened, the file behaves like one opened with OPNDBF, and high-level language programs access its records through the shared open data path. The path is closed and query resources are released with the CLOF command. The command can join records from several files, calculate new field values, group records with aggregate functions, select records before and after grouping, and arrange results by key fields.
The source help entry is marked incomplete.
Allowed environments: *ALL.
Positional parameters: 2.
Restrictions
- Overrides can change the FILE file, library, and member names; overrides on FORMAT are ignored unless FORMAT(*FILE) is specified. Other override parameters, except TOFILE, MBR, LVLCHK, WAITRCD, SEQONLY, INHWRT, and SHARE, are ignored by OPNQRYF.
- OPNQRYF does not share an existing open data path in the job or activation group; if an existing SHARE(*YES) open has the same file, library, and member, the query file does not open and an escape message is sent.
- Each subsequent shared open must use the same open options (such as SEQONLY) in effect when OPNQRYF was run.
- Some system functions, such as DSPPFM and CPYF, do not share an existing open data path and cannot be used with OPNQRYF.
- A file opened with OPNQRYF cannot be used by programs written in BASIC, because BASIC does not share an open data path.
- The command is conditionally threadsafe; in multithreaded jobs it is not threadsafe for distributed files that use *SNA relational databases, and it fails for *SNA DDM files.
- Users need *EXECUTE on libraries used to locate the FILE and FORMAT files; *OBJOPR on the FILE and FORMAT files; the matching data authority for the open option (*READ for *INP, *ADD for *OUT, *UPD for *UPD, *DLT for *DLT, all four for *ALL); and *USE on any translate tables used with MAPFLD.
Parameters
FILE
File specifications
Specifies one or more files, members, and record formats processed by the open query file. All files must be physical or logical database files, or DDM files. This is a required parameter.
*LIBL- The library list is used to locate the database file.
*CURLIB- The current library for the job is used to locate the file; QGPL is used if no current library is set.
*FIRST- The oldest member created is used.
*LAST- The newest member created is used.
*ALL- All members of a partition file are used.
*ONLY- The only record format in the file is used.
Elements in order
File
File
Qualified parts (object, then library; write LIBRARY/OBJECT)
File
File
Library
Library
Suggested / special values:
*LIBL, *CURLIB
Member
Member
Suggested / special values:
*FIRST, *LAST, *ALL
Record format
Record format
Suggested / special values:
*ONLY
OPTION
Open options
Specifies the open option used for the query file. Options chosen on the first full open are not changed on subsequent shared opens.
Allowed values:
*INP, *OUT, *UPD, *DLT, *ALL
*ALL- Opens the file for all operations (*INP, *OUT, *UPD, *DLT).
*INP- Opens the file for input.
*OUT- Opens the file for output.
*UPD- Opens the file for update operations.
*DLT- Opens the file for delete operations.
FORMAT
Format specifications
Specifies the record format used for records available through the open query file.
Suggested / special values:
*FILE
*FILE- The record format of the first or only entry on the FILE parameter is used; not allowed when a join query is specified.
*ONLY- The only record format in the file is used.
Elements in order
File
File
Qualified parts (object, then library; write LIBRARY/OBJECT)
File
File
Library
Library
Suggested / special values:
*LIBL, *CURLIB
Record format
Record format
Suggested / special values:
*ONLY
QRYSLT
Query selection expression
Specifies the selection values used, before grouping, to determine which records are available through the open query file.
Suggested / special values:
*ALL
*ALL- All records in the files, members, and record formats specified on FILE (after join processing, if required) are selected.
KEYFLD
Key field specifications
Specifies key fields used to arrange the query records, or that the access path sequence of the first file is used.
Suggested / special values:
*NONE, *FILE
*NONE- No key fields are used, so any arrangement is acceptable.
*FILE- The query records have the same arrangement as the first file, member, and record format.
*ASCEND- The part of the key for the field is ordered by ascending values.
*DESCEND- The part of the key for the field is ordered by descending values.
*ABSVAL- Records are arranged by absolute value; ignored for non-numeric key fields.
*MAPFLD- The field is defined on the MAPFLD parameter.
Elements in order
Key field
Key field
Qualified parts (object, then library; write LIBRARY/OBJECT)
Key field
Key field
File or element
File or element
Suggested / special values:
*MAPFLD
Key field order
Key field order
Allowed values:
*ASCEND, *DESCEND
Order by absolute value
Order by absolute value
Allowed values:
*ABSVAL
UNIQUEKEY
Unique key fields
Specifies whether the query is restricted to records with unique key values, and how many of the key fields must be unique.
Suggested / special values:
*NONE, *ALL
*NONE- Key fields are not required to be unique; all query records are available.
*ALL- All key fields must be unique; only the first record with a given set of key values is available.
JFLD
Join field specifications
Specifies whether the query joins records from multiple file members, and how field values are joined. Up to 50 join field pairs can be specified.
Suggested / special values:
*NONE
*NONE- No join operation is specified.
*MAPFLD- The field is defined on the MAPFLD parameter.
*EQ- An equal join operation is performed.
*GT- A greater than join operation is performed.
*LT- A less than join operation is performed.
*NE- A not equal join operation is performed.
*GE- A greater than or equal join operation is performed.
*LE- A less than or equal join operation is performed.
Elements in order
From field
From field
Qualified parts (object, then library; write LIBRARY/OBJECT)
From field
From field
File or element
File or element
Suggested / special values:
*MAPFLD
To field
To field
Qualified parts (object, then library; write LIBRARY/OBJECT)
To field
To field
File or element
File or element
Suggested / special values:
*MAPFLD
Join operator
Join operator
Allowed values:
*EQ, *NE, *LT, *GT, *LE, *GE
JDFTVAL
Join with default values
Specifies whether the query includes join records that use default values for fields from a join secondary file that has no record satisfying the join connections.
Allowed values:
*NO, *YES, *ONLYDFT
*NO- No default values are used to construct join query records.
*YES- Creates all records for the join, including those produced with and without default values.
*ONLYDFT- Creates only the records produced by using default values.
JORDER
Join file order
Specifies, for a join query, whether the join order must match the order specified for the FILE parameter.
Allowed values:
*ANY, *FILE
*ANY- Any join file order is allowed, which lets the system choose an arrangement for performance.
*FILE- The order of the FILE elements is preserved in the join operation.
GRPFLD
Grouping field names
Specifies the field names used to group query results; one query record is created for each group selected by QRYSLT.
Suggested / special values:
*NONE
*NONE- No fields are used to form groups; all records selected by QRYSLT are handled as a single group.
*MAPFLD- The field is defined on the MAPFLD parameter.
Qualified parts (object, then library; write LIBRARY/OBJECT)
Grouping field names
Grouping field names
File or element
File or element
Suggested / special values:
*MAPFLD
GRPSLT
Group selection expression
Specifies the selection values used after grouping to determine which records are available through the open query file.
Suggested / special values:
*ALL
*ALL- All records defined by the grouping function are selected.
MAPFLD
Mapped field specifications
Specifies the definition of query fields that are mapped or derived from other fields. Up to 50 mapped field definitions can be specified.
Suggested / special values:
*NONE
*NONE- No mapped fields are needed.
*CALC- Calculates appropriate field type attributes.
*BIN2- Two-byte binary field.
*BIN4- Four-byte binary field.
*FLT4- Four-byte floating-point field.
*FLT8- Eight-byte floating-point field.
*DEC- Packed decimal field.
*ZONED- Zoned decimal field.
*CHAR- Character field.
*VCHAR- Variable length character field.
*HEX- Hexadecimal field.
*VHEX- Variable length hexadecimal field.
*DATE- Date field.
*TIME- Time field.
*TIMESTP- Timestamp field.
Elements in order
Mapped field
Mapped field
Field definition expression
Field definition expression
Mapped field type
Mapped field type
Allowed values:
*CALC, *BIN2, *BIN4, *FLT4, *FLT8, *DEC, *ZONED, *CHAR, *VCHAR, *HEX, *VHEX, *DATE, *TIME, *TIMESTP, *ONLY, *VONLY, *OPEN, *VOPEN, *EITHER, *VEITHER, *GRAPHIC, *VGRAPHIC
Length
Length
Decimal positions
Decimal positions
Mapped field CCSID
Mapped field CCSID
Suggested / special values:
*CALC, *HEX
IGNDECERR
Ignore decimal data errors
Allowed values:
*NO, *YES
OPNID
Open file identifier
Suggested / special values:
*FILE
SEQONLY
Limit to sequential only
Elements in order
Sequential only
Sequential only
Allowed values:
*YES
Number of records
Number of records
COMMIT
Commitment control active
Allowed values:
*NO, *YES
OPNSCOPE
Open scope
Allowed values:
*ACTGRPDFN, *ACTGRP, *JOB
DUPKEYCHK
Duplicate key check
Allowed values:
*NO, *YES
ALWCPYDTA
Allow copy of data
Allowed values:
*YES, *OPTIMIZE, *NO
OPTIMIZE
Performance optimization
Elements in order
Performance optimization
Performance optimization
Allowed values:
*FIRSTIO
Number of records
Number of records
OPTALLAP
Optimize all access paths
Allowed values:
*NO, *YES
SRTSEQ
Sort sequence
Qualified parts (object, then library; write LIBRARY/OBJECT)
Sort sequence
Sort sequence
Library
Library
Suggested / special values:
*LIBL, *CURLIB
LANGID
Language ID
Suggested / special values:
*JOB
CCSID
Final output CCSID
Suggested / special values:
*JOB, *HEX
TYPE
Type of open
Allowed values:
*NORMAL, *PERM
Generated from os/cl/catalog/OPNQRYF.json and os/cl/help/OPNQRYF.json.