Subfield Access
In operand positions, it is possible to access a subarea of a character-type or byte-like data object
or a subarea of a character-type initial part of a structure by specifying an offset or length. In write positions>, this can be done only for flat data objects and not for strings.
An offset or length is appended directly to either the dobj
descriptor of the data object, an fs field symbol, or
a dref->* de-referencing data reference variable (since Release 6.10 and if the data reference variable is fully typed), as shown below:
-
dobj[+off][(len)]
[+off][(len)]
dref->*[+off][(len)]
The segment of the data object is used that has the offset specified in
off and the length in characters or bytes specified in>
len. The off
and len operands require data objects of type I, and these must contain whole positive numbers, with the following exceptions:
- The length 0 can be specified for>strings>.
- A negative offset can be specified if an fs field symbol is specified in the ASSIGN> statement for dobj .
If off is smaller than the length of
dobj, an asterisk (*) can be specified for len.
The upper limit of dobj then determines the upper limit of the memory area.
A subfield that is specified by an offset or length is handled like a data object of the specified length
whose data type depends on the data type of the original data object, the field symbol or the data reference variable, as shown below:
Original data type |
Data type of the subfield |
c |
c |
d |
n |
n |
n |
t |
n |
string |
string |
x |
x |
xstring |
xstring |
Structuretype |
c |
The following restrictions apply:
- A memory area may not be addressed outside the field boundaries, except in the case of
ASSIGN. If an offset is specified without a length, the whole subfield from the
off characters is addressed; if a length is specified without an offset, the first
len characters are addressed. Different rules apply to the ASSIGN statement.
- No offset or length data can be specified if a literal or a text symbol is specified.
- From 6.10, offset and length data is counted in characters in character-type data objects, and otherwise in bytes. In non-
Unicode systems, one character corresponds to one byte.
- In Unicode programs, offset and
length specifications are permitted only in character-type and byte-like areas of data obejcts. Offset and length specifications for structures are permitted in Unicode programs only if the structures are
flat, if the offset and length specifications access only the first
Unicode fragment of the structure, and if this is a character-type fragment. Also see
Offset/length specifications in Unicode programs.