Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
Defining a substring - &SUBSTR z/OS TSO/E CLISTs SA32-0978-00 |
|||||||||||||||
Use the &SUBSTR built-in function to request that a CLIST use only certain bytes of an indicated string when performing substitution. You indicate the starting and ending positions of the string from which the substitution is made. For example, assuming a variable called &ANIMALS contains the
character string "DOGSCATSSEALS", to set a variable called &FELINE
to the character string "CATS", code the following:
Note that the character string "CATS" begins in the fifth position of &ANIMALS and ends in the eighth position. A &SUBSTR built-in function can contain other built-in functions. Assume your CLIST receives input from the user and assigns it to a variable called &NAME. &NAME contains a person's first and middle initial followed immediately by the family name. To add a blank between the initials and the family name, you can set a variable called &NFIELD to a character string consisting of the following:
If you want the substring to contain only one character, you can
omit the colon and end-expression. For example, if you are interested
only in the first letter of the family name, code the following:
You can substitute variables for starting and ending expressions.
For instance, to set the section of &STRING beginning at the second
position and ending at the eighth position to a variable called &WIDGET,
you can create a variable and substitute it in the SET statement.
Assume that the substring data represents a part number.
When a variable is named in &SUBSTR, arithmetic evaluation
of the variable's contents is suppressed, as in &STR. For example:
However, when another built-in function such as &LENGTH is specified
in the &SUBSTR, the variable within the built-in function is evaluated
before the &SUBSTR. To protect that variable from arithmetic
evaluation, use &STR.
If a string contains data of the double-byte character set (DBCS), &SUBSTR
counts each DBCS character as two bytes, and counts each DBCS delimiter
as one byte. For
example, using d1d2 to denote two DBCS characters and using <
and > to denote the DBCS delimiters X'0E' (shift-out)
and X'0F' (shift-in):
When &SUBSTR returns DBCS data, &SUBSTR encloses the data between the DBCS delimiters X'0E' and X'0F'. &SUBSTR attempts to return the exact bytes requested. However, when the starting or ending positions of the substring are DBCS data or DBCS delimiters, &SUBSTR makes the following adjustments:
In addition, if the adjustment causes a not valid DBCS character, or a contiguous pair of DBCS delimiters, &SUBSTR replaces those by single-byte blanks. However, SUBSTR does not change any contiguous pairs of DBCS delimiters that were part of the original data string. The following are several examples of the adjustment process.
In the examples, the characters s, Dn, <, >, and b denote a
single-byte character, double-byte character, shift-out delimiter,
shift-in delimiter, and single-byte blank.
Because &SUBSTR may truncate data in DBCS strings,
you can use &SYSCSUBSTR as an alternative to &SUBSTR for DBCS
data. |
Copyright IBM Corporation 1990, 2014
|