comp3-packed-decimal
Agent skill frombenchflow-ai/skillsbench
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.
How to install comp3-packed-decimal
install comp3-packed-decimal
# install the skillsbench pack with the skills CLI
npx skills add benchflow-ai/skillsbench# or add only this skill to Claude Code: copy the folder
tasks-extra/cobol-gl-batch-reconcile/environment/skills/comp3-packed-decimal/
# into
~/.claude/skills/comp3-packed-decimal/ (all projects)
.claude/skills/comp3-packed-decimal/ (one project)
tasks-extra/cobol-gl-batch-reconcile/environment/skills/comp3-packed-decimal/SKILL.md
Apache-2.0Full file1# COMP-3 / packed decimal storage23`USAGE COMP-3` (a.k.a. PACKED-DECIMAL) stores a signed numeric field as4binary-coded-decimal nibbles: each byte holds two decimal digits, except the5last byte whose low nibble is the sign:67```8PIC S9(11)V99 USAGE COMP-39+--+--+--+--+--+--+--+10|D1|D2|D3|D4|D5|D6|D7| 7 bytes total for 13 digits11+--+--+--+--+--+--+--+12 ^^-- sign nibble in the LOW half of the last byte13```1415Bytes-on-disk = `ceil((digit_count + 1) / 2)`. For `PIC S9(11)V99` that is16`ceil(14 / 2) = 7` bytes. The high nibble of the first byte holds the first17decimal digit; the implied decimal point is not stored.1819Sign nibbles:2021| Nibble | Meaning |22|--------|---------|23| `C` | positive (some shops emit `F` for unsigned, but `C` is standard for SIGNED) |24| `D` | negative |25| `F` | unsigned / non-`S` PIC |2627## Declaring COMP-3 in an FD2829The record layout must match the byte budget. If the data in the file is30packed but you declare the field as `PIC X(n)` or as an unpacked decimal,31the COBOL runtime will not decode it and the value will look like binary32garbage when displayed.3334```cobol35FD MAST-FILE36 RECORD CONTAINS 80 CHARACTERS.3701 MAST-REC.38 05 M-ACCT PIC X(6).39 05 M-TYPE PIC X.40 05 M-STATUS PIC X.41 05 M-CCY PIC X(3).42 05 M-CARRY PIC S9(11)V99 USAGE COMP-3. *> 7 bytes43 05 FILLER PIC X(62). *> remainder of 8044```45…
Excerpt shown under the repository's Apache-2.0 license.
