Copy User Space Data

CpyUsrSpace

The CpyUsrSpace procedure copies the data from one user space to another.

The CpyUsrSpace procedure can be used to copy the data from an existing user space object to a second user space. If the target user space does not exist, it is created.

user-space-data  CpyUsrSpace(
 szFromUserSpace    21A    Const 
 szToUserSpace      21A    Const 
 bReplace            1N    Const OPTIONS(*NOPASS)
 nBytes             10I 0  Const OPTIONS(*NOPASS) 
)

See also: CrtUsrSpace, DltUsrSpace

Parameters

szFromUserSpace
[input Char(21) const]  Originating/Source User Space name.
 
szToUserSpace
[input Char(21) const]  Target User Space name.
 
The user space parameters consists of two parts (1) in the first 10 positions, the name of the user space, and (2) in the second 10 positions, the name of the library containing the user space For example:
 *...v....1....v....2
'MYSPACE   QTEMP     '
 

An alternative, and preferred syntax is also supported for user space names. This syntax allows you to specify the user space name similar to that of an OS/400 CL command, that is it may be specified using qualified name syntax, as follows:

 *...v....1....v....2
'QTEMP/MYSPACE       '
 

The qualified user space name in the above example is MYSPACE in the QTEMP library. Both syntax styles are supported.

 
bReplace  [ optional ] DFT('1')
[input Indy(1) const]  Indicates whether the target user space is to be replace if it already exists. The possible values are *ON ('1') which causes the user space to be replaced if it already exists, and *OFF ('0') which causes the procedure to return 0 if the target user space specified in the szToUsersSpace parameter already exists.
nBytes  [optional ] DFT(object size of szFromUserSpace)
[input Int(4) const]  Use this parameter to override the number of bytes copied from the szFromUserSpace to the szToUserSpace. If unspecified, the current size (length) of the szFromUserSpace is used.
 

Return Value

If the copy is successful, the number of bytes copied is returned.

If the function fails, 0 is returned.

Remarks

This procedure, by default, replaces the existing user space. If the user space already exists, it is cleared by setting its current size to zero and the the copy is performed. The ibute should be set on the target user space (its size set to zero). If the target user space does not exist, it is created using the default settings of the CrtUsrSpace procedure.

Example

A user space may be used in place of a data area or a "control" file. A user space may be up to 16 megabytes in length; far surpassing the maximum length of a data area.

.....DName+++++++++++EUDS.......Length+TDc.Functions++++++++++++++++++++++++++
     D szMyUS          C                   Const('CONTROLS  QGPL')
 
.....CSRn01..............OpCode(ex)Extended-factor2++++++++++++++++++++++++++++++
     C                   callp     CpyUsrSpace(szMyUS : 'qtemp/backupUS')

This example calls the CpyUsrSpace() procedure to copy the user space named CONTROLS in QGPL to the user space named BACKUPUS in QTEMP.