CL program coding with the Open Query File (OPNQRYF) command

The Open Query File (OPNQRYF) command has these basic rules that can prevent coding errors.

  1. Specify selection fields from a database file without an ampersand (&). Fields declared in the control language (CL) program with DCL or DCLF require the ampersand.
  2. Enclose fields defined in the CL program with DCL or DCLF within single quotation marks ('&testfld', for example).
  3. Enclose all parameter comparisons within quotation marks when compared to character fields, single quotation marks when compared to numeric fields.
In the following example, the fields INVCUS and INVPRD are defined as character data:
QRYSLT('INVCUS *EQ "' *CAT &K1CUST *CAT '" *AND +
        INVPRD *GE "' *CAT &LPRD *CAT '" *AND +
        INVPRD *LE "' *CAT &HPRD *CAT '"')
If the fields are defined numeric data, the QRYSLT parameter can look like this:
QRYSLT('INVCUS *EQ ' *CAT &K1CUST *CAT ' *AND +
        INVPRD *GE ' *CAT &LPRD *CAT ' *AND +
        INVPRD *LE ' *CAT &HPRD *CAT ' ')
Related concepts
Usage notes for Open Query File (OPNQRYF) command