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

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.

Type
*ELEM
Required
Yes
List limit
32
Case
Uppercase
*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

Type
*QUAL
Required
No
Case
Uppercase
Qualified parts (object, then library; write LIBRARY/OBJECT)

File File

Type
*NAME
Required
No
Length
10
Case
Uppercase

Library Library

Type
*NAME
Required
No
Default
*LIBL
Length
10
Case
Uppercase

Suggested / special values: *LIBL, *CURLIB

Member Member

Type
*NAME
Required
No
Default
*FIRST
Length
10
Case
Uppercase

Suggested / special values: *FIRST, *LAST, *ALL

Record format Record format

Type
*NAME
Required
No
Default
*ONLY
Length
10
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*INP
Length
4
List limit
4
Case
Uppercase

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.

Type
*ELEM
Required
No
Default
*FILE
Case
Uppercase

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

Type
*QUAL
Required
No
Case
Uppercase
Qualified parts (object, then library; write LIBRARY/OBJECT)

File File

Type
*NAME
Required
No
Length
10
Case
Uppercase

Library Library

Type
*NAME
Required
No
Default
*LIBL
Length
10
Case
Uppercase

Suggested / special values: *LIBL, *CURLIB

Record format Record format

Type
*NAME
Required
No
Default
*ONLY
Length
10
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*ALL
Length
5000
Case
Mixed case

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.

Type
*ELEM
Required
No
Default
*NONE
List limit
50
Case
Uppercase

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

Type
*QUAL
Required
No
Case
Uppercase
Qualified parts (object, then library; write LIBRARY/OBJECT)

Key field Key field

Type
*NAME
Required
No
Length
10
Case
Uppercase

File or element File or element

Type
*NAME
Required
No
Length
10
Case
Uppercase

Suggested / special values: *MAPFLD

Key field order Key field order

Type
*CHAR
Required
No
Default
*ASCEND
Length
8
Case
Uppercase

Allowed values: *ASCEND, *DESCEND

Order by absolute value Order by absolute value

Type
*CHAR
Required
No
Length
7
Case
Uppercase

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.

Type
*UINT2
Required
No
Default
*NONE
Range
1 to 120
Case
Uppercase

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.

Type
*ELEM
Required
No
Default
*NONE
List limit
50
Case
Uppercase

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

Type
*QUAL
Required
No
Case
Uppercase
Qualified parts (object, then library; write LIBRARY/OBJECT)

From field From field

Type
*NAME
Required
No
Length
10
Case
Uppercase

File or element File or element

Type
*NAME
Required
No
Length
10
Case
Uppercase

Suggested / special values: *MAPFLD

To field To field

Type
*QUAL
Required
No
Case
Uppercase
Qualified parts (object, then library; write LIBRARY/OBJECT)

To field To field

Type
*NAME
Required
No
Length
10
Case
Uppercase

File or element File or element

Type
*NAME
Required
No
Length
10
Case
Uppercase

Suggested / special values: *MAPFLD

Join operator Join operator

Type
*CHAR
Required
No
Default
*EQ
Length
3
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*NO
Length
8
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*ANY
Length
5
Case
Uppercase

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.

Type
*QUAL
Required
No
Default
*NONE
List limit
50
Case
Uppercase

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

Type
*NAME
Required
No
Length
10
Case
Uppercase

File or element File or element

Type
*NAME
Required
No
Length
10
Case
Uppercase

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.

Type
*CHAR
Required
No
Default
*ALL
Length
5000
Case
Mixed case

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.

Type
*ELEM
Required
No
Default
*NONE
List limit
50
Case
Uppercase

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

Type
*NAME
Required
No
Length
10
Case
Uppercase

Field definition expression Field definition expression

Type
*CHAR
Required
No
Length
2000
Case
Mixed case

Mapped field type Mapped field type

Type
*CHAR
Required
No
Default
*CALC
Length
9
Case
Uppercase

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

Type
*UINT2
Required
No
Range
0 to 32766
Case
Uppercase

Decimal positions Decimal positions

Type
*UINT2
Required
No
Range
0 to 63
Case
Uppercase

Mapped field CCSID Mapped field CCSID

Type
*UINT2
Required
No
Default
*CALC
Range
1 to 65535
Case
Uppercase

Suggested / special values: *CALC, *HEX

IGNDECERR Ignore decimal data errors

Type
*CHAR
Required
No
Default
*NO
Length
4
Case
Uppercase

Allowed values: *NO, *YES

OPNID Open file identifier

Type
*NAME
Required
No
Default
*FILE
Length
10
Case
Uppercase

Suggested / special values: *FILE

SEQONLY Limit to sequential only

Type
*ELEM
Required
No
Case
Uppercase
Elements in order

Sequential only Sequential only

Type
*CHAR
Required
No
Default
*YES
Length
4
Case
Uppercase

Allowed values: *YES

Number of records Number of records

Type
*UINT2
Required
No
Range
1 to 32767
Case
Uppercase

COMMIT Commitment control active

Type
*CHAR
Required
No
Default
*NO
Length
4
Case
Uppercase

Allowed values: *NO, *YES

OPNSCOPE Open scope

Type
*CHAR
Required
No
Default
*ACTGRPDFN
Length
10
Case
Uppercase

Allowed values: *ACTGRPDFN, *ACTGRP, *JOB

DUPKEYCHK Duplicate key check

Type
*CHAR
Required
No
Default
*NO
Length
4
Case
Uppercase

Allowed values: *NO, *YES

ALWCPYDTA Allow copy of data

Type
*CHAR
Required
No
Default
*YES
Length
9
Case
Uppercase

Allowed values: *YES, *OPTIMIZE, *NO

OPTIMIZE Performance optimization

Type
*ELEM
Required
No
Case
Uppercase
Elements in order

Performance optimization Performance optimization

Type
*CHAR
Required
No
Default
*FIRSTIO
Length
8
Case
Uppercase

Allowed values: *FIRSTIO

Number of records Number of records

Type
*UINT4
Required
No
Range
1 to 2147483647
Case
Uppercase

OPTALLAP Optimize all access paths

Type
*CHAR
Required
No
Default
*NO
Length
4
Case
Uppercase

Allowed values: *NO, *YES

SRTSEQ Sort sequence

Type
*QUAL
Required
No
Case
Uppercase
Qualified parts (object, then library; write LIBRARY/OBJECT)

Sort sequence Sort sequence

Type
*NAME
Required
No
Length
10
Case
Uppercase

Library Library

Type
*NAME
Required
No
Default
*LIBL
Length
10
Case
Uppercase

Suggested / special values: *LIBL, *CURLIB

LANGID Language ID

Type
*NAME
Required
No
Default
*JOB
Length
10
Case
Uppercase

Suggested / special values: *JOB

CCSID Final output CCSID

Type
*UINT2
Required
No
Default
*JOB
Range
1 to 65535
Case
Uppercase

Suggested / special values: *JOB, *HEX

TYPE Type of open

Type
*CHAR
Required
No
Default
*NORMAL
Length
7
Case
Uppercase

Allowed values: *NORMAL, *PERM

IBM command documentation

Generated from os/cl/catalog/OPNQRYF.json and os/cl/help/OPNQRYF.json.