Files

01-matching-1-1: 1:1 Matching (one master matches one detail by key)

电信业务场景

请求书↔支付对账。读取已排序的请求书文件(INVOICE)和支付文件(PAYMENT),按请求书ID进行1:1对账。匹配成功的记录写入output.dat,未匹配的分别记录到error.dat。

Description

Tests one-to-one matching where each master record matches at most one detail record on STD-KEY. The program implements a sorted merge algorithm: both files are read in key order, and when keys match, one output record is written. Unmatched records in either file are silently skipped.

Record Layout

Field Type Length Description
STD-KEY PIC X 10 Record key
STD-DATA-1 PIC X 20 Description text
STD-DATA-2 PIC 9 10 Numeric data (display)
STD-DATA-3 PIC S9(7)V99 05 Numeric data (COMP-3)

Total record length: 45 bytes.

Files

File Purpose
main-01-matching-1-1.cbl Main COBOL program (fixed format)
data-gen.sh Generate test data files
run.sh Compile, run, verify
README.md This file

Data

  • master.dat: 7 records — KEY00001..KEY00005 (matched), KEY00006 (unmatched master), KEY00008 (extra unmatched master)
  • detail.dat: 6 records — KEY00001..KEY00005 (matched), KEY00007 (unmatched detail)

Matching Logic

  1. Read both files in parallel by STD-KEY.
  2. If keys equal: write output record (from master), read both.
  3. If master key < detail key: read master only (unmatched master).
  4. If master key > detail key: read detail only (unmatched detail).
  5. Continue until both files are exhausted.

Test

Check Expected
Output records 5 (KEY00001..KEY00005)
Output file size 225 bytes (5 x 45)
Unmatched master 2 (KEY00006, KEY00008)
Unmatched detail 1 (KEY00007)

Usage

cd 01-matching-1-1
bash run.sh