String
If you use a string in a template, parsing checks the input data for a matching string. When assigning data
into variables, parsing generally skips over the part of the input string that matches the string in the
template.
phrase = 'To be, or not to be?' /* phrase containing comma */
PARSE VAR phrase part1 ',' part2 /* template containing comma */
/* as string separator */
/* part1 contains 'To be' */
/* part2 contains ' or not to be?' */
In this example, notice that the comma is not included with 'To be' because the comma is the string
separator. (Notice also that part2 contains a value that begins with a blank. Parsing splits the input string
at the matching text. It puts data up to the start of the match in one variable and data starting after the
match in the next variable.
Variable
When you do not know in advance what string to specify as separator in a template, you can use a
variable enclosed in parentheses.
separator = ','
phrase = 'To be, or not to be?'
PARSE VAR phrase part1 (separator) part2
/* part1 contains 'To be' */
/* part2 contains ' or not to be?' */
Again, in this example, notice that the comma is not included with 'To be' because the comma is the string
separator.
Number
You can use numbers in a template to indicate the column at which to separate data. An unsigned integer
indicates an absolute column position. A signed integer indicates a relative column position.
An unsigned integer or an integer with the prefix of an equal sign (=) separates the data according to
absolute column position. The first segment starts at column 1 and goes up to, but does not include, the
information in the column number specified. Subsequent segments start at the column numbers specified.
quote = 'Ignorance is bliss.'
....+....1....+....2
PARSE VAR quote part1 5 part2
/* part1 contains 'Igno' */
/* part2 contains 'rance is bliss.' */
The following code has the same result:
quote = 'Ignorance is bliss.'
....+....1....+....2
PARSE VAR quote 1 part1 =5 part2
/* part1 contains 'Igno' */
/* part2 contains 'rance is bliss.' */
Specifying the numeric pattern 1 is optional. If you do not use a numeric pattern to indicate a starting point
for parsing, this defaults to 1. The example also shows that the numeric pattern 5 is the same as =5.
If a template has several numeric patterns and a later one is lower than a preceding one, parsing loops
back to the column the lower number specifies.
quote = 'Ignorance is bliss.'
....+....1....+....2
PARSE VAR quote part1 5 part2 10 part3 1 part4
Manipulating Data
76
CICS TS for VSE/ESA: REXX Guide