z/OS TSO/E REXX User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Number

z/OS TSO/E REXX User's Guide
SA32-0982-00

You can use numbers in a template to indicate the column at which to separate data. An unsigned integer indicates an absolute column position and a signed integer indicates a relative column position.
  • Absolute column position
    An unsigned integer or an integer prefixed with an equal sign (=) in a template 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. The 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.'  */
    This example could have also been coded as follows. Note the explicit use of the column 1 indicator prior to part1 that was implied in the previous example and the use of the =5 part2 to indicate the absolute position, column 5.
    quote = 'Ignorance is bliss.'
             ....+....1....+....2
    
    PARSE VAR quote 1 part1 =5 part2
                                  /* part1 contains 'Igno'             */
                                  /* part2 contains 'rance is bliss.'  */
    When a template has more than one number, and a number at the end of the template is lower than an earlier number, parse loops back to the beginning of the data.
    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.' */
  • Relative column position
    A signed integer in a template separates the data according to relative column position, that is, a starting position relative to the starting position of the preceding part. A signed integer can be either positive (+) or negative (-) causing the part to be parsed to shift either to the right (with a +) or to the left (with a -). part1 starts at column 1, the preceding 1 is not coded but implied. In the following example, therefore, the +5 part2 causes part2 to start in column 1+5=6, the +5 part3 causes part3 to start in column 6+5=11, and so on.
    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.'           */
    The use of the minus sign is similar to the use of the plus sign in that it is used to identify a relative position in the data string. The minus sign is used to "back up" (move to the left) in the data string. In the following example, therefore, the part1 causes part1 to start in column 1 (implied), the +10 part2 causes part2 to start in column 1+10=11, the +3 part3 causes part3 to start in column 11+3=14, and the -3 part4 causes part4 to start in column 14-3=11.
    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.'      */
  • Variables
    You can define and use variables to provide further flexibility of a PARSE VAR instruction. Define the variable prior to the parse instruction, such as the movex variable in the following example. With the PARSE instruction, enclose the variable in parenthesis, in place of a number. This variable must be an unsigned integer. Therefore, use a sign outside the parenthesis to indicate how REXX is to interpret the unsigned integer. REXX substitutes the numeric value for the variable as follows:
    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.'      */
    Note: The variable movex in the previous example must be an unsigned integer. Always code a sign prior to the parenthesis to indicate how the integer is to be interpreted. If you do not, the variable will be interpreted as a string separator. Valid signs are:
    • A plus sign (+) indicates column movement to the right
    • A minus sign (-) indicates column movement to the left
    • An equal sign (=) indicates an absolute column position.

For more information about parsing, see z/OS TSO/E REXX Reference.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014