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.
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.
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.
123456DEFINE 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
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.
123DEFINE 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
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.
| Need | Easytrieve approach |
|---|---|
| Copy full field | MOVE or assignment |
| Slice bytes 10-19 | Overlay DEFINE at offset |
| Walk each character | OCCURS 1 A with INDEX loop |
| Variable SQL text | VARYING A with :DATA |
| Find delimiter | DO loop; optional legacy STRSRCH macro |
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.
1234* 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
True dynamic concatenation without length planning fails when result exceeds buffer LENGTH. Size the receive buffer for maximum business case plus delimiters.
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.
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.
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 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.
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.
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.
1. Easytrieve provides built-in SUBSTR functions like SQL:
2. Assigning a shorter literal to a longer A field:
3. INDEX on DEFINE adjusts field start by:
4. Trailing spaces in character comparisons:
5. Parsing delimited strings often uses: