Parsing Instructions Examples

About this task

All examples in this section parse source strings into words.

ARG
/* ARG with source string named in REXX program invocation       */
/*  Program name is PALETTE.  Specify 2 primary colors (yellow,  */
/*   red, blue) on call.   Assume call is: palette red blue      */
arg var1 var2                /* Assigns: var1='RED'; var2='BLUE' */
If var1<>'RED' & var1<>'YELLOW' & var1<>'BLUE' then signal err
If var2<>'RED' & var2<>'YELLOW' & var2<>'BLUE' then signal err
total=length(var1)+length(var2)
SELECT;
  When total=7 then new='purple'
  When total=9 then new='orange'
  When total=10 then new='green'
  Otherwise new=var1                       /* entered duplicates */
END
Say new; exit                              /* Displays: "purple" */

Err:
say 'Input error--color is not "red" or "blue" or "yellow"'; exit

ARG converts alphabetic characters to uppercase before parsing. An example of ARG with the arguments in the CALL to a subroutine is in section Parsing Multiple Strings.

PARSE ARG
Works the same as ARG except that PARSE ARG does not convert alphabetic characters to uppercase before parsing.
PARSE EXTERNAL
Say "Enter Yes or No =====> "
parse upper external answer 2 .
If answer='Y'
  then say "You said 'Yes'!"
  else say "You said 'No'!"
PARSE NUMERIC
parse numeric digits fuzz form
say digits fuzz form           /* Displays: '9 0 SCIENTIFIC'     */
                               /* (if defaults are in effect)    */
PARSE PULL
PUSH '80 7'                /* Puts data on queue                 */
parse pull fourscore seven /* Assigns: fourscore='80'; seven='7' */
SAY fourscore+seven        /* Displays: "87"                     */
PARSE SOURCE
parse source sysname .
Say sysname                          /* Displays:       "CICS"   */
PARSE VALUE
Example is in section Simple Templates for Parsing into Words.
PARSE VAR
Examples are throughout the chapter, starting in section Simple Templates for Parsing into Words.
PARSE VERSION
parse version . level .
say level                                    /* Displays: "3.48" */
PULL
Works the same as PARSE PULL except that PULL converts alphabetic characters to uppercase before parsing.

Task Task

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


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