1

I am trying to use OPNQRYF in a CL program to select some records from a given file. The query selection string is defined in the OPNQRYF statement. But during execution, message CPF9899 was thrown with the cause that QRYSLT is empty. I had re-compiled the programs for several times and the problem was still there. Then I tried to define the query selection in a character variable first, then assigned it to QRYSLT. This times it worked. How did this happen? I have some other OPNQRYF statements in the same program with QRYSLT defined within, and they worked out fine. Is there anything else that might interfere with OPNQRYF?

This one does not work:

OPNQRYF FILE(&SLIB/CKFESCP) QRYSLT('DWSYST *EQ "' *CAT &KVAL *TCAT '"')

And this one does:

DCL VAR(&QRYSLT) TYPE(*CHAR) LEN(200)
.
.
.
CHGVAR VAR(&QRYSLT) VALUE('DWSYST *EQ "' *CAT &KVAL *TCAT '"')
OPNQRYF FILE(&SLIB/CKFESCP) QRYSLT(&QRYSLT)
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
God_of_Thunder
  • 753
  • 3
  • 20
  • 46
  • OPNQRYF is heavily used in CL in my company for filtering out record. If you are talking about using QMQRY, I would say that it is an option, but not as flexible as I need (RUNSQLSTM is out of the question). I am not sure if that is a systematic behaviour or due to other inappropriate setting. The problem does not make any sense. – God_of_Thunder Nov 05 '12 at 12:40
  • 1
    As described, the symptoms indicate programmer error. Could be mis-matched quotes or a TRIM issue... very hard to say without seeing code. – Buck Calabro Nov 05 '12 at 15:07
  • One of several reasons OPNQRYF is discouraged, is that there are often errors that are not detected until run time, as you are now discovering. But beginners are generally well advised to follow conventions found in existing code, as you seem to be doing. – WarrenT Nov 05 '12 at 18:46
  • As suggested, try debug. – WarrenT Nov 06 '12 at 04:38
  • There's nothing wrong with using OPNQRYF – David G Nov 06 '12 at 16:16
  • What errors are you getting in the joblog? – David G Nov 06 '12 at 16:17
  • Syntax in QRYSLT() not valid. It appears to be some string retrieved from somewhere else. Looks like there is a mismatch in the memory somehow, resulted in an unrelated string be used here as option rather than my own defined string. – God_of_Thunder Nov 06 '12 at 16:23
  • I don't think the QRYSLT parameter is empty ... just the query select syntax is invalid. I would suggest just using the variable to hold the query, so long as it works. – David G Nov 07 '12 at 22:22

0 Answers0