Guild Companies, Inc.  
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 5 - January 23, 2002

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

Sponsored By
LANSA

LANSA INTEGRATOR SPEEDS DEVELOPMENT & PERFORMANCE OF JAVA

LANSA Partner MDC replaced its hand-written Java remote system integration programs with LANSA Integrator and gained a tenfold increase in performance. InsureIT uses LANSA Integrator to offer XML Java services between heterogeneous insurer & broker systems.

Find out more at http://www.lansa.com/press/20122.htm

THIS ISSUE
SPONSORED BY:
WorksRight Software
LANSA
BACK ISSUES
TABLE OF CONTENTS
SQL Replace Function, Take Two
A CPYF Idiosyncrasy
Reader Feedback and Insights
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 1/23/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.