Reconciling Two Interface Files with DFSORT JOINKEYS Before a Batch Rerun
When an inbound file and a downstream extract disagree, a support team needs to know *which keys* are missing, extra, or changed before choosing a restart action. DFSORT `JOINKEYS` can produce that comparison without writing a COBOL program, provided the record layouts and comparison key are understood.
When an inbound file and a downstream extract disagree, a support team needs to know *which keys* are missing, extra, or changed before choosing a restart action. DFSORT JOINKEYS can produce that comparison without writing a COBOL program, provided the record layouts and comparison key are understood.
This tutorial uses fictional membership files and generic dataset names. It is a controlled diagnostic technique, not a reason to resend a file, reload a table, or rerun a job without the application owner’s recovery decision.
The question behind a count mismatch
Assume an overnight membership interface contains 125,430 accepted detail records. A downstream staging extract reports 125,417 records for the same cycle. A count difference of 13 is useful, but it does not answer the operational question:
Are 13 source members absent from the staging extract?
Are there 13 unexpected staging members?
Did the same member key occur on both files with different status?
Are the two files even from the same business cycle?
A JOINKEYS run compares records by a defined key and sends matched and unmatched pairs to a main task. It is especially useful for read-only investigation when the source file and a controlled downstream extract are both available. The output provides an evidence list for the application team; it does not determine whether a missing row is a processing fault, an allowed business exclusion, or an issue in the comparison itself.
Before comparing, establish that both inputs identify the same cycle, interface version, and population. A comparison between a Monday source file and a Tuesday table extract can produce a technically perfect, operationally meaningless exception report.
Define the comparison contract first
For this fictional example, both files are fixed-block 80-byte detail records. Bytes 1–10 contain the member number and bytes 11–18 contain an effective date in YYYYMMDD format. Those 18 bytes form the business comparison key. The source file has a transaction code at bytes 19–20; the staging extract has a load status at bytes 19–20.
Write down the contract before coding control statements:
| Decision | Example choice | Why it matters |
|---|---|---|
| Join key | member number + effective date | A member can have more than one effective record |
| Input population | accepted source details and committed staging extract | Rejects and uncommitted work must not be mixed in silently |
| Duplicate-key rule | investigate; do not assume one-to-one | JOINKEYS can create multiple pairings for duplicate keys |
| Cycle identity | file header/run ID and extract control ID match | Prevents a false exception list from different runs |
| Sensitive fields | key and approved status only | Limits diagnostic output to what support needs |
The key must reflect the business rule being tested. Joining only on member number would make a termination record look like a match for a later enrollment record. Conversely, adding non-key fields such as status to the key can hide a meaningful change by classifying it as two unmatched records.
A compact JOINKEYS diagnostic job
The following JCL sorts each input by the same 18-byte key, pairs records with that key, and adds a one-byte indicator after each record. The REFORMAT layout contains the source record, a source-presence indicator, the staging record, and a staging-presence indicator.
//RECON EXEC PGM=SORT
//SORTJNF1 DD DSN=APP.MEMBER.SOURCE.ACCEPTED.D20261102,DISP=SHR
//SORTJNF2 DD DSN=APP.MEMBER.STAGE.EXTRACT.D20261102,DISP=SHR
//SORTOUT DD DSN=&&RECONOUT,DISP=(NEW,PASS),
// SPACE=(CYL,(5,2)),UNIT=SYSDA
//SYSOUT DD SYSOUT=*
//SYSIN DD *
JOINKEYS F1=SORTJNF1,FIELDS=(1,18,A)
JOINKEYS F2=SORTJNF2,FIELDS=(1,18,A)
JOIN UNPAIRED,F1,F2,ONLY
REFORMAT FIELDS=(F1:1,80,?,F2:1,80,?)
SORT FIELDS=(1,18,CH,A)
OUTFIL INCLUDE=(81,1,CH,EQ,C'B'),
BUILD=(C'SOURCE-ONLY ',1,18,19,2)
OUTFIL INCLUDE=(162,1,CH,EQ,C'B'),
BUILD=(C'STAGE-ONLY ',82,18,100,2)
/*
JOIN UNPAIRED,F1,F2,ONLY is the important diagnostic choice. It retains records that occur on just one side and suppresses normal matched pairs. In the reformat record, ? supplies a one-byte indicator: B means the corresponding input record is present; a blank indicates it is absent. Here, byte 81 describes the source portion and byte 162 describes the staging portion.
The two OUTFIL statements then create readable exception lines. A source-only line uses bytes 1–18 and the source transaction code at bytes 19–20. A stage-only line uses the staging key at bytes 82–99 and its status at bytes 100–101. The temporary SORTOUT keeps the example compact; local naming, retention, and review rules should govern any real diagnostic dataset.
A short sample result might be:
SOURCE-ONLY 000184250120261102AD
SOURCE-ONLY 000193770220261102CH
STAGE-ONLY 000224090120261102ER
That output says only that the records did not pair under the chosen 18-byte key. It does not say that the two source records failed to load. AD might be an action intentionally excluded from staging; ER might be a row retained from a prior cycle. The interface specification and load logic decide that interpretation.
Do not overlook duplicate keys
A join comparison is easiest to read when each file has one record per key. If either side contains repeated keys, a many-to-many pairing can inflate matched results. For example, two source records and three staging records with the same key may result in six pairings. A simple count of joined output would then be misleading.
Detect and resolve that condition before treating the reconciliation as final. One approach is to run a separate sort with SUM FIELDS=NONE only when the interface contract says duplicate keys are invalid. Another is to retain sequence number or record-type information in the key or output so that legitimate repeated business events remain distinguishable. Do not remove duplicates just to get a clean comparison; first determine whether they are source data, a rerun artifact, or valid repetitions under the interface design.
Also confirm the data type and collation. A numeric identifier stored as character data may require CH, including leading zeroes. A packed-decimal field has a different length and comparison format. Copying a field position from a copybook without checking the actual file layout is a common way to generate a convincing but false exception report.
What to verify before proposing a rerun
- Confirm both input datasets, their resolved generation names, and their run or cycle controls belong to the same processing event.
- Confirm whether the downstream extract represents committed work, a staging area, or a post-filtered reporting view.
- Validate the join key positions, formats, and leading-zero rules against the current file layouts.
- Check whether header, trailer, rejected, or logical-delete records were excluded consistently.
- Determine whether duplicate join keys are forbidden, expected, or need a sequence-level comparison.
- Preserve the exception list and record counts with the job ID and program/load version used to create the staging extract.
- For every exception type, ask the application owner whether it is a permitted business rule, a load failure, a timing issue, or an upstream data problem.
- Do not rerun, resend, delete, or manually insert records based only on the JOINKEYS output.
DFSORT options, record formats, and local standards vary. Test the control cards with masked or test data first, and use approved access paths when creating a downstream extract from a production database.
Practical takeaway
JOINKEYS turns a vague count mismatch into a focused key-level evidence list. Its value comes from a deliberate comparison contract: same cycle, correct business key, known duplicate behavior, and a human decision about what each exception means before any recovery action is taken.