Files
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.4 KiB

31-validation-withdup: Field Validation with Duplicate Check

电信业务场景

重复CDR检测。对已按CDR-ID排序的明细文件进行WS-PREV-KEY重复检测,首次出现通过,同一ID再次出现判定为重复并拒否。

Description

Reads a sorted input file and checks for duplicate KEY values using the WS-PREV-KEY pattern. The first occurrence of a key is written to FILE-OUT-GOOD. Any subsequent occurrence of the same key is written to FILE-OUT-BAD with an error code (duplicate detection).

Record Layout

Input / Good Output (35 bytes)

Field Type Length Description
KEY PIC X 5 Sort key
DATA PIC X 30 Payload data

Bad Output (37 bytes)

Field Type Length Description
KEY PIC X 5 Duplicated key
DATA PIC X 30 Original data
ERR PIC X 2 Error code ('01')

Files

File Purpose
main-31-validation-withdup.cbl Main COBOL program
data-gen.sh Generate sorted test data
run.sh Compile, run, verify
README.md This file

Test Data

KEY01  FIRST-RECORD         -> PASS (1st unique)
KEY02  SECOND-RECORD        -> PASS (2nd unique)
KEY03  FIRST-DUP-A          -> PASS (1st)
KEY03  SECOND-DUP-A         -> FAIL (dup)
KEY03  THIRD-DUP-A          -> FAIL (dup)
KEY04  UNIQUE-AFTER-DUP     -> PASS (unique after dups)
KEY05  DUP-GROUP-B-1ST      -> PASS (1st)
KEY05  DUP-GROUP-B-2ND      -> FAIL (dup)
KEY06  TRIPLE-GROUP-1ST     -> PASS (1st)
KEY06  TRIPLE-GROUP-2ND     -> FAIL (dup)
KEY06  TRIPLE-GROUP-3RD     -> FAIL (dup)
KEY99  LAST-UNIQUE          -> PASS (final unique)

Expected: 7 good records, 5 bad records.

Usage

cd 31-validation-withdup
bash data-gen.sh
bash run.sh

Expected Behavior

  • The first occurrence of each KEY is always accepted.
  • Subsequent occurrences of the same KEY are rejected as duplicates.
  • The WS-PREV-KEY is updated only when a record passes validation.
  • Duplicate records contain error code '01' in the BAD output.
  • Input must be sorted by KEY for correct sequential detection.