IBM SC34-5764-01 Server User Manual


 
The PARSE VAR instruction is similar to PARSE VALUE except that the source string to parse is always a
variable. In PARSE VAR, the name of the variable containing the source string follows the keywords PARSE
VAR. In the next example, the variable stars contains the source string. The template is star1 star2
star3.
/* PARSE VAR example */
stars='Sirius Polaris Rigil'
parse var stars star1 star2 star3 /* star1='Sirius' */
/* star2='Polaris' */
/* star3='Rigil' */
All variables in a template receive new values. If there are more variables in the template than words in
the source string, the leftover variables receive null (empty) values. This is true for all parsing: for parsing
into words with simple templates and for parsing with templates containing patterns. Here is an example
using parsing into words.
/* More variables in template than (words in) the source string */
satellite='moon'
parse var satellite Earth Mercury /* Earth='moon' */
/* Mercury='' */
If there are more words in the source string than variables in the template, the last variable in the template
receives all leftover data. Here is an example:
/* More (words in the) source string than variables in template */
satellites='moon Io Europa Callisto...'
parse var satellites Earth Jupiter /* Earth='moon' */
/* Jupiter='Io Europa Callisto...'*/
Parsing into words removes leading and trailing blanks from each word before it is assigned to a variable.
The exception to this is the word or group of words assigned to the last variable. The last variable in a
template receives leftover data, preserving extra leading and trailing blanks. Here is an example:
/* Preserving extra blanks */
solar5='Mercury Venus Earth Mars Jupiter '
parse var solar5 var1 var2 var3 var4
/* var1 ='Mercury' */
/* var2 ='Venus' */
/* var3 ='Earth' */
/* var4 =' Mars Jupiter ' */
In the source string, Earth has two leading blanks. Parsing removes both of them (the word-separator
blank and the extra blank) before assigning var3='Earth'. Mars has three leading blanks. Parsing removes
one word-separator blank and keeps the other two leading blanks. It also keeps all five blanks between
Mars and Jupiter and both trailing blanks after Jupiter.
Parsing removes no blanks if the template contains only one variable. For example:
parse value ' Pluto ' with var1 /* var1=' Pluto '*/
The Period as a Placeholder
A period in a template is a placeholder. It is used instead of a variable name, but it receives no data. It is
useful:
v As a “dummy variable” in a list of variables
v Or to collect unwanted information at the end of a string.
The period in the first example is a placeholder. Be sure to separate adjacent periods with spaces;
otherwise, an error results.
/* Period as a placeholder */
stars='Arcturus Betelgeuse Sirius Rigil'
parse var stars . . brightest . /* brightest='Sirius' */
Parsing
204
CICS TS for VSE/ESA: REXX Guide