IBM SC34-5764-01 Manual page 229

Cics transaction server for vse/esa
Table of Contents

Advertisement

A relative positional pattern is a number with a plus (+) or minus (-) sign preceding it. (It can also be a
variable within parentheses, with a plus (+) or minus (-) sign preceding the left parenthesis; for details see
section "Parsing with Variable Patterns" on page 209.)
The number specifies the relative character position at which to split the source string. The plus or minus
indicates movement right or left, respectively, from the start of the string (for the first pattern) or from the
position of the last match. The position of the last match is the first character of the last match. Here is the
same example as for absolute positional patterns done with relative positional patterns:
/* Parsing with relative positional patterns in template
record.1='Clemens
Samuel
record.2='Evans
Mary Ann George Eliot
record.3='Munro
H.H.
do n=1 to 3
parse var record.n lastname +10 firstname + 10 pseudonym
If lastname='Evans' & firstname='Mary Ann' then say 'By George!'
end
Blanks between the sign and the number are insignificant. Therefore, +10 and + 10 have the same
meaning. Note that +0 is a valid relative positional pattern.
Absolute and relative positional patterns are interchangeable (except in the special case (on page 212)
when a string pattern precedes a variable name and a positional pattern follows the variable name). The
templates from the examples of absolute and relative positional patterns give the same results.
│lastname 11│
│lastname +10│
└──┬───┘
└──────┬─────┘
(Implied
Put characters
starting
1 through 10
point is
in lastname.
position
(Non─inclusive
1.)
stopping point
is 11 (1+10).)
Only with positional patterns can a matching operation back up to an earlier position in the source string.
Here is an example using absolute positional patterns:
/* Backing up to an earlier position (with absolute positional) */
string='astronomers'
parse var string 2 var1 4 1 var2 2 4 var3 5 11 var4
say string 'study' var1||var2||var3||var4
/* Displays: "astronomers study stars"
The absolute positional pattern 1 backs up to the first character in the source string.
With relative positional patterns, a number preceded by a minus sign backs up to an earlier position. Here
is the same example using relative positional patterns:
/* Backing up to an earlier position (with relative positional) */
string='astronomers'
parse var string 2 var1 +2 -3 var2 +1 +2 var3 +1 +6 var4
say string 'study' var1||var2||var3||var4
In the previous example, the relative positional pattern -3 backs up to the first character in the source
string.
The templates in the last two examples are equivalent.
Mark Twain
'
'
Saki
'
/* same results */
│firstname 21 │ │ pseudonym │
│firstname + 10│ │ pseudonym │
└──────┬───────┘ └─────┬─────┘
Put characters
Put characters
11 through 20
21 through
in firstname.
end of string
(Non─inclusive
in pseudonym.
stopping point
is 21 (11+10).)
/* same results
*/
*/
*/
Chapter 15. Parsing
Parsing
207

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Rexx

Table of Contents