Choosing Between PARSE and SUBSTR for Data Extraction in Rexx
Decide when to use PARSE versus SUBSTR in Rexx for efficient string parsing, with a comparison table and runnable examples.
27 Jul 2026, 23:59 UTC

When processing structured data in Rexx, you must decide whether to use the PARSE command or the SUBSTR function for extracting fields. The choice hinges on whether your data is delimited by a separator (comma, pipe, whitespace) or defined by fixed character positions.
Decision Factors
| Method | Best Fit | Performance | Flexibility |
|---|---|---|---|
| PARSE VAR | Delimited data (CSV, TSV, log lines) | High – optimized internal engine | Medium – depends on static pattern |
| SUBSTR() | Fixed‑width records (mainframe extracts, formatted reports) | Lower – function call overhead per field | High – start/length can be computed at runtime |
Using PARSE for Delimited Data
The PARSE command splits a string into variables based on a pattern that can include literal delimiters. It is ideal when fields are separated by a known character and you want the interpreter to handle the splitting in one step.
/* Example: parse a comma‑separated log line */ line = "2026-10-11,WARN,Disk_full,85"; PARSE VAR line date , level , message , code ; say "Date:" date say "Level:" level say "Message:" message say "Code:" code
The commas in the pattern act as delimiters. A space before each comma tells Rexx to ignore surrounding whitespace, which helps clean up messy input.
Using SUBSTR for Fixed‑Width Data
When data fields occupy exact column ranges, SUBSTR(string, start, length) extracts the needed slice. This approach works well when the start position or length is calculated at runtime.
/* Example: extract fields from a fixed‑width record */ record = "ID00452SMITH JOHN ACTIVE0010"; id = SUBSTR(record, 1, 6) name = TRIM(SUBSTR(record, 7, 10)) status = SUBSTR(record, 17, 6) say "ID:" id say "Name:" name say "Status:" status
The TRIM function removes padding spaces that are common in fixed‑width formats.
Validation and Verification
- Save the script to a file, e.g.,
extract.rexx. - Run it with the Rexx interpreter:
rexx extract.rexx(no special privileges required). - Compare the printed output to the expected values shown in the comments.
- If the output matches, the extraction logic is correct for the given sample.
Limitations and Practical Checks
- PARSE variable collision: If the input contains more delimiters than variables supplied, excess data can overwrite existing variables. Guard against this by adding a placeholder variable at the end of the
PARSE VARlist to capture overflow, or by checking the delimiter count beforehand. - SUBSTR overhead in tight loops: Each call incurs function‑call cost. When processing millions of records, consider extracting all needed fields with a single
PARSEif the format permits, or pre‑compute start/length values to minimize calls. - Length verification: Before using
SUBSTR, confirm thatLENGTH(record)meets the maximum start+length you intend to access, preventingSUBSTRfrom returning a shorter string or raising a condition.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.