COBOL Fixed-Length Interface Records: Detect a Layout Shift Before Business Fields Are Misread
A fixed-length interface can be structurally wrong while still looking like ordinary data to a COBOL program. This guide shows how to detect a record-layout shift early, preserve useful evidence, and avoid processing amounts or keys from the wrong byte positions.
A fixed-length interface can be structurally wrong while still looking like ordinary data to a COBOL program. This guide shows how to detect a record-layout shift early, preserve useful evidence, and avoid processing amounts or keys from the wrong byte positions.
Symptom: values look possible, but do not reconcile
A typical inbound file has a fixed record layout agreed by two systems. One program writes each record at 120 bytes; the COBOL batch program defines the same 120-byte record in an FD. The risk is not limited to a short record that fails immediately. A sender can insert a two-byte version field, change a packed amount to display numeric, or alter a delimiter in a preceding extract. If the transfer pads or truncates records, the receiving program may still read 120 bytes. It can then treat one field's bytes as the next field's value.
That failure is dangerous because some shifted values remain valid characters. A customer identifier may become a different numeric-looking identifier. A date may pass a basic numeric check but represent the wrong positions. The batch run can finish with RC=0 and only later fail reconciliation.
Use a fictional payment interface to make the problem concrete. The expected record has these positions:
| Positions | Field | Expected form |
| --- | --- | --- |
| 1-2 | record type | PM |
| 3-12 | account number | 10 digits |
| 13-20 | effective date | YYYYMMDD |
| 21-31 | payment amount | 11 digits, implied 2 decimals |
| 32-120 | reserved/detail area | site-defined |
An upstream change inserts 01 after the record type. The receiver still reads a 120-byte record. Account number now starts in position 5 instead of 3, and every later field is displaced. A simple NUMERIC test on the account field is not sufficient evidence that the layout is correct.
Evidence to capture before changing anything
Start by preserving the run context, not by editing the copybook or rerunning the job. The objective is to establish whether the issue is source content, transport handling, or a changed layout.
Capture these items according to local security and data-handling rules:
- job name, step name, run date, input dataset generation, and a safe sample record reference or masked hex display;
- the DCB attributes reported for the received dataset, especially
RECFM,LRECL, and block size where relevant; - the JCL DD statement, including any transfer, sort, conversion, or exit step that created the input;
- the current COBOL FD, record definition, and the copybook version actually compiled into the load module;
- sender notification, interface specification version, and file-level count or hash controls if supplied;
- rejects grouped by reason and a few masked examples showing byte positions rather than exposed customer data.
Do not assume a file is correct because its dataset name and generation look familiar. Likewise, do not assume a changed LRECL proves a layout change: a transfer setting, an unload format, or a record-format conversion can produce similar symptoms.
Diagnosis path: test the layout as a contract
The most useful first check is a small, non-updating validation mode. It reads records, validates stable anchors at known positions, counts failures, and writes a controlled reject record. Stable anchors are fields whose values are constrained by the interface: record type, version, date range, allowed code, or checksum. Use more than one anchor. One valid field can occur by accident after a shift.
The following simplified COBOL fragment illustrates the idea. Field names and positions are fictional; adapt compiler options, copybooks, and error handling to local standards.
FD PAY-IN.
01 PAY-IN-REC.
05 IN-REC-TYPE PIC X(2).
05 IN-ACCOUNT PIC X(10).
05 IN-EFFECTIVE-DATE PIC 9(8).
05 IN-AMOUNT PIC 9(11).
05 IN-DETAIL PIC X(89).
01 WS-REJECT-REASON PIC X(24).
READ PAY-IN
AT END MOVE 'Y' TO WS-END-OF-FILE
NOT AT END
EVALUATE TRUE
WHEN IN-REC-TYPE NOT = 'PM'
MOVE 'UNEXPECTED-RECORD-TYPE'
TO WS-REJECT-REASON
WHEN IN-ACCOUNT NOT NUMERIC
MOVE 'NONNUMERIC-ACCOUNT' TO WS-REJECT-REASON
WHEN IN-EFFECTIVE-DATE NOT NUMERIC
MOVE 'INVALID-DATE-FORMAT' TO WS-REJECT-REASON
WHEN OTHER
MOVE SPACES TO WS-REJECT-REASON
END-EVALUATE
END-READ
```
This is deliberately not a complete date validator. A production validator should also reject impossible months and days, check permitted record types, and apply any business-effective-date rules. More importantly, it should not update a DB2 table or a VSAM file when structural validation has failed.
Compare the observed position map with the interface contract. A hex or character-position display from an approved diagnostic tool can help, but protect sensitive values. Look for patterns: does every account begin with the new version code? Are effective dates consistently missing their first two digits? Do reject counts begin at the first record or only after a header/trailer? Consistency points toward a contract shift; scattered failures may point toward source-data quality instead.
Safe correction options
The right correction depends on where the contract broke.
| Finding | Safer response | Do not assume |
| --- | --- | --- |
| Sender introduced a new layout | hold the load and obtain the revised specification and test file | a two-byte adjustment is the only change |
| Transfer altered record format or length | correct the transfer configuration in a test path and compare byte-level samples | changing the COBOL FD fixes transport corruption |
| Copybook is behind the approved layout | promote an reviewed copybook/program change through normal compile and test controls | a source edit alone changes the executing load module |
| A few records are malformed | quarantine them under the agreed reject process and confirm business disposition | all rejected records can be discarded or rerun |
If a compatible layout transition is required, make version handling explicit rather than silently moving fields. For example, route PM01 and PM02 through separate validated layouts, or reject an unknown version before any update. This makes the next change observable and gives support staff a clear reason code.
Before rerun: support checklist
- Confirm whether the original run performed any commits, writes, or downstream extracts. A validation failure does not prove that no updates occurred.
- Reconcile input count, accepted count, rejected count, and any trailer controls for the exact input generation.
- Verify the corrected file's
RECFMandLRECLand inspect masked position samples against the approved layout. - Run the validation path in a controlled test or dry-run mode first; review rejection reasons, not just the return code.
- Obtain the required business and change-control approval before loading corrected data or restarting from a checkpoint.
- Preserve the original evidence until the incident and any duplicate-processing risk are closed.
A record definition is an interface contract, not merely a COBOL declaration. Validate several position-specific anchors before updates begin; when they disagree, stop the business load, prove the actual byte layout, and correct the responsible contract or transport path before rerun.