Files
cobol-java-v3/benchmark-programs/02-matching-1-N

02-matching-1-N: 1:N Matching (one master matches N details by key)

电信业务场景

合同↔通话明细关联。读取合同文件(CONTRACT)和通话明细文件(CDR),按合同ID进行1:N关联。一个合同可关联多条CDR,未关联的记录输出到异常文件。

Description

Tests one-to-many matching where one master record can match multiple detail records sharing the same STD-KEY. The program reads a master, then reads all consecutive details with the same key, writing one output record per matching detail. Unmatched master and detail records 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-02-matching-1-N.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: 2 records — KEY00001 (has 3 matching details), KEY00004 (unmatched master)
  • detail.dat: 4 records — KEY00001 x3 (3 details for KEY00001), KEY00005 (unmatched detail)

Matching Logic

  1. Read master, then advance detail cursor to find matching key.
  2. For each detail with the same key, write one output record (from master).
  3. When details run out or key changes, read next master.
  4. Skip unmatched masters (master key < detail key).
  5. Skip unmatched details (detail key < master key).

Test

Check Expected
Output records 3 (1 master x 3 details)
Output file size 135 bytes (3 x 45)
Unmatched master 1 (KEY00004)
Unmatched detail 1 (KEY00005)

Usage

cd 02-matching-1-N
bash run.sh