Trimming removes unwanted spaces—usually trailing—from character fields before you compare, concatenate, or export delimited data. COBOL developers reach for FUNCTION TRIM; SQL has RTRIM and LTRIM. Easytrieve offers fixed-length A fields and expects you to implement trim logic with INDEX loops, overlays, and careful MOVE lengths. That sounds tedious, but payroll and customer extract programs have used the same patterns for decades. This page teaches why trailing spaces appear, how to detect them with DISPLAY HEX, reverse-scan algorithms, left-trim for imported data, and when trimming hurts if downstream systems expect fixed padding.
Fixed-length records assign every byte. A thirty-byte name field may hold SMITH plus twenty-five spaces. COBOL MOVE of shorter literal space-fills the target. Easytrieve FILE A fields read those bytes faithfully. Comparisons against unpadded literals fail. CSV exports include ugly trailing spaces before delimiters unless you trim. Understanding the source prevents blaming Easytrieve for data shaped upstream.
Broadcom documentation does not define TRIM, RTRIM, or LTRIM functions for standard batch Easytrieve. Forum archives confirm developers implement custom logic. Plan a reusable PROC or paragraph TRIM-RIGHT that accepts source field, length, and target work field—copy across programs in your shop macro library for consistency.
Define single-byte OCCURS field over the source with INDEX. Set index to last byte position. DO WHILE current byte is space and index greater than zero, decrement index. When non-space found, MOVE from start through index length to trimmed work field—or record trimmed length in a separate numeric counter for delimited output. EBCDIC space is X'40'—compare to literal space or use known hex in DISPLAY debug.
1234567DEFINE WS-RAW W 30 A DEFINE WS-TRIM W 30 A DEFINE WS-LEN W 3 N 0 * Conceptual: loop from byte 30 down to 1 * while byte = space, decrement position * WS-LEN = last non-space position * MOVE overlay WS-RAW length WS-LEN to WS-TRIM
INDEX value equals (occurrence number minus one) times element length. For one-byte OCCURS, index equals byte offset. For multi-byte elements, stepping index by one jumps entire element width—use one-byte scan for trim logic. Setting index to field-length minus one targets last byte on zero-based occurrence math per Broadcom manual examples.
| Goal | Approach |
|---|---|
| Remove trailing spaces | Reverse INDEX scan, MOVE slice |
| Compare to short literal | Trim first or use equal-length overlay |
| CSV export | Trim then append delimiter literal |
| Debug invisible spaces | DISPLAY HEX field |
| Remove leading spaces | Forward scan until non-space |
Imported ASCII files or poorly formatted input may pad left. Scan forward from byte one until non-space byte found. MOVE from that offset for remaining length into work field. Combine left and right trim for full normalization when building free-text search keys. Watch empty-all-space fields—trim result length zero; guard IF before MOVE to avoid negative length logic errors in hand-coded counters.
Alternative to trim: define overlay matching literal length for compare only. IF STATUS-1 EQ 'Y' where STATUS-1 overlays first byte of five-byte STATUS avoids trimming entire field. Choose overlay when only first character matters; choose full trim when exporting human-readable text to spreadsheets or emails.
VARYING A fields store explicit length prefix—data portion may not include trailing spaces if SQL loader set length correctly. Still verify :DATA bytes for spaces when length counts trailing spaces as significant. FLDA:LENGTH trim may mean adjusting binary length after removing spaces from :DATA before INSERT—advanced pattern for DB2 interface programs.
When IF results mystify, DISPLAY HEX shows each byte. Trailing X'40' bytes confirm space padding. Low-values X'00' indicate different problem— uninitialized data not trim case. Teach support staff to read hex snippet in compile listing SYSPRINT output during incident calls.
Per-record trim loop adds CPU on million-row extracts. Trim once when reading if reused many times in same record processing. Avoid trim inside innermost nested IF on every field when only one field exports. Batch trim PROC inlined by compiler still executes per row— profile before production peak windows.
Trimming is erasing empty space stickers at the end of a word on your label. The box still has thirty slots but only five letters matter. You walk from the end backward until you find a real letter, then copy only those letters to a clean label. Easytrieve does not give you an eraser tool—you count boxes with your finger in a loop.
1. Easytrieve provides a built-in TRIM function:
2. Trailing spaces in file name fields often come from:
3. To trim, you typically scan:
4. After trimming for compare, store result in:
5. Trimming changes file data on disk when: