Agent Skillsbenchflow-ai/skillsbench › comp3-packed-decimal

comp3-packed-decimal

GitHub

提供COBOL COMP-3压缩十进制数据的存储布局、FD声明方法及常见陷阱。指导如何正确解码字节、避免类型错误,并解决工作存储中进位值丢失的问题,确保数值计算准确。

tasks-extra/cobol-gl-batch-reconcile/environment/skills/comp3-packed-decimal/SKILL.md benchflow-ai/skillsbench

Trigger Scenarios

解析COBOL COMP-3或packed decimal格式数据 处理COBOL FD记录中的数字字段声明 调试COMP-3值在内存传输或算术运算中的错误

Install

npx skills add benchflow-ai/skillsbench --skill comp3-packed-decimal -g -y
More Options

Non-standard path

npx skills add https://github.com/benchflow-ai/skillsbench/tree/main/tasks-extra/cobol-gl-batch-reconcile/environment/skills/comp3-packed-decimal -g -y

Use without installing

npx skills use benchflow-ai/skillsbench@comp3-packed-decimal

指定 Agent (Claude Code)

npx skills add benchflow-ai/skillsbench --skill comp3-packed-decimal -a claude-code -g -y

安装 repo 全部 skill

npx skills add benchflow-ai/skillsbench --all -g -y

预览 repo 内 skill

npx skills add benchflow-ai/skillsbench --list

SKILL.md

Frontmatter
{
    "name": "comp3-packed-decimal",
    "description": "Reference for COBOL COMP-3 (packed decimal \/ BCD) numeric storage -- layout on disk, declaring it in the FD, and pitfalls when carrying the decoded value through working storage and into later arithmetic. Useful when an input record holds a balance, rate, or carry-forward as packed decimal rather than a printable digit string."
}

COMP-3 / packed decimal storage

USAGE COMP-3 (a.k.a. PACKED-DECIMAL) stores a signed numeric field as binary-coded-decimal nibbles: each byte holds two decimal digits, except the last byte whose low nibble is the sign:

PIC S9(11)V99 USAGE COMP-3
+--+--+--+--+--+--+--+
|D1|D2|D3|D4|D5|D6|D7|   7 bytes total for 13 digits
+--+--+--+--+--+--+--+
              ^^-- sign nibble in the LOW half of the last byte

Bytes-on-disk = ceil((digit_count + 1) / 2). For PIC S9(11)V99 that is ceil(14 / 2) = 7 bytes. The high nibble of the first byte holds the first decimal digit; the implied decimal point is not stored.

Sign nibbles:

Nibble Meaning
C positive (some shops emit F for unsigned, but C is standard for SIGNED)
D negative
F unsigned / non-S PIC

Declaring COMP-3 in an FD

The record layout must match the byte budget. If the data in the file is packed but you declare the field as PIC X(n) or as an unpacked decimal, the COBOL runtime will not decode it and the value will look like binary garbage when displayed.

FD  MAST-FILE
    RECORD CONTAINS 80 CHARACTERS.
01  MAST-REC.
    05  M-ACCT     PIC X(6).
    05  M-TYPE     PIC X.
    05  M-STATUS   PIC X.
    05  M-CCY      PIC X(3).
    05  M-CARRY    PIC S9(11)V99 USAGE COMP-3.   *> 7 bytes
    05  FILLER     PIC X(62).                    *> remainder of 80

Use a runtime check: cobc -x -free -o prog PROG.cbl && ./prog and DISPLAY one record's COMP-3 field before relying on it. Common mistakes:

  • Forgetting the USAGE COMP-3 clause -> the field is read as 7 zoned ASCII characters; values look like control characters.
  • Wrong digit count -> the byte budget changes and subsequent fields slide.
  • Moving COMP-3 directly into a PIC X(7) workspace -> the bytes copy but no arithmetic translation happens; the value is unusable.

Carrying the value through working storage

A common defect when there is an opening balance / carry-forward column:

  1. The COMP-3 column is decoded correctly in the FD-side record (the master lookup returns the right number).
  2. But when the per-account accumulator row is created later in the program, the carry-forward seed is initialised to a constant (often zero) instead of being copied from the lookup result.
  3. Every account is then summed up correctly from the detail tape but the opening balance is silently dropped at output time.

The cure is structural, not a single magic line: when you allocate a new accumulator row, seed every column that has a meaningful starting value — including the decoded carry-forward — rather than leaving it at its INITIALIZE/VALUE ZERO default. Pseudocode with placeholder names (adapt to your own record and table identifiers):

       *> placeholders: <new-row> is the freshly allocated accumulator,
       *> <decoded-carry> is the COMP-3 value from the master lookup.
       IF row-not-yet-present
           allocate <new-row>
           MOVE <account-key>   TO key-of   (<new-row>)
           MOVE <currency>      TO ccy-of   (<new-row>)
           MOVE <decoded-carry> TO carry-of (<new-row>)   *> seed, don't zero
           MOVE <period-delta>  TO delta-of (<new-row>)
       END-IF

The point is to recognise which fields need a non-zero seed at row creation; the exact MOVE targets depend on how your program names its balance table.

Verification tip

od -An -tx1 ACCT.MASTER | head and confirm bytes 11-17 of one record match the expected packed nibbles for that account's known opening balance. A few hand-decoded rows are usually enough to confirm both the FD declaration and the carry-through logic.

References

  • IBM Enterprise COBOL Language Reference -- "USAGE PACKED-DECIMAL / COMP-3"
  • GnuCOBOL documentation on USAGE clauses and arithmetic on packed fields

Version History

  • 9a1f4dd Current 2026-07-24 16:36

Same Skill Collection

.agents/skills/skill-creator/SKILL.md
.agents/skills/skillsbench/SKILL.md
.agents/skills/task-creator/SKILL.md
tasks-extra/cobol-gl-batch-reconcile/environment/skills/ebcdic-overpunch-decoding/SKILL.md
tasks-extra/cobol-gl-batch-reconcile/environment/skills/gl-posting-codes/SKILL.md
tasks-extra/cobol-gl-batch-reconcile/environment/skills/gnucobol-mainframe-batch/SKILL.md
tasks-extra/diff-transformer_impl/environment/skills/attention-variants-from-papers/SKILL.md
tasks-extra/diff-transformer_impl/environment/skills/modal-gpu/SKILL.md
tasks-extra/find-topk-similiar-chemicals/environment/skills/pdf/SKILL.md
tasks-extra/find-topk-similiar-chemicals/environment/skills/pubchem-database/SKILL.md
tasks-extra/find-topk-similiar-chemicals/environment/skills/rdkit/SKILL.md
tasks-extra/gh-repo-analytics/environment/skills/gh-cli/SKILL.md
tasks-extra/gpu-cluster-online-scheduling/environment/skills/fragmentation-aware-packing/SKILL.md
tasks-extra/gpu-cluster-online-scheduling/environment/skills/multi-resource-allocation-validation/SKILL.md
tasks-extra/gpu-cluster-online-scheduling/environment/skills/online-resource-scheduling/SKILL.md
tasks-extra/mhc-layer-impl/environment/skills/mhc-algorithm/SKILL.md
tasks-extra/mhc-layer-impl/environment/skills/modal-gpu/SKILL.md
tasks-extra/mhc-layer-impl/environment/skills/nanogpt-training/SKILL.md
tasks-extra/nda-playbook-review/environment/skills/nda-clause-taxonomy/SKILL.md
tasks-extra/nda-playbook-review/environment/skills/xlsx-parsing/SKILL.md
tasks-extra/pedestrian-traffic-counting/environment/skills/gemini-count-in-video/SKILL.md
tasks-extra/pedestrian-traffic-counting/environment/skills/gemini-video-understanding/SKILL.md
tasks-extra/pedestrian-traffic-counting/environment/skills/gpt-multimodal/SKILL.md
tasks-extra/pedestrian-traffic-counting/environment/skills/video-frame-extraction/SKILL.md
tasks-extra/pg-essay-to-audiobook/environment/skills/audiobook/SKILL.md
tasks-extra/pg-essay-to-audiobook/environment/skills/elevenlabs-tts/SKILL.md
tasks-extra/pg-essay-to-audiobook/environment/skills/gtts/SKILL.md
tasks-extra/pg-essay-to-audiobook/environment/skills/openai-tts/SKILL.md
tasks-extra/scheduling-email-assistant/environment/skills/gmail-skill/SKILL.md
tasks-extra/speaker-diarization-subtitles/environment/skills/automatic-speech-recognition/SKILL.md
tasks-extra/speaker-diarization-subtitles/environment/skills/multimodal-fusion/SKILL.md
tasks-extra/speaker-diarization-subtitles/environment/skills/speaker-clustering/SKILL.md
tasks-extra/speaker-diarization-subtitles/environment/skills/voice-activity-detection/SKILL.md
tasks-extra/taxonomy-tree-merge/environment/skills/hierarchical-taxonomy-clustering/SKILL.md
tasks-extra/video-filler-word-remover/environment/skills/ffmpeg-video-editing/SKILL.md
tasks-extra/video-filler-word-remover/environment/skills/filler-word-processing/SKILL.md
tasks-extra/video-filler-word-remover/environment/skills/whisper-transcription/SKILL.md
tasks-extra/video-tutorial-indexer/environment/skills/speech-to-text/SKILL.md
tasks/3d-scan-calc/environment/skills/mesh-analysis/SKILL.md
tasks/ada-bathroom-plan-repair/environment/skills/ada-plan-view-accessibility/SKILL.md
tasks/ada-bathroom-plan-repair/environment/skills/architectural-dxf-extraction/SKILL.md
tasks/ada-bathroom-plan-repair/environment/skills/geometric-layout-repair/SKILL.md
tasks/adaptive-cruise-control/environment/skills/csv-processing/SKILL.md
tasks/adaptive-cruise-control/environment/skills/pid-controller/SKILL.md
tasks/adaptive-cruise-control/environment/skills/simulation-metrics/SKILL.md
tasks/adaptive-cruise-control/environment/skills/vehicle-dynamics/SKILL.md
tasks/adaptive-cruise-control/environment/skills/yaml-config/SKILL.md
tasks/azure-bgp-oscillation-route-leak/environment/skills/azure-bgp/SKILL.md
tasks/bike-rebalance/environment/skills/geospatial-routing-data/SKILL.md

Metadata

Files
0
Version
9a1f4dd
Hash
729203ed
Indexed
2026-07-24 16:36

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-07 19:19
浙ICP备14020137号-1 $방문자$