CL Command Reference - CPYLIB

CL Command List > CPYLIB Reference

Description:

The Copy Library (CPYLIB) command copies the contents of a library to a new library. If the new library does not exist, the command optionally creates it before the copy.

All copied objects are created in the same auxiliary storage pool (ASP) as the new library. Any objects that already exist in the new library remain in the new library after the new objects are copied.

Note:

If the new library is created by this command:
. The new library is created in the same ASP as the existing library.
. The public authority of the new library is the same as the create authority for the QSYS library. The create authority for the QSYS library can be displayed by using the Display Library Description (DSPLIBD) command. If the create authority for the QSYS library is changed with the Change Library (CHGLIB) command after the new library is created, the new authority will not affect the public authority for the new library.
. The private authorities for the existing library are not copied to the new library.
. The owner of the new library is either the user profile of the user who issues the command or the group profile if the user profile of the user who issues the command is a member user profile that has specified that the group should be the owner.
. The new library is not secured by an authorization list even if the existing library was secured by an authorization list.
. You can use the Grant Object Authority (GRTOBJAUT) command specifying the existing library for the Reference object (REFOBJ) parameter to copy authorities from the existing library to the new library.

Restrictions:

. Only object types supported by the Create Duplicate Object (CRTDUPOBJ) command can be copied. The restrictions for the CRTDUPOBJ command also apply to this command.

. If this command is interrupted prior to completion, the results are unpredictable.

. If another job is processing any of the objects in the library specified for the Existing library (FROMLIB) parameter, the results may be unpredictable. For example:
¨C Objects created in the existing library after the copy starts are not copied.
¨C If objects are deleted from the existing library after the copy starts, a user of this command gets an error message.
¨C If objects in the existing library are in use or are locked by another job, the copy may not be successful.

. Other jobs should not attempt to use objects in the library specified for the New library (TOLIB) parameter until the copy is complete.


Examples:

Example 1: Copying the Contents of a Library to a New library After Creating the New Library

CPYLIB FROMLIB(MYLIB) TOLIB(NEWLIB)

This command copies the contents of library MYLIB into library NEWLIB after creating library NEWLIB. The data records, constraints, and triggers associated with a database physical file in MYLIB will be copied to the database physical file in NEWLIB.



Example 2: Copying the Contents of a Library to an Existing Library

CPYLIB FROMLIB(MYLIBA) TOLIB(MYLIBB) CRTLIB(*NO) +
DATA(*YES) CST(*NO) TRG(*NO) MONMSG MSGID(CPF2358)

This command copies the contents of library MYLIBA into existing library MYLIBB. All copied objects are created in the same auxiliary storage pool (ASP) as library MYLIBB. Any objects that already exist in library MYLIBB remain in library MYLIBB after the new objects are copied. The data records in a database physical file in MYLIBA will be copied to a newly created database physical file in MYLIBB. The constraints and triggers associated with a database physical file in MYLIBA will not be copied to a newly created database physical file in MYLIBB.

The MONMSG command allows you to ignore escape message CPF2358 which may be signalled if all objects in library MYLIBA cannot be copied to library MYLIBB. One reason an object cannot be copied is if the object already exists in library MYLIBB.