Files
cobol-java-v3/benchmark-programs/18-matching-MN-to-M/README.md
T
NB-076 94400d50d4 feat: add benchmark-programs — 58 telecom COBOL test programs
作为子目录纳入系统,与核心测试管道协同

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-25 09:53:21 +08:00

2.0 KiB

18-matching-MN-to-M: M:N Matching with M Output Records

电信业务场景

合同↔套餐M:N→M条。多个合同关联多个套餐的组合匹配,输出按合同件数(M件)的匹配结果。

Description

M:N matching where both sides can have duplicate keys. The output contains one record per master record that has at least one matching detail record with the same key. This tests the ability to handle M:N relationships and produce one output per matched master.

The algorithm skips master groups with no matching detail key, and skips detail key groups that have no corresponding master key.

Record Layout

Standard record (45 bytes, copybook STD-REC.cpy):

Field Type Length Description
STD-KEY PIC X 10 Record key
STD-DATA-1 PIC X 20 Text data
STD-DATA-2 PIC 9 10 Numeric data
STD-DATA-3 PIC S9(7)V99 COMP-3 5 Packed decimal

Files

File Purpose
main-18-matching-MN-to-M.cbl Main COBOL program (fixed format)
data-gen.sh Generate test data for all files
run.sh Compile, run, verify
README.md This file

Data Design

  • master.dat: 5 records -- KEY00001 (2), KEY00002 (2), KEY00003 (1)
  • detail.dat: 4 records -- KEY00001 (2), KEY00003 (2)
  • Matching keys: KEY00001, KEY00003
  • Unmatched: KEY00002 (master only)
  • Output: 3 records = 135 bytes

Expected Behavior

  • KEY00001 group (2 master records): matches detail KEY00001 -> output 2 records
  • KEY00002 group (2 master records): no matching detail -> output 0 records
  • KEY00003 group (1 master record): matches detail KEY00003 -> output 1 record
  • Total: 3 output records