PARSE
REXX's instruction for pulling a piece of text apart: by word, by position or by a mark.
Also written PARSE VAR, PARSE ARG
Why it matters. Records, messages and command output all arrive as one long line. PARSE splits them into pieces you can use.
See it
PARSE VAR splits the text at the blanks into four variables.
Syntax
PARSE [UPPER] VAR name template PARSE [UPPER] ARG template PARSE [UPPER] PULL template PARSE [UPPER] VALUE expression WITH template
- VAR
- Split a variable you already have.
- ARG
- Split what was passed to the exec.
- PULL
- Split a line from the data stack or the terminal.
- VALUE ... WITH
- Split the result of an expression.
- UPPER
- Change the text to capitals first.
- . (a dot)
- Skip a word you don't want.
- 'mark'
- Split at this text.
- numbers
- Split by column position.
Try it PARSE
- 1
In the exec SPLIT, the variable rec holds ACCT0001 SAVG 2500.00. Split it into three variables: acct, type and bal.
REXX PARSE VAR rec acct type bal - 2
Run the exec SPLIT.
EXEC 'ZB0001.DEV.REXX(SPLIT)'
Remember
- PARSE VAR name template splits the text in a variable.
- Blanks split the text into words, one for each name in the template. The last name gets everything left over, and a dot skips a word.
- A mark in quotes, like ',', splits at that mark. Numbers split by column.
The usual mistake
PARSE VAR rec acct type bal (when rec is ACCT0001,SAVG,2500.00)
There are no spaces to split on. acct gets the whole line, and type and bal are empty.
PARSE VAR rec acct ',' type ',' bal
On real z/OS
MF/OS runs REXX with its own interpreter, which covers PARSE and its templates. It differs from real TSO/E REXX in rarely used places such as SIGNAL, TRACE and NUMERIC FORM.
Where can I practise PARSE?
Right here, at ZedBank. You take a junior job at a simulated bank and use PARSE in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- REXXA readable scripting language used across the mainframe for automation, tooling and quick one-off tasks.
- REXX execA REXX program, stored as a member in a library and run by name from TSO or ISPF.
- Stem variableREXX's array, a variable with a dot in its name used to hold a list such as the lines of a file.
- TSO commandA command typed at a TSO prompt or on an ISPF command line to ask the system to do something directly.