Padding is what happens when a ten-character name field holds only four letters and the remaining six bytes are spaces. Or when a numeric working storage field starts at zero before your JOB logic runs. Easytrieve does not call it padding in every manual, but the behavior is everywhere: assignment rules, default initialization, report MASK characters, and file records that arrive space-filled from COBOL programs. Beginners lose hours when IF STATUS EQ 'Y' fails because the file field is Y plus nine spaces and the literal was one byte. This page explains space fill, zero fill, display padding versus storage padding, and patterns to pad intentionally for output formats.
DEFINE working storage fields receive default values at program start. Type A fields become all spaces—EBCDIC X'40' on the mainframe. Numeric types N, P, B, U, and I initialize to zero in their respective formats. VALUE on DEFINE overrides defaults with your literal or numeric constant. FILE fields read from input carry whatever bytes exist in the record; the compiler does not pad file fields on read.
12345DEFINE WS-NAME W 20 A DEFINE WS-CNT W 5 N 0 * WS-NAME starts as 20 spaces; WS-CNT starts as numeric zero DEFINE WS-FLAG W 1 A VALUE 'N'
When a receive field is longer than the source, assignment pads the result. Character assignment pads with spaces on the right for standard MOVE patterns. Shorter literal 'ABC' into ten-byte field yields ABC plus seven spaces. When source is longer than receive, truncation drops rightmost bytes unless you designed overlay to capture the portion you need. Numeric assignment uses conversion rules—assigning N to longer N may pad with leading zeros in zoned format per field type.
| Situation | Typical fill | Notes |
|---|---|---|
| A WS init without VALUE | Spaces | All bytes X'40' EBCDIC |
| Numeric WS init without VALUE | Zeros | Packed, zoned, or binary zero |
| Short literal to long A | Right space pad | On assignment |
| Long source to short A | Truncate right | Data loss possible |
| MASK Z on report | Suppress leading zero display | Storage unchanged |
IF FIELD EQ 'ABC' compares the literal to the full field width. A ten-byte field containing ABC plus spaces fails EQ against three-byte literal unless you compare a three-byte overlay or normalize first. GT and LT use collating sequence where space often sorts before letters in EBCDIC—another surprise for beginners. Document whether file standards require trailing spaces or trimmed values; mixed files break comparisons.
123456DEFINE WS-STAT W 5 A * File has 'OK ' in 5 bytes IF WS-STAT EQ 'OK' * May FAIL—literal is 2 bytes, field is 5 IF WS-STAT EQ 'OK ' * Matches if bytes align exactly
Part numbers and employee IDs often need leading zeros visible on reports. MASK literals with 9 characters print every digit including leading zeros: '0000000009' pattern for nine-digit IDs. MASK with Z suppresses leading zeros for counts you do not want padded: ZZZ9 shows 42 instead of 0042. Choose per business rule—social security masks use 9 throughout; quantity fields often use Z. BWZ blanks entire field on report when all zeros.
Store IDs as type A to preserve leading zeros that numeric types would drop on display. Pad character codes by building with literals: MOVE '00001234' to eight-byte field, or concatenate segments in a buffer. Loop filling with INDEX over digit positions when length varies. No built-in PAD LEFT statement—explicit logic or copy from upstream system that already padded the file.
Zoned N fields store digits with zone nybbles—unassigned digit positions may appear as zero digits in display. Packed P fields compress digits—value zero occupies packed zero pattern in all bytes. Assignment INTEGER or ROUNDED affects numeric padding on conversion, not character spaces. SUM on reports treats quantitative zero fields as numeric zero, not blank—use BWZ on MASK to hide zero amounts on printed output.
Screen ROW statement supports FILL with a fill character or NULL for input field display padding on panels. Report formatting may use literals interleaved with fields to pad columns visually. FILL affects presentation layer similar to MASK—not always the stored FILE field unless you WRITE that padded image back to disk.
When writing files, output records should match downstream COBOL or Easytrieve layouts. Space-fill unused name columns before WRITE so receivers expecting fixed eighty-byte records get consistent blanks. Numeric amounts in P format need correct length and decimal positions—zero pad is implicit in packed representation, not spaces. Mismatch padding on output breaks next job in the chain.
Padding adds fill characters; trimming removes trailing spaces before compare or output. Many programs pad on output after trimming input—normalize once in JOB logic. See the trimming tutorial for scan loops that strip spaces; combine with padding when building delimited export where separators must not include trailing spaces.
Padding is filling empty boxes with filler. Character boxes get space stickers when you do not fill them with letters. Number boxes get zero stickers when you start. When you pour a short word into a long box, spaces fill the empty spots at the end. Report masks can hide extra zero stickers on the printout even though the box still has them inside.
1. Working storage A fields initialize to:
2. Working storage numeric fields initialize to:
3. Assigning a 3-byte literal to a 10-byte A field:
4. MASK character Z in edit masks:
5. Trailing spaces in an A field: