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
       /* part1 contains 'Igno'                */
       /* part2 contains 'rance'               */
       /* part3 contains ' is bliss.'          */
       /* part4 contains 'Ignorance is bliss.' */
When each variable in a template has column numbers both before and after it, the two numbers indicate the beginning and the end of the data for the variable.
quote = 'Ignorance is bliss.'
         ....+....1....+....2

PARSE VAR quote 1 part1 10 11 part2 13 14 part3 19 1 part4 20
       /* part1 contains 'Ignorance'           */
       /* part2 contains 'is'                  */
       /* part3 contains 'bliss'               */
       /* part4 contains 'Ignorance is bliss.' */
Thus, you could use numeric patterns to skip over part of the data:
quote = 'Ignorance is bliss.'
         ....+....1....+....2

PARSE VAR quote 2 var1 3 5 var2 7 8 var3 var 4 var5
SAY var1||var2||var3 var4 var5  /* || means concatenate  */
                                /* Says: grace is bliss. */
A signed integer in a template separates the data according to relative column position. The plus or minus sign indicates movement right or left, respectively, from the starting position. In the next example, remember that part1 starts at column 1 (by default because there is no number to indicate a starting point).
quote = 'Ignorance is bliss.'
         ....+....1....+....2
PARSE VAR quote part1 +5 part2 +5 part3 +5 part4
       /* part1 contains 'Ignor'          */
       /* part2 contains 'ance '          */
       /* part3 contains 'is bl'          */
       /* part4 contains 'iss.'           */
+5 part2 means parsing puts into part2 data starting in column 6 (1+5=6). +5 part3 means data put into part3 starts with column 11 (6+5=11), and so on. The use of the minus sign is similar to the use of the plus sign. It identifies a relative position in the data string. The minus sign "backs up" (moves to the left) in the data string.
quote = 'Ignorance is bliss.'
         ....+....1....+....2
PARSE VAR quote part1 +10 part2 +3 part3 -3 part4
       /* part1 contains 'Ignorance '     */
       /* part2 contains 'is '            */
       /* part3 contains 'bliss.'         */
       /* part4 contains 'is bliss.'      */
In this example, part1 receives characters starting at column 1 (by default). +10 part2 receives characters starting in column 11 (1+10=11). +3 part3 receives characters starting in column 14 (11+3=14). -3 part4 receives characters starting in column 11 (14-3=11).
To provide more flexibility, you can define and use variable numeric patterns in a parsing instruction. To do this, first define the variable as an unsigned integer before the parsing instruction. Then, in the parsing instruction, enclose the variable in parentheses and specify one of the following before the left parenthesis:
  • A plus sign (+) to indicate column movement to the right
  • A minus sign (-) to indicate column movement to the left
  • An equal sign (=) to indicate an absolute column position.
(Without +, -, or = before the left parenthesis, the language processor would consider the variable to be a string pattern.) The following example uses the variable numeric pattern movex.
quote = 'Ignorance is bliss.'
         ....+....1....+....2
movex = 3            /* variable position               */
PARSE VAR quote part5 +10 part6 +3 part7 -(movex) part8
       /* part5 contains 'Ignorance '     */
       /* part6 contains 'is '            */
       /* part7 contains 'bliss.'         */
       /* part8 contains 'is bliss.'      */

For more information about parsing, see Parsing.


Reference Reference

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrx00065.html