CPYF Command - IBM AS400

This is a discussion on CPYF Command - IBM AS400 ; hi
When a CPYF Command is performed from a source file to target file,
Can the source file be accessed by another user? Or the later user
will be denied access to the source file (File Lock) ?
aurlam...

CPYF Command

When a CPYF Command is performed from a source file to target file,
Can the source file be accessed by another user? Or the later user
will be denied access to the source file (File Lock) ?

aurlam

Re: CPYF Command

CPYF dies not lock the source file.

Re: CPYF Command

aurlam wrote:
> hi
>
> When a CPYF Command is performed from a source file to target file,
> Can the source file be accessed by another user? Or the later user
> will be denied access to the source file (File Lock) ?
>

If the source file (FROMFILE) is a database file, CPYF must open it to
read records. It appears that CPYF open gets a shared read lock, which
would not prevent another job from accessing the file in a shared mode,
but would prevent exclusive access or deletion by another job. If you
need to prevent *any* concurrent access during the copy, you could get
an exclusive lock (eg *EXCL) prior to running CPYF. Note that for
copying one member of a multi-member database file, you would likely
only need to lock the member to be copied.

Re: CPYF Command

It actually depends on what path the CPYF takes to extract the data
from the from-file ['from-file' and FROMFILE() used here, instead of the
word 'source'].
The row-copy path of CPYF, for either key or sequential, will place a
*SHRRD lock on specified FROMFILE() and an *SHRRD lock on FROMMBR().
The fast-copy path of CPYF may be used if the FROMFILE member is not
in use. In that case the CPYF will place a *SHRRD lock on the specified
FROMFILE() and an *EXCLRD lock on the FROMMBR() which would prevent
another user from concurrent access to that member, for anything other
than read access.

The reason for the question is not clear to me, but perhaps either of
the following paragraphs are germane:
The WAITFILE() specification [that attribute in either the from-file
or an OVRDBF request] can be set to ensure that the concurrent request
to open the same member does not fail immediately while the CPYF is
processing -- a number of seconds can be specified, to wait if/while the
open is prevented by a conflicting lock in another job. If fast-copy
path must be avoided, specify ERRLVL(a-non-zero-value) on the CPYF request.
Refer to Karl's post for how to avoid data-in-transition situations
involving a CPYF request which uses a row-copy path.

Regards, Chuck
--
All comments provided "as is" with no warranties of any kind
whatsoever and may not represent positions, strategies, nor views of my
employer

aurlam wrote:
> When a CPYF Command is performed from a source file to target file,
> Can the source file be accessed by another user? Or the later user
> will be denied access to the source file (File Lock) ?