Get User Space Data

GetUsrSpace

The GetUsrSpace procedure retrieves data from a *USRSPC (user space) object.

The GetUsrSpace procedure can be used to retrieve data from an existing user space object. The start and length parameters allow a portion of the user space or the entire user space (up to the RPG field size limitation).

user-space-data  GetUsrSpace(
 szUserSpace  21A    Const
 nStart       10I 0  Const OPTIONS(*NOPASS)
 nLength      10I 0  Const OPTIONS(*NOPASS)
)

See also: CrtUsrSpace, ChgUsrSpace

Parameters

szUserSpace
[input Char(21) const]  User Space name. This parameter 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 syntax is also supported for the user space parameter. The alternate syntax allows you to specify the user space name similar to that of an OS/400 CL command, that is it may be qualified using qualified name syntax, as follows:

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

The qualified user space name is MYSPACE in the QTEMP library. Either syntax is acceptable.

 
nStart  [optional DFT(1)
[input Int(4) const]  The starting position within the user space where the data is retrieved. This parameter must be less than the length of the user space and greater than zero. If unspecified it default to 1.
 
nLength  [optional DFT(length-of-user-space minus nStart)]
[input Int(4) const]  The number of bytes retrieved from the user structure. If the parameter is less than zero the number of bytes returned is the size of the user space minus the starting position specified on the nStart parameter.

Return Value

The data from the user space is returned. It may be assigned to a variable using the EVAL operation or used in a conditional statement.

If the function fails, check the XT_ERROR data structure's subfield XT_ERRMSGID for the error message ID indicating why the user space was not created.

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 whereas a data area may up to 2000 in length.

.....DName+++++++++++EUDS.......Length+TDc.Functions++++++++++++++++++++++++++
     D szUS            C                   Const('CONTROLS  QGPL')
     D szNextCust      S              7A
     D nNextCust       S              7P 0
 
 
.....CSRn01..............OpCode(ex)Extended-factor2+++++++++++++++++++++++++++
     C                   eval      szNextCust = GetUsrSpace(szUS:1:7)
     C                   eval      nNextCust = CharToNum(szNextCust) + 1
     C                   callp     ChgUsrSpace(szUS:1:7 : %EditC(nNextCust:'X'))

This call to GetUsrSpace() retrieves the first 7 bytes of the user space named CONTROLS in the QGPL library. The second line of code converts that value to numeric and assigns it to the numeric field named nNextCust. Then the user space is updated with the new value.