This example shows how to select records with a specific date value using the Open Query File (OPNQRYF) command.
DCL VAR(&CURDAT); TYPE(*CHAR) LEN(6) RTVSYSVAL SYSVAL(QDATE) RTNVAR(&CURDAT); OVRDBF FILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) QRYSLT('"' *CAT &CURDAT *CAT '" *EQ DATE') CALL PGM(PGMB) CLOF OPNID(FILEA) DLTOVR FILE(FILEA)
A CL variable is assigned with a leading ampersand (&) and is not enclosed in single quotation marks. The whole expression is enclosed in single quotation marks. The CAT operators and CL variable are enclosed in both single quotation marks and quotation marks.
It is important to know whether the data in the database is defined as character, date, time, timestamp, or numeric. In the preceding example, the Date field is assumed to be character.
OVRDBF FILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) QRYSLT('%CURDATE *EQ DATE') CALL PGM(PGMB) CLOF OPENID(FILEA) DLTOVR FILE(FILEA)
DCL VAR(&CVTDAT); TYPE(*CHAR) LEN(6) DCL VAR(&CURDAT); TYPE(*CHAR) LEN(8) RTVSYSVAL SYSVAL(QDATE) RTNVAR(&CVTDAT); CVTDAT DATE(&CVTDAT); TOVAR(&CURDAT); TOSEP(/) OVRDBF FILE(FILEA) SHARE(*YES) OPNQRYF FILE(FILEA) QRYSLT('"' *CAT &CURDAT *CAT '" *EQ DATE') CALL PGM(PGMB) CLOF OPNID (FILEA) DLTOVR FILE(FILEA)
QRYSLT('"12/31/87" *EQ DATE')The job default date format must be MMDDYY and the job default separator must be the slash (/).
CHGVAR VAR(&CHARVAR); VALUE('123188')
QRYSLT(&CHARVAR *CAT ' *GT DATE')
QRYSLT('123187 *GT DATE')