Easytrieve String Handling

Modern languages offer trim, split, and substring functions on every string. Easytrieve predates that convenience: character data lives in fixed-length A fields, and you manipulate it with MOVE, assignment, overlay definitions, INDEX positioning, and explicit loops. That surprises developers from Java or COBOL UNSTRING backgrounds. Yet payroll extract programs have parsed semicolon-delimited email lists and copied name portions for decades with these patterns. This page teaches practical string handling—concatenation, substring extraction, delimiter parsing, comparison pitfalls, and VARYING fields—without pretending built-in string libraries exist where Broadcom documents field-based techniques instead.

Progress0 of 0 lessons

Fixed-Length String Model

Every A field has a declared byte length. There is no dynamic string object—operations always consider the full length unless VARYING or overlay slicing narrows the view. MOVE from a ten-byte field to a four-byte field truncates right side unless you designed overlay to capture the left four. Understanding fixed length first prevents half the string bugs in production.

MOVE and Assignment

Assignment copies bytes from source to receive field. Shorter sources pad with spaces in longer receives. Longer sources truncate to receive length. Numeric to A assignment may produce edited character digits. Character literals in quotes assign exact bytes for literal length then pad. These rules are your primary concatenation building blocks when combined with multiple assignments into offsets.

text
1
2
3
4
5
6
DEFINE WS-OUT W 20 A DEFINE WS-PART1 W 8 A VALUE 'HELLO' DEFINE WS-PART2 W 8 A VALUE 'WORLD' WS-OUT = WS-PART1 * overlay or further MOVE needed to append WS-PART2

Field Overlay for Substrings

Define a second field name starting at an offset within the same record or a large working storage buffer. If WS-BUF is 40 A at W, define WS-BUF-10 10 10 A as overlay starting at byte ten within WS-BUF per POSITION rules—or use explicit POSITION on DEFINE relative to file. Overlay lets you reference ten bytes starting at position ten without a substring function. COBOL REDEFINES parallels this pattern.

text
1
2
3
DEFINE WS-LINE W 80 A DEFINE WS-DEPT W 5 A POSITION WS-LINE + 0 DEFINE WS-NAME W 20 A POSITION WS-LINE + 5

INDEX and OCCURS for Scanning

Define a one-byte A field with OCCURS n and INDEX(name). Set index to (desired position - 1) times element length—for one-byte elements, index value equals byte offset. MOVE from indexed occurrence reads that byte. Loop DO WHILE incrementing index walks the string character by character for delimiter search. Multi-byte element OCCURS advances index by full element length per Broadcom manual—indexing a 4096-byte element steps 4096 bytes per increment, not one byte.

String technique comparison
NeedEasytrieve approach
Copy full fieldMOVE or assignment
Slice bytes 10-19Overlay DEFINE at offset
Walk each characterOCCURS 1 A with INDEX loop
Variable SQL textVARYING A with :DATA
Find delimiterDO loop; optional legacy STRSRCH macro

Delimiter Parsing Pattern

For input like 12345;NAME;email@corp.com, define indexed single-byte scan over the record, DO UNTIL finding semicolon, accumulate characters into a target A field, advance past delimiter, repeat for next token. No single UNSTRING statement exists—forum archives document this pattern extensively. Watch index start at 0 versus 1 for off-by-one errors when adapting examples. Test with empty tokens and trailing delimiters.

text
1
2
3
4
* Conceptual delimiter scan—not complete program * SCAN-IDX indexes 1-byte occurrences over INPUT-LINE * WS-POS holds current byte offset * Build TOKEN A field until ';' found

Concatenation Strategies

  1. Build DISPLAY line listing multiple A fields separated by literals in one DISPLAY statement.
  2. MOVE literal and fields into sections of a large buffer via overlays at fixed offsets.
  3. Use REPORT LINE with multiple fields and literals interleaved.
  4. For SQL export, WRITE delimiters as separate literal fields in sequence.

True dynamic concatenation without length planning fails when result exceeds buffer LENGTH. Size the receive buffer for maximum business case plus delimiters.

Comparisons and Padding

IF FIELD EQ 'ABC' compares three bytes of literal to full field length—remaining bytes must be spaces for EQ on a three-byte conceptual value in a longer field, or compare a three-byte overlay instead. GT and LT use collating sequence—not intuitive alphabetical rules for mixed case. NE tests any byte difference. Normalize padding before compare when file data is inconsistently space-filled.

Trimming and Padding

No TRIM function—see dedicated padding and trimming tutorials for loop patterns that strip trailing spaces or pad left with zeros for character codes. MASK BWZ suppresses leading zeros on output without changing stored value. For input cleanup, scan from end with INDEX decreasing until non-space found, then MOVE substring overlay to shortened work field.

VARYING Character Strings

SQL VARCHAR-style fields use VARYING on A. Two-byte length prefix precedes data. Reference FLDA:DATA for text without length bytes. FLDA:LENGTH reads binary count. DISPLAY HEX shows both for debug. Assignment to varying fields must respect length prefix updates— incorrect length causes truncated read on next SQL FETCH equivalent.

DISPLAY for String Debug

DISPLAY field name prints character representation. DISPLAY HEX shows hexadecimal bytes alongside character—essential when EBCDIC special characters or low-values appear in file data. SKIP and column control format multi-field string dumps in batch logs without full report machinery.

Legacy STRSRCH Macro

Easytrieve 6.4 shipped STRSRCH sample macro for Boyer-Moore search. Release 11.6 does not distribute it; Broadcom notes third-party copyright. Sites may copy from 6.4 libraries if policy allows. Do not assume STRSRCH exists on new installations—plan INDEX loop logic for portable code.

Common String Handling Mistakes

  • Assuming SUBSTR from COBOL or SQL exists in Easytrieve.
  • INDEX on multi-byte OCCURS stepping one byte when element length is larger.
  • Ignoring trailing spaces in EQ comparisons.
  • Buffer too short for concatenated result.
  • Parsing multi-byte DBCS with single-byte scan logic.

Explain It Like I'm Five

Easytrieve strings are like a row of letter boxes with a fixed count—no stretchy balloon string. To get letters from the middle, you put a smaller row of boxes on top of that section without moving the letters. To find a comma, you walk box by box with your finger counting steps. There is no magic scissors function—you decide where the smaller row starts by counting carefully.

Exercises

  1. Define an 80-byte buffer and two overlays for bytes 1-10 and 11-20.
  2. Write IF comparing a 1-byte flag to Y and N literals.
  3. Outline DO loop steps to find first semicolon in a line.
  4. Explain why INDEX element length matters for OCCURS.
  5. State three ways to build a delimited output line for DISPLAY.

Quiz

Test Your Knowledge

1. Easytrieve provides built-in SUBSTR functions like SQL:

  • No—use overlay, INDEX, or custom logic
  • Yes—$SUBSTR on every field
  • Only in REPORT
  • Only on mainframe 6.4

2. Assigning a shorter literal to a longer A field:

  • Pads with spaces in the receive field
  • Truncates the literal
  • Abends always
  • Converts to packed

3. INDEX on DEFINE adjusts field start by:

  • (occurrence - 1) * element length
  • One byte always
  • Record length
  • Random

4. Trailing spaces in character comparisons:

  • Are significant for full field length EQ
  • Always ignored
  • Removed by compiler
  • Only in JCL

5. Parsing delimited strings often uses:

  • DO WHILE loops scanning one byte at a time
  • Built-in UNSTRING
  • SQL JOIN
  • JCL DD
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 assignment, INDEX, VARYING, and community string patternsSources: Broadcom Easytrieve Report Generator 11.6 TechDocs, Assignment Statement, Define Files and Fields, Knowledge Base STRSRCHApplies to: Easytrieve alphanumeric string manipulation