94400d50d4
作为子目录纳入系统,与核心测试管道协同 Co-Authored-By: Claude <noreply@anthropic.com>
97 lines
3.6 KiB
Markdown
97 lines
3.6 KiB
Markdown
# 24-table-search: Internal Table Search
|
|
|
|
## 电信业务场景
|
|
|
|
资费表内部检索。在内存套餐资费表中使用SEARCH ALL(二分查找)按套餐代码检索单价,使用SEARCH顺序查找备用。
|
|
|
|
## Description
|
|
|
|
Demonstrates OCCURS table processing with three search methods:
|
|
|
|
1. **SEARCH ALL** (binary search) on a sorted 10-entry table
|
|
2. **SEARCH** (sequential scan) on the same table
|
|
3. **SEARCH ALL** on a variable-length table (OCCURS DEPENDING ON)
|
|
|
|
Also demonstrates INDEXED BY index manipulation and bounds checking.
|
|
|
|
## Record Layout
|
|
|
|
### Input (2 bytes)
|
|
|
|
| Field | Type | Length | Description |
|
|
|--------|----------|--------|------------------|
|
|
| IN-KEY | PIC X | 2 | Key to search for |
|
|
|
|
### Output (71 bytes)
|
|
|
|
| Field | Type | Length | Description |
|
|
|------------|----------|--------|----------------------------|
|
|
| OUT-KEY | PIC X | 2 | Searched key |
|
|
| FILLER | PIC X | 1 | Space separator |
|
|
| ALL-STAT | PIC X | 1 | SEARCH ALL found? (Y/N) |
|
|
| FILLER | PIC X | 1 | Space separator |
|
|
| SEQ-STAT | PIC X | 1 | SEARCH found? (Y/N) |
|
|
| FILLER | PIC X | 1 | Space separator |
|
|
| VAR-STAT | PIC X | 1 | VAR table found? (Y/N) |
|
|
| FILLER | PIC X | 1 | Space separator |
|
|
| ALL-VAL | PIC X | 20 | SEARCH ALL found value |
|
|
| FILLER | PIC X | 1 | Space separator |
|
|
| SEQ-VAL | PIC X | 20 | SEARCH found value |
|
|
| FILLER | PIC X | 1 | Space separator |
|
|
| VAR-VAL | PIC X | 20 | VAR table found value |
|
|
|
|
## Internal Table (10 entries)
|
|
|
|
| Index | Key | Value |
|
|
|-------|-----|--------------|
|
|
| 1 | AA | Alpha-001 |
|
|
| 2 | BB | Beta-002 |
|
|
| 3 | CC | Charlie-003 |
|
|
| 4 | DD | Delta-004 |
|
|
| 5 | EE | Echo-005 |
|
|
| 6 | FF | Foxtrot-006 |
|
|
| 7 | GG | Golf-007 |
|
|
| 8 | HH | Hotel-008 |
|
|
| 9 | II | India-009 |
|
|
| 10 | JJ | Juliett-010 |
|
|
|
|
Variable-length table (OCCURS DEPENDING ON size=8): entries 1-8.
|
|
|
|
## Files
|
|
|
|
| File | Purpose |
|
|
|--------------------------|--------------------------------|
|
|
| main-24-table-search.cbl | Main COBOL program |
|
|
| data-gen.sh | Generate search key data |
|
|
| run.sh | Compile, run, verify |
|
|
| README.md | This file |
|
|
|
|
## Tests
|
|
|
|
| Test Case | Description |
|
|
|----------------------|------------------------------------------|
|
|
| Key exists (first) | 'AA' - found by all methods |
|
|
| Key exists (middle) | 'CC' - found by all methods |
|
|
| Key exists (last) | 'JJ' - found by main, excluded in var |
|
|
| Key not exists | 'XX' - not found |
|
|
| Invalid format | '99' - numeric, not found |
|
|
| Case mismatch | 'aa' - lowercase, case-sensitive search |
|
|
| Empty key | Spaces - not found |
|
|
| Var table boundary | 'II' - in main table(9), not in var(8) |
|
|
| Index bounds test | Set index to 15, detect out-of-bounds |
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
cd 24-table-search
|
|
bash data-gen.sh
|
|
bash run.sh
|
|
```
|
|
|
|
## Expected Behavior
|
|
|
|
- SEARCH ALL and SEARCH both find keys AA, BB, CC, DD, EE, FF, GG, HH, II, JJ.
|
|
- SEARCH ALL on VAR table (size 8) finds only AA-HH.
|
|
- Non-existent keys return 'N' status with empty values.
|
|
- Index manipulation (SET to 15) is detected and reported.
|