|
A CPYF Idiosyncrasy
Hey, Ted:
I have a problem with the Copy File (CPYF) command.
When I use a CPYF command in a CL program and put a
variable in the value argument of the Include records
by field test (INCREL) parameter, the system copies
all the records that start with the non-blank
contents of this variable.
This is the command:
CPYF FROMFILE(DATALIB/USERPF) +
TOFILE(BAHRLIB/USERPF) +
MBROPT(*ADD) +
INCREL((*IF PRFNAM *EQ &USERPRF)).
The value of variable &USERPRF is CEM. The copy command copies all the records where the first three characters
of PRFNAM are CEM. This includes records with PRFNAM
values of CEM, CEMA, CEMT, CEMIL, and so on. I only
want it to copy records with CEM and nothing else.
How can I solve this problem?
Thanks and kind regards.
-- Cem
It's good to hear from you again, Cem. You have stumbled
upon one of CPYF's weird features. The system examines
the fourth argument in the INCREL parameter to see how
many characters are left after stripping out trailing
blanks. In your example, &USERPRF contains three non-blank
characters followed by seven blanks, so CPYF looks at
the first three characters of PRFNAM and nothing else.
I suggest you use the Open Query File (OPNQRYF) and
Copy from Query File (CPYFRMQRYF) commands instead.
Here's an example:
OPNQRYF FILE((DATALIB/USERPF)) +
QRYSLT('PRFNAM *EQ "' +
*CAT &USERPRF *CAT '"')
CPYFRMQRYF FROMOPNID(USERPF) +
TOFILE(BAHRLIB/USERPF) +
MBROPT(*ADD)
CLOF OPNID(USERPF)
OPNQRYF selects records with an exact match and doesn't
ignore trailing blanks.
-- Ted
|