Chapter 15. Parsing
General Description
The parsing instructions are ARG, PARSE, and PULL (see section “ARG” on page 134, section “PARSE”
on page 152, and section “PULL” on page 158).
The data to parse is a source string. Parsing splits up the data in a source string and assigns pieces of it
into the variables named in a template. A template is a model specifying how to split the source string. The
simplest kind of template consists of only a list of variable names. Here is an example:
variable1 variable2 variable3
This kind of template parses the source string into blank-delimited words. More complicated templates
contain patterns in addition to variable names.
String patterns
Match characters in the source string to specify where to split it. (See section “Templates
Containing String Patterns” on page 205 for details.)
Positional patterns
Indicate the character positions at which to split the source string. (See section “Templates
Containing Positional (Numeric) Patterns” on page 206 for details.)
Parsing is essentially a two-step process.
1. Parse the source string into appropriate substrings using patterns.
2. Parse each substring into words.
Simple Templates for Parsing into Words
Here is a parsing instruction:
parse value 'time and tide' with var1 var2 var3
The template in this instruction is: var1 var2 var3. The data to parse is between the keywords PARSE
VALUE and the keyword WITH, the source string time and tide. Parsing divides the source string into
blank-delimited words and assigns them to the variables named in the template as follows:
var1='time'
var2='and'
var3='tide'
In this example, the source string to parse is a literal string, time and tide. In the next example, the
source string is a variable.
/* PARSE VALUE using a variable as the source string to parse */
string='time and tide'
parse value string with var1 var2 var3 /* same results */
(PARSE VALUE does not convert lowercase a–z in the source string to uppercase A–Z. If you want to
convert characters to uppercase, use PARSE UPPER VALUE. See “Using UPPER” on page 209 for a
summary of the effect of parsing instructions on case.)
All of the parsing instructions assign the parts of a source string into the variables named in a template.
There are various parsing instructions because of differences in the nature or origin of source strings. (A
summary of all the parsing instructions is on page 210.)
© Copyright IBM Corp. 1992, 2009 203